Mercurial > hgrepos > Python > libs > data-schema
comparison tests/test_schema.py @ 16:2a9e7c4b717e
Problem severity now is also an enum
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 07 Jul 2023 02:33:28 +0200 |
| parents | 696b83f29363 |
| children | c3a0fe8d4587 |
comparison
equal
deleted
inserted
replaced
| 15:696b83f29363 | 16:2a9e7c4b717e |
|---|---|
| 8 | 8 |
| 9 import configmix.yaml | 9 import configmix.yaml |
| 10 | 10 |
| 11 import data_schema | 11 import data_schema |
| 12 import data_schema.util | 12 import data_schema.util |
| 13 from data_schema import ERRORS, WARNINGS | 13 from data_schema import SEVERITY, ERRORS, WARNINGS |
| 14 | 14 |
| 15 | 15 |
| 16 TYPE_RE = type(re.compile(r"\A.+\Z")) | 16 TYPE_RE = type(re.compile(r"\A.+\Z")) |
| 17 | 17 |
| 18 | 18 |
| 1332 | 1332 |
| 1333 def test_enum_name(self): | 1333 def test_enum_name(self): |
| 1334 code = ERRORS.E10001 | 1334 code = ERRORS.E10001 |
| 1335 self.assertEqual("ERRORS.E10001", str(code)) | 1335 self.assertEqual("ERRORS.E10001", str(code)) |
| 1336 self.assertEqual("E10001", code.name) | 1336 self.assertEqual("E10001", code.name) |
| 1337 self.assertTrue(isinstance(code, ERRORS)) | |
| 1337 | 1338 |
| 1338 def test_schema_must_be_a_dict_alike(self): | 1339 def test_schema_must_be_a_dict_alike(self): |
| 1339 try: | 1340 try: |
| 1340 pr = list(data_schema.validate(None, None)) | 1341 pr = list(data_schema.validate(None, None)) |
| 1341 except data_schema.SchemaError: | 1342 except data_schema.SchemaError: |
| 1347 def test_problem_ctor_no_code(self): | 1348 def test_problem_ctor_no_code(self): |
| 1348 self.assertRaises(TypeError, data_schema.ValidationProblem, code=None) | 1349 self.assertRaises(TypeError, data_schema.ValidationProblem, code=None) |
| 1349 | 1350 |
| 1350 def test_error_ctor(self): | 1351 def test_error_ctor(self): |
| 1351 v = data_schema.ValidationProblem(code=ERRORS.E10000) | 1352 v = data_schema.ValidationProblem(code=ERRORS.E10000) |
| 1352 self.assertEqual(data_schema.ERROR, v.severity) | 1353 self.assertEqual(SEVERITY.ERROR, v.severity) |
| 1353 | 1354 |
| 1354 def test_warning_ctor(self): | 1355 def test_warning_ctor(self): |
| 1355 v = data_schema.ValidationProblem(code=WARNINGS.W80000) | 1356 v = data_schema.ValidationProblem(code=WARNINGS.W80000) |
| 1356 self.assertEqual(data_schema.WARNING, v.severity) | 1357 self.assertEqual(SEVERITY.WARNING, v.severity) |
| 1357 | 1358 |
| 1358 def test_d1(self): | 1359 def test_d1(self): |
| 1359 x = list(data_schema.validate({}, {"type": "dict"})) | 1360 x = list(data_schema.validate({}, {"type": "dict"})) |
| 1360 self.assertEqual(0, len(x)) | 1361 self.assertEqual(0, len(x)) |
| 1361 | 1362 |
| 1370 self.assertEqual(0, len(x)) | 1371 self.assertEqual(0, len(x)) |
| 1371 | 1372 |
| 1372 def test_d2(self): | 1373 def test_d2(self): |
| 1373 x = list(data_schema.validate([], {"type": "map"})) | 1374 x = list(data_schema.validate([], {"type": "map"})) |
| 1374 self.assertEqual(1, len(x)) | 1375 self.assertEqual(1, len(x)) |
| 1375 self.assertEqual(data_schema.ERROR, x[0].severity) | 1376 self.assertEqual(SEVERITY.ERROR, x[0].severity) |
| 1376 self.assertEqual(ERRORS.E10000, x[0].code) | 1377 self.assertEqual(ERRORS.E10000, x[0].code) |
| 1377 | 1378 |
| 1378 def test_d3(self): | 1379 def test_d3(self): |
| 1379 x = list(data_schema.validate( | 1380 x = list(data_schema.validate( |
| 1380 {"key": "value"}, | 1381 {"key": "value"}, |
| 1381 {"type": "dict", | 1382 {"type": "dict", |
| 1382 "required": ["key2"]})) | 1383 "required": ["key2"]})) |
| 1383 self.assertEqual(2, len(x)) | 1384 self.assertEqual(2, len(x)) |
| 1384 self.assertEqual(data_schema.ERROR, x[0].severity) | 1385 self.assertEqual(SEVERITY.ERROR, x[0].severity) |
| 1385 self.assertEqual(ERRORS.E10004, x[0].code) | 1386 self.assertEqual(ERRORS.E10004, x[0].code) |
| 1386 self.assertEqual("key", x[0].hint) | 1387 self.assertEqual("key", x[0].hint) |
| 1387 self.assertEqual(data_schema.ERROR, x[1].severity) | 1388 self.assertEqual(SEVERITY.ERROR, x[1].severity) |
| 1388 self.assertEqual(ERRORS.E10005, x[1].code) | 1389 self.assertEqual(ERRORS.E10005, x[1].code) |
| 1389 self.assertEqual(["key2"], x[1].hint) | 1390 self.assertEqual(["key2"], x[1].hint) |
| 1390 | 1391 |
| 1391 def test_d4(self): | 1392 def test_d4(self): |
| 1392 x = list(data_schema.validate( | 1393 x = list(data_schema.validate( |
