-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
54 lines (44 loc) · 1.67 KB
/
conftest.py
File metadata and controls
54 lines (44 loc) · 1.67 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
import json
import pytest # noqa: F401
collect_ignore = ["src/memwiper/utils/_coretest.py"]
def pytest_addoption(parser):
parser.addoption(
"--basicfile",
action="append",
default=["tests/basictest.txt"],
help="File used to load strings for test, "
"we provide a default one (basictest.txt)",
)
parser.addoption(
"--widefile",
action="append",
default=["tests/widetest.txt"],
help="A JSON file that let define the test "
"of the differents char wides.\n"
"We provide a default one (widetest.txt)",
)
def pytest_generate_tests(metafunc): # pragma: no cover
strings = None
filename = None
parametrize_to = None
if "basicteststr" in metafunc.fixturenames:
filename = metafunc.config.option.basicfile[0]
parametrize_to = "basicteststr"
if "wideteststr" in metafunc.fixturenames:
filename = metafunc.config.option.widefile[0]
parametrize_to = "wideteststr"
if "widetestchar" in metafunc.fixturenames:
filename = metafunc.config.option.widefile[0]
parametrize_to = "widetestchar"
if filename:
with open(filename, "r", encoding="utf_8") as f:
strings = f.readlines()
if "wideteststr" in metafunc.fixturenames:
strings = "".join([x for x in strings if not x.startswith("#")])
strings = json.loads(strings)["strings"].values()
if "widetestchar" in metafunc.fixturenames:
strings = "".join([x for x in strings if not x.startswith("#")])
strings = json.loads(strings)["chars"].values()
if parametrize_to:
metafunc.parametrize(parametrize_to, strings)
return