Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
spec = importlib.util.spec_from_file_location("catalogue_generator", ROOT / "scripts/prepare-geography-catalogue.py")
|
||||
generator = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(generator)
|
||||
|
||||
|
||||
class CatalogueBytesTest(unittest.TestCase):
|
||||
def test_serialization_keeps_unicode_and_approved_line_ending(self):
|
||||
data = {"name": "Mo\u00e7ambique", "records": []}
|
||||
result = generator.catalogue_bytes(data)
|
||||
self.assertEqual(result, b'{"name":"Mo\xc3\xa7ambique","records":[]}\r\n')
|
||||
self.assertEqual(json.loads(result), data)
|
||||
|
||||
def test_real_catalogue_reproduces_the_accepted_artifact_hash(self):
|
||||
content = (ROOT / "resources/data/geography/cartografia-moz.json").read_bytes()
|
||||
data = json.loads(content)
|
||||
expected = "28530f11f528e6f715396991e1294872c7e6a8b260d08a84e7d8fe17e5920457"
|
||||
self.assertEqual(hashlib.sha256(content).hexdigest(), expected)
|
||||
self.assertEqual(generator.catalogue_bytes(data), content)
|
||||
self.assertEqual(len(data["records"]), 20407)
|
||||
self.assertEqual(data["manifest"]["source_sha256"], "70996d9a9133785a848de90bedb4bf685e24d8f823cd153c0adc43eac642a292")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user