-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
86 lines (82 loc) · 2.45 KB
/
conftest.py
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
import pytest
from re import sub
from subprocess import run
def pytest_addoption(parser):
parser.addoption(
"--compare", action="store", default=None,
help="Print test items in my custom format"
)
def pytest_collection_finish(session):
f = open("__pycache__/cargo.tests", "w")
run(
['cargo', 'test', '--tests', '--', '--list', '--format=terse'],
stdout=f, stderr=0
)
f.close()
run(
['sed', '-i', 's@: test@@', '__pycache__/cargo.tests']
)
# remove monte carlo tests
run(
['sed', '-i', '-r', '/monte/d', '__pycache__/cargo.tests']
)
f = open("__pycache__/julia.tests", "w")
run(
['grep', '-r', '@testset', 'src/'],
stdout=f, stderr=0
)
f.close()
run(
['sed', '-i', 's@^.*testset "@@', '__pycache__/julia.tests']
)
run(
['sed', '-i', 's@".*$@@', '__pycache__/julia.tests']
)
stdout = open('__pycache__/pytest.tests', 'w')
if session.config.option.compare is not None:
for item in session.items:
class_name = sub(
r'(?<!^)(?=[A-Z])', '_', item.parent.name
).lower()
stdout.write(
'{}::{}::{}\n'.format(
item.fspath, class_name, item.name
)
)
stdout.close()
run(
['sed', '-i', '[email protected]::@::@', '__pycache__/pytest.tests']
)
run(
['sed', '-i', 's@test_@@', '__pycache__/pytest.tests']
)
run(
['sed', '-i', 's@^.*src/@@', '__pycache__/pytest.tests']
)
run(
['sed', '-i', 's@/@::@g', '__pycache__/pytest.tests']
)
run(
['sort', '__pycache__/cargo.tests',
'-o', '__pycache__/cargo.tests']
)
run(
['sort', '__pycache__/pytest.tests',
'-o', '__pycache__/pytest.tests']
)
run(
['sort', '__pycache__/julia.tests',
'-o', '__pycache__/julia.tests']
)
code = run(
['cmp', '-s', '__pycache__/cargo.tests',
'__pycache__/pytest.tests']
).returncode
code += run(
['cmp', '-s', '__pycache__/cargo.tests',
'__pycache__/julia.tests']
).returncode
if code == 0:
pytest.exit('tests match across languages', code)
else:
pytest.exit('tests do not match across languages', code)