mirror of
https://github.com/sist2app/sist2.git
synced 2025-05-11 12:25:54 +02:00
Remove UUID dep, fix incremental scan, use MD5(path) as unique id, version bump
This commit is contained in:
parent
c6e1ba03bc
commit
050c1283a3
29 changed files with 352 additions and 179 deletions
75
tests/test_scan.py
Normal file
75
tests/test_scan.py
Normal file
|
@ -0,0 +1,75 @@
|
|||
import unittest
|
||||
import subprocess
|
||||
import shutil
|
||||
import json
|
||||
import os
|
||||
|
||||
TEST_FILES = "third-party/libscan/libscan-test-files/test_files"
|
||||
|
||||
|
||||
def copy_files(files):
|
||||
base = os.path.basename(files)
|
||||
new_path = os.path.join("/tmp/sist2_test/", base)
|
||||
|
||||
shutil.rmtree(new_path, ignore_errors=True)
|
||||
shutil.copytree(files, new_path)
|
||||
return new_path
|
||||
|
||||
|
||||
def sist2(*args):
|
||||
return subprocess.check_output(
|
||||
args=["./sist2_debug", *args],
|
||||
)
|
||||
|
||||
|
||||
def sist2_index(files, *args):
|
||||
path = copy_files(files)
|
||||
|
||||
shutil.rmtree("i", ignore_errors=True)
|
||||
sist2("scan", path, "-o", "i", *args)
|
||||
return iter(sist2_index_to_dict("i"))
|
||||
|
||||
|
||||
def sist2_incremental_index(files, func=None, *args):
|
||||
path = copy_files(files)
|
||||
|
||||
if func:
|
||||
func(path)
|
||||
|
||||
shutil.rmtree("i_inc", ignore_errors=True)
|
||||
sist2("scan", path, "-o", "i_inc", "--incremental", "i", *args)
|
||||
return iter(sist2_index_to_dict("i_inc"))
|
||||
|
||||
|
||||
def sist2_index_to_dict(index):
|
||||
res = subprocess.check_output(
|
||||
args=["./sist2_debug", "index", "--print", index],
|
||||
)
|
||||
|
||||
for line in res.splitlines():
|
||||
if line:
|
||||
yield json.loads(line)
|
||||
|
||||
|
||||
class ScanTest(unittest.TestCase):
|
||||
|
||||
def test_incremental1(self):
|
||||
def remove_files(path):
|
||||
os.remove(os.path.join(path, "msdoc/test1.doc"))
|
||||
os.remove(os.path.join(path, "msdoc/test2.doc"))
|
||||
|
||||
def add_files(path):
|
||||
with open(os.path.join(path, "newfile1"), "w"):
|
||||
pass
|
||||
with open(os.path.join(path, "newfile2"), "w"):
|
||||
pass
|
||||
with open(os.path.join(path, "newfile3"), "w"):
|
||||
pass
|
||||
|
||||
file_count = sum(1 for _ in sist2_index(TEST_FILES))
|
||||
self.assertEqual(sum(1 for _ in sist2_incremental_index(TEST_FILES, remove_files)), file_count - 2)
|
||||
self.assertEqual(sum(1 for _ in sist2_incremental_index(TEST_FILES, add_files)), file_count + 3)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue