forked from JPEWdev/shacl2code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
102 lines (79 loc) · 2.09 KB
/
Copy pathconftest.py
File metadata and controls
102 lines (79 loc) · 2.09 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#
# Copyright (c) 2024 Joshua Watt
#
# SPDX-License-Identifier: MIT
import json
import os
import shutil
import subprocess
import time
from pathlib import Path
import pytest
from testfixtures.httpserver import HTTPTestServer
THIS_FILE = Path(__file__)
THIS_DIR = THIS_FILE.parent
DATA_DIR = THIS_DIR / "data"
MODEL_DIR = DATA_DIR / "model"
@pytest.fixture
def http_server():
with HTTPTestServer() as s:
s.start()
yield s
@pytest.fixture(scope="session")
def model_server():
with HTTPTestServer() as s:
for p in MODEL_DIR.iterdir():
if not p.is_file():
continue
shutil.copyfile(p, s.document_root / p.name)
s.start()
yield s.uri
@pytest.fixture(scope="session")
def test_context_url(model_server):
yield model_server + "/test-context.json"
@pytest.fixture(scope="session")
def test_jsonschema(model_server, test_context_url):
p = subprocess.run(
[
"shacl2code",
"generate",
"--input",
MODEL_DIR / "test.ttl",
"--context",
test_context_url,
"--jss-signature",
"signatures",
"jsonschema",
"--output",
"-",
],
check=True,
stdout=subprocess.PIPE,
encoding="utf-8",
)
yield json.loads(p.stdout)
@pytest.fixture(scope="function")
def test_timezone():
try:
current_tz = os.environ["TZ"]
except KeyError:
current_tz = None
os.environ["TZ"] = "TST+02"
time.tzset()
try:
yield
finally:
if current_tz is None:
del os.environ["TZ"]
else:
os.environ["TZ"] = current_tz
time.tzset()
@pytest.fixture(scope="session")
def roundtrip(tmp_path_factory, model_server):
outfile = tmp_path_factory.mktemp("roundtrip") / "roundtrip.json"
with (DATA_DIR / "roundtrip.json").open("r") as f:
data = f.read()
data = data.replace("@CONTEXT_URL@", model_server + "/test-context.json")
with outfile.open("w") as f:
f.write(data)
yield outfile