def test_it_handles_multiple_edges_to_the_same_node(self):
     m1, m2, m3, m4 = self.get_mock_migrations()
     m2.depends.add(m1)
     m3.depends.add(m1)
     m4.depends.add(m1)
     assert list(topological_sort([m1, m2, m3, m4])) == [m1, m2, m3, m4]
 def test_it_catches_cycles(self):
     m1, m2, m3, m4 = self.get_mock_migrations()
     m3.depends.add(m3)
     with pytest.raises(exceptions.BadMigration):
         list(topological_sort([m1, m2, m3, m4]))
 def test_it_discards_missing_dependencies(self):
     m1, m2, m3, m4 = self.get_mock_migrations()
     m3.depends.add(Mock())
     assert list(topological_sort([m1, m2, m3, m4])) == [m1, m2, m3, m4]
 def test_it_brings_depended_upon_migrations_to_the_front(self):
     m1, m2, m3, m4 = self.get_mock_migrations()
     m1.depends.add(m4)
     assert list(topological_sort([m1, m2, m3, m4])) == [m4, m1, m2, m3]
 def test_it_sorts_topologically(self):
     m1, m2, m3, m4 = self.get_mock_migrations()
     m3.depends.add(m4)
     assert list(topological_sort([m1, m2, m3, m4])) == [m4, m3, m1, m2]
 def test_it_keeps_stable_order(self):
     m1, m2, m3, m4 = self.get_mock_migrations()
     assert list(topological_sort([m1, m2, m3, m4])) == [m1, m2, m3, m4]
     assert list(topological_sort([m4, m3, m2, m1])) == [m4, m3, m2, m1]