-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest_common.py
More file actions
163 lines (104 loc) · 4.22 KB
/
test_common.py
File metadata and controls
163 lines (104 loc) · 4.22 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import shutil
import sys
from pathlib import Path
import pytest
def test_mono(example_netstandard: Path):
from clr_loader import get_mono
mono = get_mono()
asm = mono.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def test_mono_debug(example_netstandard: Path):
from clr_loader import get_mono
mono = get_mono(
debug=True,
jit_options=[
"--debugger-agent=address=0.0.0.0:5831,transport=dt_socket,server=y"
],
)
asm = mono.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def test_mono_signal_chaining(example_netstandard: Path):
from clr_loader import get_mono
mono = get_mono(set_signal_chaining=True)
asm = mono.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def test_mono_trace_mask(example_netstandard: Path):
from clr_loader import get_mono
mono = get_mono(trace_mask="all")
asm = mono.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def test_mono_trace_level(example_netstandard: Path):
from clr_loader import get_mono
mono = get_mono(trace_level="message")
asm = mono.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def test_mono_set_dir(example_netstandard: Path):
from clr_loader import get_mono
mono = get_mono(assembly_dir="/usr", config_dir="/etc")
asm = mono.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def test_coreclr(example_netcore: Path):
from clr_loader import get_coreclr
coreclr = get_coreclr(runtime_config=example_netcore / "example.runtimeconfig.json")
asm = coreclr.get_assembly(example_netcore / "example.dll")
run_tests(asm)
def test_coreclr_command_line(example_netcore: Path):
run_in_subprocess(_do_test_coreclr_command_line, example_netcore)
def _do_test_coreclr_command_line(example_netcore: Path):
from clr_loader import get_coreclr
coreclr = get_coreclr(entry_dll=example_netcore / "example.dll")
asm = coreclr.get_assembly(example_netcore / "example.dll")
run_tests(asm)
def test_coreclr_properties(example_netcore: Path):
run_in_subprocess(
_do_test_coreclr_autogenerated_runtimeconfig,
example_netcore,
APP_CONTEXT_BASE_DIRECTORY=str(example_netcore),
)
def test_coreclr_autogenerated_runtimeconfig(example_netstandard: Path):
run_in_subprocess(_do_test_coreclr_autogenerated_runtimeconfig, example_netstandard)
def _do_test_coreclr_autogenerated_runtimeconfig(
example_netstandard: Path, **properties: str
):
from clr_loader import get_coreclr
coreclr = get_coreclr(properties=properties)
asm = coreclr.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
@pytest.mark.skipif(
sys.platform != "win32", reason=".NET Framework only exists on Windows"
)
def test_netfx(example_netstandard: Path):
run_in_subprocess(_do_test_netfx, example_netstandard)
@pytest.mark.skipif(
sys.platform != "win32", reason=".NET Framework only exists on Windows"
)
def test_netfx_chinese_path(example_netstandard: Path, tmpdir_factory):
tmp_path = Path(tmpdir_factory.mktemp("example-中国"))
shutil.copytree(example_netstandard, tmp_path, dirs_exist_ok=True)
run_in_subprocess(_do_test_netfx, tmp_path)
@pytest.mark.skipif(
sys.platform != "win32", reason=".NET Framework only exists on Windows"
)
def test_netfx_separate_domain(example_netstandard):
run_in_subprocess(_do_test_netfx, example_netstandard, domain="some domain")
def _do_test_netfx(example_netstandard, **kwargs):
from clr_loader import get_netfx
netfx = get_netfx(**kwargs)
asm = netfx.get_assembly(example_netstandard / "example.dll")
run_tests(asm)
def run_tests(asm):
func = asm.get_function("Example.TestClass", "Test")
test_data = b"testy mctestface"
res = func(test_data)
assert res == len(test_data)
def run_in_subprocess(func, *args, **kwargs):
from multiprocessing import get_context
p = get_context("spawn").Process(target=func, args=args, kwargs=kwargs)
p.start()
p.join()
try:
assert p.exitcode == 0, (
f"Subprocess {func.__name__!r} failed with exit code {p.exitcode}"
)
finally:
p.close()