import json from pathlib import Path import tempfile import unittest import sys sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'scripts')) from sync import sync class SyncTest(unittest.TestCase): def test_filter_update_delete_and_invalid_input(self): with tempfile.TemporaryDirectory() as d: base=Path(d) src=base/'source'; dst=base/'output' for rel in ['cve/2016/old.json','cve/2025/current.json','usn/USN-1.json']: p=src/rel;p.parent.mkdir(parents=True,exist_ok=True);p.write_text(json.dumps({'id':rel})) st=sync(src,dst,2017) self.assertEqual(st['files'],2) self.assertFalse((dst/'cve/2016/old.json').exists()) self.assertEqual(sync(src,dst,2017)['updated'],0) (src/'cve/2025/current.json').unlink() st=sync(src,dst,2017) self.assertEqual(st['removed'],1) bad=src/'cve/2026/bad.json';bad.parent.mkdir(parents=True,exist_ok=True);bad.write_text('not-json') with self.assertRaises(ValueError):sync(src,dst,2017) self.assertTrue((dst/'usn/USN-1.json').exists()) if __name__=='__main__':unittest.main()