test(python): Bring the suite tests back
This commit is contained in:
parent
dee71c7c56
commit
4da2f0d2bb
|
@ -7,11 +7,13 @@ import pytest
|
|||
|
||||
import jsonschema_rs
|
||||
|
||||
TEST_SUITE_PATH = "../../jsonschema/tests/suite"
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def mock_server():
|
||||
process = subprocess.Popen(args=[sys.executable, f"{TEST_SUITE_PATH}/bin/jsonschema_suite", "serve"])
|
||||
try:
|
||||
process = subprocess.Popen(args=[sys.executable, "../tests/suite/bin/jsonschema_suite", "serve"])
|
||||
yield
|
||||
finally:
|
||||
process.terminate()
|
||||
|
@ -19,9 +21,9 @@ def mock_server():
|
|||
|
||||
SUPPORTED_DRAFTS = (4, 6, 7)
|
||||
NOT_SUPPORTED_CASES = {
|
||||
4: ("bignum.json",),
|
||||
6: ("bignum.json",),
|
||||
7: ("bignum.json", "idn-hostname.json"), # https://github.com/Stranger6667/jsonschema-rs/issues/101
|
||||
4: ("bignum.json", "float-overflow.json", "email.json"),
|
||||
6: ("bignum.json", "float-overflow.json", "email.json"),
|
||||
7: ("bignum.json", "float-overflow.json", "email.json", "idn-hostname.json"),
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,9 +36,7 @@ def load_file(path):
|
|||
def maybe_optional(draft, schema, instance, expected, description, filename):
|
||||
output = (filename, draft, schema, instance, expected, description)
|
||||
if filename in NOT_SUPPORTED_CASES.get(draft, ()):
|
||||
output = pytest.param(
|
||||
*output, marks=pytest.mark.skip(reason="{filename} is not supported".format(filename=filename))
|
||||
)
|
||||
output = pytest.param(*output, marks=pytest.mark.skip(reason=f"{filename} is not supported"))
|
||||
return output
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ def pytest_generate_tests(metafunc):
|
|||
cases = [
|
||||
maybe_optional(draft, block["schema"], test["data"], test["valid"], test["description"], filename)
|
||||
for draft in SUPPORTED_DRAFTS
|
||||
for root, dirs, files in os.walk("../tests/suite/tests/draft{draft}/".format(draft=draft))
|
||||
for root, dirs, files in os.walk(f"{TEST_SUITE_PATH}/tests/draft{draft}/")
|
||||
for filename in files
|
||||
for block in load_file(os.path.join(root, filename))
|
||||
for test in block["tests"]
|
||||
|
@ -53,17 +53,9 @@ def pytest_generate_tests(metafunc):
|
|||
|
||||
|
||||
def test_draft(filename, draft, schema, instance, expected, description):
|
||||
error_message = f"[{filename}] {description}: {schema} | {instance}"
|
||||
try:
|
||||
result = jsonschema_rs.is_valid(schema, instance, int(draft))
|
||||
assert result is expected, "[{filename}] {description}: {schema} | {instance}".format(
|
||||
description=description,
|
||||
schema=schema,
|
||||
instance=instance,
|
||||
filename=filename,
|
||||
)
|
||||
assert result is expected, error_message
|
||||
except ValueError:
|
||||
pytest.fail(
|
||||
"[{filename}] {description}: {schema} | {instance}".format(
|
||||
description=description, schema=schema, instance=instance, filename=filename
|
||||
)
|
||||
)
|
||||
pytest.fail(error_message)
|
||||
|
|
Loading…
Reference in New Issue