diff options
author | Olly Cope <olly@ollycope.com> | 2021-05-02 16:29:52 +0000 |
---|---|---|
committer | Olly Cope <olly@ollycope.com> | 2021-05-02 16:29:52 +0000 |
commit | 2193d3c1e3d8430045b3b5a992362691f2447913 (patch) | |
tree | de6a72240072cf512de6f474920064fc095e54bc | |
parent | 23bf2b84b837d3e17fd9f82f254227577e368879 (diff) | |
download | yoyo-2193d3c1e3d8430045b3b5a992362691f2447913.tar.gz |
topological sort: add test for sort stability
-rw-r--r-- | yoyo/tests/test_migrations.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/yoyo/tests/test_migrations.py b/yoyo/tests/test_migrations.py index 5d694ba..2fdef3b 100644 --- a/yoyo/tests/test_migrations.py +++ b/yoyo/tests/test_migrations.py @@ -270,9 +270,14 @@ def test_grouped_migrations_can_be_rolled_back(backend): class TestTopologicalSort(object): + def check(self, nodes, edges, expected_order): migrations = self.get_mock_migrations(nodes, edges) - output_order = "".join(m.id for m in topological_sort(migrations)) + output = [m.id for m in topological_sort(migrations)] + if isinstance(expected_order, str): + output_order = "".join(output) + else: + output_order = output assert output_order == expected_order def get_mock_migrations(self, nodes="ABCD", edges=[]): @@ -341,6 +346,14 @@ class TestTopologicalSort(object): for input_order in itertools.permutations("ABC"): self.check(input_order, {"AB", "AC", "CB"}, "ACB") + def test_it_doesnt_modify_order_unnecessarily(self): + """ + Test for issue raised in + + https://lists.sr.ht/~olly/yoyo/%3C09c43045fdf14024a0f2e905408ea41f%40atos.net%3E + """ + self.check(["m1", "m2", "m3"], {("m1", "m3")}, ["m1", "m2", "m3"]) + class TestMigrationList(object): def test_can_create_empty(self): |