-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtest_common.py
165 lines (105 loc) · 4.29 KB
/
test_common.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
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
164
165
import shutil
import pytest
from subprocess import check_call
import os
import sys
from pathlib import Path
@pytest.fixture(scope="session")
def example_netstandard(tmpdir_factory):
return build_example(tmpdir_factory, "netstandard20")
@pytest.fixture(scope="session")
def example_netcore(tmpdir_factory):
return build_example(tmpdir_factory, "net60")
def build_example(tmpdir_factory, framework):
out = Path(tmpdir_factory.mktemp(f"example-{framework}"))
proj_path = Path(__file__).parent.parent / "example" / "example.csproj"
check_call(["dotnet", "build", str(proj_path), "-o", str(out), "-f", framework])
return out
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/lib", 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_properties(example_netcore: Path):
run_in_subprocess(
_do_test_coreclr_autogenerated_runtimeconfig,
example_netstandard,
properties=dict(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
):
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()
p.close()