Skip to content

Commit d63d682

Browse files
authored
Merge pull request #143 from abravalheri/add-tests-to-ci
Add github workflow for tests
2 parents 17969a7 + 03d44db commit d63d682

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

.github/workflows/tests.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: tests
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
concurrency:
6+
group: >-
7+
${{ github.workflow }}-
8+
${{ github.ref_type }}-
9+
${{ github.event.pull_request.number || github.sha }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
test:
14+
strategy:
15+
matrix:
16+
python:
17+
- 3.7 # oldest Python supported by PSF
18+
- "3.10" # newest Python that is stable
19+
platform:
20+
- ubuntu-latest
21+
- macos-latest
22+
- windows-latest
23+
runs-on: ${{ matrix.platform }}
24+
steps:
25+
- uses: actions/checkout@v2
26+
- name: Setup Python
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python }}
30+
- name: Run tests
31+
run: pipx run tox -e py -- -vvv

tests/test_compile_to_code.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_compile_to_code_custom_format():
9999
assert exc.value.message == "data must be my-format"
100100

101101

102-
def test_compile_to_code_custom_format_with_refs():
102+
def test_compile_to_code_custom_format_with_refs(tmp_path, monkeypatch):
103103
schema = {
104104
'type': 'object',
105105
'properties': {
@@ -115,9 +115,12 @@ def test_compile_to_code_custom_format_with_refs():
115115
}
116116
formats = {'my-format': str.isidentifier}
117117
code = compile_to_code(schema, formats=formats)
118-
with open('temp/schema_4.py', 'w') as f:
119-
f.write(code)
120-
from temp.schema_4 import validate
118+
119+
(tmp_path / "schema_4.py").write_text(code, encoding="utf-8")
120+
with monkeypatch.context() as m:
121+
m.syspath_prepend(tmp_path)
122+
from schema_4 import validate
123+
121124
assert validate({"a": ["identifier"]}, formats) is not None
122125
with pytest.raises(JsonSchemaValueException) as exc:
123126
validate({"a": ["identifier", "not-valid"]}, formats)

tests/test_examples.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030
def test_validate(example_group):
3131
example_dir = EXAMPLES / example_group
3232
schema = next(example_dir.glob("*.schema.json"))
33-
validator = compile(json.loads(schema.read_text()))
33+
validator = compile(json.loads(schema.read_text(encoding="utf-8")))
3434
examples = (
35-
(e, e.with_suffix(".error"), json.loads(e.read_text()))
35+
(e, e.with_suffix(".error"), json.loads(e.read_text(encoding="utf-8")))
3636
for e in example_dir.glob("*.json")
3737
if not str(e).endswith(".schema.json")
3838
)
3939
for example_file, err_file, example in examples:
4040
if err_file.exists():
4141
with pytest.raises(JsonSchemaException) as exc_info:
4242
validator(example)
43-
assert err_file.read_text().strip() in str(exc_info.value).strip()
43+
assert err_file.read_text(encoding="utf-8").strip() in str(exc_info.value).strip()
4444
else:
4545
validator(example) # valid

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ envlist = py{34,35,36,37},lint
1010
deps =
1111
pytest
1212
commands =
13-
pytest -m "not benchmark"
13+
pytest -m "not benchmark" {posargs}
1414

1515
[testenv:lint]
1616
deps =

0 commit comments

Comments
 (0)