32 lines
905 B
Python
32 lines
905 B
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from govoplan_core.core.datasources import DatasourceValidationError
|
|
from govoplan_datasources.backend.tabular import (
|
|
fingerprint_rows,
|
|
infer_schema,
|
|
parse_csv_rows,
|
|
)
|
|
|
|
|
|
class DatasourceTabularTests(unittest.TestCase):
|
|
def test_csv_schema_and_fingerprint_are_stable(self) -> None:
|
|
rows = parse_csv_rows("id;name\n1;Ada\n2;\n", delimiter=";")
|
|
schema = infer_schema(rows)
|
|
|
|
self.assertEqual(["id", "name"], [field.name for field in schema])
|
|
self.assertTrue(schema[1].nullable)
|
|
self.assertEqual(
|
|
fingerprint_rows(rows, schema),
|
|
fingerprint_rows(rows, schema),
|
|
)
|
|
|
|
def test_csv_requires_headers(self) -> None:
|
|
with self.assertRaises(DatasourceValidationError):
|
|
parse_csv_rows("", delimiter=",")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|