-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·58 lines (44 loc) · 1.57 KB
/
Copy pathrun_tests.py
File metadata and controls
executable file
·58 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""Tests for jdlint."""
from __future__ import annotations
import contextlib
import json
import os
import unittest
from pathlib import Path, PurePath
import tomllib
import jdlint
class AllTests(unittest.TestCase):
"""Locate and run all tests."""
def tests(self) -> None:
"""Locate and run all tests."""
self.maxDiff = None # Show full diff
# Find all tests
with os.scandir(PurePath("tests")) as test_it:
for f in test_it:
# Make a sub-test and open result file
with (
self.subTest(msg=f.name, f=f),
Path(
f,
"result.json",
).open() as golden_file,
Path(f, "jdlint.toml").open("rb") as config_file,
contextlib.chdir(f),
):
# Load config
config = jdlint.Config(tomllib.load(config_file))
# Lint the test directory
results = jdlint.lint_system(config)
expected = json.load(golden_file)
# Convert lint results into loaded format
actual = json.loads(
json.dumps(
results,
cls=jdlint._EnhancedJSONEncoder,
),
)
# Compare results
self.assertEqual(expected, actual) # noqa: PT009
if __name__ == "__main__":
unittest.main()