Skip to content

Commit b7ec900

Browse files
committed
Add simple test of find_duplicates
Check that it correctly identifies files with duplicate contents. Signed-off-by: John Pennycook <[email protected]>
1 parent 5ea5c4d commit b7ec900

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/duplicates/test_duplicates.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import Path
99

1010
from codebasin import CodeBase, finder
11+
from codebasin.report import find_duplicates
1112

1213

1314
class TestDuplicates(unittest.TestCase):
@@ -117,6 +118,20 @@ def test_symlink_files(self):
117118
setmap = state.get_setmap(codebase)
118119
self.assertDictEqual(setmap, expected_setmap, "Mismatch in setmap")
119120

121+
def test_find_duplicates(self):
122+
"""Check that we can correctly identify duplicate files."""
123+
tmp = tempfile.TemporaryDirectory()
124+
path = Path(tmp.name)
125+
with open(path / "foo.cpp", mode="w") as f:
126+
f.write("void foo();")
127+
with open(path / "bar.cpp", mode="w") as f:
128+
f.write("void foo();")
129+
codebase = CodeBase(path)
130+
131+
duplicates = find_duplicates(codebase)
132+
expected_duplicates = [{path / "foo.cpp", path / "bar.cpp"}]
133+
self.assertCountEqual(duplicates, expected_duplicates)
134+
120135
tmp.cleanup()
121136

122137

0 commit comments

Comments
 (0)