FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/tests/conftest.py at master · AdsTable/pythonnet · GitHub
AdsTable
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
tests
/
conftest.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
106 lines (81 loc) · 2.86 KB
Breadcrumbs
pythonnet
/
tests
/
conftest.py
Copy path
File metadata and controls
106 lines (81 loc) · 2.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# -*- coding: utf-8 -*-
# TODO: move tests one out of src to project root.
# TODO: travis has numpy on their workers. Maybe add tests?
"""Helpers for testing."""
import
ctypes
import
os
import
sys
import
sysconfig
from
subprocess
import
check_call
from
tempfile
import
mkdtemp
import
shutil
import
pytest
from
pythonnet
import
set_runtime
# Add path for `Python.Test`
cwd
=
os
.
path
.
dirname
(
__file__
)
fixtures_path
=
os
.
path
.
join
(
cwd
,
"fixtures"
)
sys
.
path
.
append
(
fixtures_path
)
def
pytest_addoption
(
parser
):
parser
.
addoption
(
"--runtime"
,
action
=
"store"
,
default
=
"default"
,
help
=
"Must be one of default, netcore, netfx and mono"
)
def
pytest_configure
(
config
):
global
bin_path
if
"clr"
in
sys
.
modules
:
# Already loaded (e.g. by the C# test runner), skip build
import
clr
clr
.
AddReference
(
"Python.Test"
)
return
runtime_opt
=
config
.
getoption
(
"runtime"
)
test_proj_path
=
os
.
path
.
join
(
cwd
,
".."
,
"src"
,
"testing"
)
if
runtime_opt
not
in
[
"netcore"
,
"netfx"
,
"mono"
,
"default"
]:
raise
RuntimeError
(
f"Invalid runtime:
{
runtime_opt
}
"
)
bin_path
=
mkdtemp
()
# tmpdir_factory.mktemp(f"pythonnet-{runtime_opt}")
fw
=
"net5.0"
if
runtime_opt
==
"netcore"
else
"netstandard2.0"
check_call
([
"dotnet"
,
"publish"
,
"-f"
,
fw
,
"-o"
,
bin_path
,
test_proj_path
])
sys
.
path
.
append
(
bin_path
)
if
runtime_opt
==
"default"
:
pass
elif
runtime_opt
==
"netfx"
:
from
clr_loader
import
get_netfx
runtime
=
get_netfx
()
set_runtime
(
runtime
)
elif
runtime_opt
==
"mono"
:
from
clr_loader
import
get_mono
runtime
=
get_mono
()
set_runtime
(
runtime
)
elif
runtime_opt
==
"netcore"
:
from
clr_loader
import
get_coreclr
rt_config_path
=
os
.
path
.
join
(
bin_path
,
"Python.Test.runtimeconfig.json"
)
runtime
=
get_coreclr
(
rt_config_path
)
set_runtime
(
runtime
)
import
clr
clr
.
AddReference
(
"Python.Test"
)
def
pytest_unconfigure
(
config
):
global
bin_path
try
:
shutil
.
rmtree
(
bin_path
)
except
Exception
:
pass
def
pytest_report_header
(
config
):
"""Generate extra report headers"""
# FIXME: https://github.com/pytest-dev/pytest/issues/2257
is_64bits
=
sys
.
maxsize
>
2
**
32
arch
=
"x64"
if
is_64bits
else
"x86"
ucs
=
ctypes
.
sizeof
(
ctypes
.
c_wchar
)
libdir
=
sysconfig
.
get_config_var
(
"LIBDIR"
)
shared
=
bool
(
sysconfig
.
get_config_var
(
"Py_ENABLE_SHARED"
))
header
=
(
"Arch: {arch}, UCS: {ucs}, LIBDIR: {libdir}, "
"Py_ENABLE_SHARED: {shared}"
.
format
(
**
locals
()))
return
header
@
pytest
.
fixture
()
def
filepath
():
"""Returns full filepath for file in `fixtures` directory."""
def
make_filepath
(
filename
):
# http://stackoverflow.com/questions/18011902/parameter-to-a-fixture
return
os
.
path
.
join
(
fixtures_path
,
filename
)
return
make_filepath
Back
|
FazBrowse Home
|
New Git URL