Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_toposort.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from pathlib import Path | from pathlib import Path | ||||
import subprocess | import subprocess | ||||
from swh.graph.luigi import TopoSort | from swh.graph.luigi import TopoSort | ||||
DATA_DIR = Path(__file__).parents[0] / "dataset" | DATA_DIR = Path(__file__).parents[0] / "dataset" | ||||
EXPECTED_ROWS = """ | EXPECTED = """\ | ||||
SWHID,ancestors,successors,sample_ancestor1,sample_ancestor2 | |||||
swh:1:rev:0000000000000000000000000000000000000003,0,1,, | swh:1:rev:0000000000000000000000000000000000000003,0,1,, | ||||
swh:1:rev:0000000000000000000000000000000000000009,1,3,swh:1:rev:0000000000000000000000000000000000000003, | swh:1:rev:0000000000000000000000000000000000000009,1,3,swh:1:rev:0000000000000000000000000000000000000003, | ||||
swh:1:rel:0000000000000000000000000000000000000010,1,1,swh:1:rev:0000000000000000000000000000000000000009, | swh:1:rel:0000000000000000000000000000000000000010,1,1,swh:1:rev:0000000000000000000000000000000000000009, | ||||
swh:1:snp:0000000000000000000000000000000000000020,2,1,swh:1:rev:0000000000000000000000000000000000000009,swh:1:rel:0000000000000000000000000000000000000010 | swh:1:snp:0000000000000000000000000000000000000020,2,1,swh:1:rev:0000000000000000000000000000000000000009,swh:1:rel:0000000000000000000000000000000000000010 | ||||
swh:1:ori:83404f995118bd25774f4ac14422a8f175e7a054,1,0,swh:1:snp:0000000000000000000000000000000000000020, | swh:1:ori:83404f995118bd25774f4ac14422a8f175e7a054,1,0,swh:1:snp:0000000000000000000000000000000000000020, | ||||
swh:1:rev:0000000000000000000000000000000000000013,1,1,swh:1:rev:0000000000000000000000000000000000000009, | swh:1:rev:0000000000000000000000000000000000000013,1,1,swh:1:rev:0000000000000000000000000000000000000009, | ||||
swh:1:rev:0000000000000000000000000000000000000018,1,1,swh:1:rev:0000000000000000000000000000000000000013, | swh:1:rev:0000000000000000000000000000000000000018,1,1,swh:1:rev:0000000000000000000000000000000000000013, | ||||
swh:1:rel:0000000000000000000000000000000000000019,1,0,swh:1:rev:0000000000000000000000000000000000000018, | swh:1:rel:0000000000000000000000000000000000000019,1,0,swh:1:rev:0000000000000000000000000000000000000018, | ||||
Show All 10 Lines | task = TopoSort( | ||||
topological_order_path=topological_order_path, | topological_order_path=topological_order_path, | ||||
graph_name="example", | graph_name="example", | ||||
) | ) | ||||
task.run() | task.run() | ||||
csv_text = subprocess.check_output(["zstdcat", topological_order_path]).decode() | csv_text = subprocess.check_output(["zstdcat", topological_order_path]).decode() | ||||
lines = csv_text.split("\n") | (header, *rows) = csv_text.split("\n") | ||||
(header, *rows) = lines | (expected_header, *expected_lines) = EXPECTED.split("\n") | ||||
assert header == "SWHID,ancestors,successors,sample_ancestor1,sample_ancestor2" | assert header == expected_header | ||||
# The only possible first line | # The only possible first line | ||||
assert rows[0] == "swh:1:rev:0000000000000000000000000000000000000003,0,1,," | assert rows[0] == "swh:1:rev:0000000000000000000000000000000000000003,0,1,," | ||||
assert set(rows) == set(EXPECTED_ROWS.split("\n")) | assert set(rows) == set(expected_lines) | ||||
assert rows.pop() == "", "Missing trailing newline" | assert rows.pop() == "", "Missing trailing newline" | ||||
# The only two possible last lines | # The only two possible last lines | ||||
assert rows[-1] in [ | assert rows[-1] in [ | ||||
"swh:1:ori:83404f995118bd25774f4ac14422a8f175e7a054,1,0" | "swh:1:ori:83404f995118bd25774f4ac14422a8f175e7a054,1,0" | ||||
",swh:1:snp:0000000000000000000000000000000000000020,", | ",swh:1:snp:0000000000000000000000000000000000000020,", | ||||
"swh:1:rel:0000000000000000000000000000000000000019,1,0" | "swh:1:rel:0000000000000000000000000000000000000019,1,0" | ||||
",swh:1:rev:0000000000000000000000000000000000000018,", | ",swh:1:rev:0000000000000000000000000000000000000018,", | ||||
] | ] |