import importlib.util import json import pathlib import tempfile import unittest ROOT = pathlib.Path(__file__).resolve().parents[2] SPEC = importlib.util.spec_from_file_location( "nextpath_catalog_refresh", ROOT / "scripts" / "nextpath-catalog-refresh.py" ) MODULE = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(MODULE) class NextPathCatalogRefreshTests(unittest.TestCase): def test_atomic_json_replaces_catalog_with_private_permissions(self): with tempfile.TemporaryDirectory() as temporary: path = pathlib.Path(temporary) / "catalog.json" path.write_text("old") MODULE.atomic_json(path, {"version": "generated", "occupations": []}) self.assertEqual(json.loads(path.read_text())["version"], "generated") self.assertEqual(path.stat().st_mode & 0o777, 0o600) def test_riasec_codes_cover_every_official_interest_name(self): self.assertEqual(set(MODULE.RIASEC_CODES), set(MODULE.RIASEC)) self.assertEqual(set(MODULE.RIASEC_CODES.values()), set("RIASEC")) if __name__ == "__main__": unittest.main()