utilotest 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- power/__init__.py +17 -0
- utilotest/__init__.py +99 -0
- utilotest/baseline.py +144 -0
- utilotest/call.py +151 -0
- utilotest/cli/__init__.py +8 -0
- utilotest/cli/tracer.py +62 -0
- utilotest/config.py +16 -0
- utilotest/file.py +87 -0
- utilotest/install.py +49 -0
- utilotest/log.py +58 -0
- utilotest/runner.py +168 -0
- utilotest/select.py +126 -0
- utilotest/shortcuts.py +20 -0
- utilotest/utils.py +144 -0
- utilotest-1.0.1.dist-info/METADATA +21 -0
- utilotest-1.0.1.dist-info/RECORD +22 -0
- utilotest-1.0.1.dist-info/WHEEL +5 -0
- utilotest-1.0.1.dist-info/entry_points.txt +2 -0
- utilotest-1.0.1.dist-info/top_level.txt +3 -0
- viewvisitor/__init__.py +20 -0
- viewvisitor/fixture.py +43 -0
- viewvisitor/fuchs/geckodriver.exe +0 -0
power/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# REMOVE LATER
|
|
2
|
+
|
|
3
|
+
DOCU007_PDF = "abc/docu/docu007.pdf"
|
|
4
|
+
DOCU009_PDF = "abc/docu/docu009.pdf"
|
|
5
|
+
|
|
6
|
+
BACHELOR028_PDF = "abc/bachelor/bachelor028.pdf"
|
|
7
|
+
BACHELOR090_PDF = "abc/bachelor/bachelor090.pdf"
|
|
8
|
+
|
|
9
|
+
MASTER116_PDF = "abc/master/master116.pdf"
|
|
10
|
+
|
|
11
|
+
RESOURCES = [
|
|
12
|
+
DOCU007_PDF,
|
|
13
|
+
DOCU009_PDF,
|
|
14
|
+
BACHELOR028_PDF,
|
|
15
|
+
BACHELOR090_PDF,
|
|
16
|
+
MASTER116_PDF,
|
|
17
|
+
]
|
utilotest/__init__.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#==============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
#------------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
#==============================================================================
|
|
9
|
+
|
|
10
|
+
import importlib.metadata
|
|
11
|
+
import os
|
|
12
|
+
|
|
13
|
+
# baseline
|
|
14
|
+
from utilotest.baseline import BaseLineMixin
|
|
15
|
+
from utilotest.baseline import BaseLiner
|
|
16
|
+
# api calls
|
|
17
|
+
from utilotest.call import API_PREFIX
|
|
18
|
+
from utilotest.call import apicall
|
|
19
|
+
from utilotest.call import apidelete
|
|
20
|
+
from utilotest.call import apipost
|
|
21
|
+
from utilotest.call import apiput
|
|
22
|
+
from utilotest.call import apiupload
|
|
23
|
+
from utilotest.call import decode
|
|
24
|
+
from utilotest.call import delete
|
|
25
|
+
from utilotest.call import get
|
|
26
|
+
from utilotest.call import post
|
|
27
|
+
from utilotest.call import setup
|
|
28
|
+
from utilotest.call import upload
|
|
29
|
+
# file
|
|
30
|
+
from utilotest.file import increased_filecount
|
|
31
|
+
from utilotest.file import simplify_testfile_names
|
|
32
|
+
# install
|
|
33
|
+
from utilotest.install import clean_install
|
|
34
|
+
from utilotest.install import install_and_run
|
|
35
|
+
from utilotest.install import install_package
|
|
36
|
+
# log
|
|
37
|
+
from utilotest.log import log_raw
|
|
38
|
+
from utilotest.log import print_return
|
|
39
|
+
from utilotest.log import stderr
|
|
40
|
+
from utilotest.log import stdout
|
|
41
|
+
from utilotest.log import write_capsys
|
|
42
|
+
# run
|
|
43
|
+
from utilotest.runner import assert_failure
|
|
44
|
+
from utilotest.runner import assert_run
|
|
45
|
+
from utilotest.runner import assert_run_fail
|
|
46
|
+
from utilotest.runner import assert_success
|
|
47
|
+
from utilotest.runner import create_cli_runner
|
|
48
|
+
from utilotest.runner import run
|
|
49
|
+
from utilotest.runner import run_cov
|
|
50
|
+
from utilotest.runner import single_execution
|
|
51
|
+
# select
|
|
52
|
+
from utilotest.select import FASTRUN
|
|
53
|
+
from utilotest.select import LONGRUN
|
|
54
|
+
from utilotest.select import NIGHTLY
|
|
55
|
+
from utilotest.select import NONVIRTUAL
|
|
56
|
+
from utilotest.select import VIRTUAL
|
|
57
|
+
from utilotest.select import displayed
|
|
58
|
+
from utilotest.select import fixture_requires
|
|
59
|
+
from utilotest.select import hasbaw
|
|
60
|
+
from utilotest.select import hasgit
|
|
61
|
+
from utilotest.select import hasprog
|
|
62
|
+
from utilotest.select import holyvalue
|
|
63
|
+
from utilotest.select import linux
|
|
64
|
+
from utilotest.select import longrun
|
|
65
|
+
from utilotest.select import monday
|
|
66
|
+
from utilotest.select import nightly
|
|
67
|
+
from utilotest.select import no_cov
|
|
68
|
+
from utilotest.select import no_linux
|
|
69
|
+
from utilotest.select import no_win
|
|
70
|
+
from utilotest.select import nonvirtual
|
|
71
|
+
from utilotest.select import register_marker
|
|
72
|
+
from utilotest.select import requires
|
|
73
|
+
from utilotest.select import step
|
|
74
|
+
from utilotest.select import virtual
|
|
75
|
+
from utilotest.select import win
|
|
76
|
+
# shortcuts
|
|
77
|
+
from utilotest.shortcuts import mp
|
|
78
|
+
from utilotest.shortcuts import td
|
|
79
|
+
# utils
|
|
80
|
+
from utilotest.utils import assert_bin
|
|
81
|
+
from utilotest.utils import binhash
|
|
82
|
+
from utilotest.utils import is_ci
|
|
83
|
+
from utilotest.utils import open_webbrowser
|
|
84
|
+
from utilotest.utils import simple
|
|
85
|
+
from utilotest.utils import test_resources
|
|
86
|
+
from utilotest.utils import testid
|
|
87
|
+
from utilotest.utils import worker_count
|
|
88
|
+
|
|
89
|
+
__version__ = importlib.metadata.version('utilotest')
|
|
90
|
+
|
|
91
|
+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
92
|
+
PACKAGE = 'utilotest'
|
|
93
|
+
|
|
94
|
+
skip_longrun = longrun
|
|
95
|
+
skip_nightly = nightly
|
|
96
|
+
skip_nonvirtual = nonvirtual
|
|
97
|
+
skip_virtual = virtual
|
|
98
|
+
run_command = run_cov
|
|
99
|
+
# TODO: REMOVE log_raw with next increment
|
utilotest/baseline.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import contextlib
|
|
11
|
+
import functools
|
|
12
|
+
import os
|
|
13
|
+
|
|
14
|
+
import resinf
|
|
15
|
+
import utilo
|
|
16
|
+
|
|
17
|
+
import utilotest.config
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class BaseLineMixin:
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
cmd,
|
|
25
|
+
workdir,
|
|
26
|
+
index,
|
|
27
|
+
archive,
|
|
28
|
+
onfailure: callable = None,
|
|
29
|
+
):
|
|
30
|
+
self.cmd = cmd
|
|
31
|
+
self.workdir = workdir
|
|
32
|
+
self.index = index
|
|
33
|
+
self.archive = archive
|
|
34
|
+
self.onfailure = onfailure
|
|
35
|
+
|
|
36
|
+
def evaluate(self):
|
|
37
|
+
self.generate()
|
|
38
|
+
loaded = self.load()
|
|
39
|
+
rawvalue = self.raw(loaded)
|
|
40
|
+
expected, path = self.expected
|
|
41
|
+
if rawvalue != expected:
|
|
42
|
+
outpath = os.path.join(self.workdir, 'baseline')
|
|
43
|
+
utilo.error('write baseline')
|
|
44
|
+
utilo.file_create(outpath, rawvalue)
|
|
45
|
+
if utilotest.config.GIT_REPLACE:
|
|
46
|
+
# ease debugging due git --diff
|
|
47
|
+
withnewline = rawvalue.rstrip() + utilo.NEWLINE
|
|
48
|
+
utilo.file_replace(path, withnewline)
|
|
49
|
+
if self.onfailure:
|
|
50
|
+
self.onfailure(loaded)
|
|
51
|
+
if self.expected is None:
|
|
52
|
+
with contextlib.suppress(AttributeError):
|
|
53
|
+
self.backup(loaded)
|
|
54
|
+
return
|
|
55
|
+
elif rawvalue != expected:
|
|
56
|
+
utilo.log('EXPECTED:')
|
|
57
|
+
utilo.log(expected)
|
|
58
|
+
utilo.log('GIVEN:')
|
|
59
|
+
utilo.log(rawvalue)
|
|
60
|
+
assert rawvalue == expected
|
|
61
|
+
|
|
62
|
+
def generate(self):
|
|
63
|
+
if isinstance(self.cmd, str):
|
|
64
|
+
utilo.run(cmd=self.cmd, cwd=self.workdir)
|
|
65
|
+
return
|
|
66
|
+
# run partial function
|
|
67
|
+
self.cmd()
|
|
68
|
+
|
|
69
|
+
def raw(self, value) -> str: # pylint:disable=R0201
|
|
70
|
+
return str(value)
|
|
71
|
+
|
|
72
|
+
def load(self): # pylint:disable=R0201
|
|
73
|
+
return ''
|
|
74
|
+
|
|
75
|
+
@functools.cached_property
|
|
76
|
+
def expected(self) -> str:
|
|
77
|
+
inpath = os.path.join(self.archive, str(self.index))
|
|
78
|
+
if not os.path.exists(inpath):
|
|
79
|
+
utilo.error(f'empty archive data: {inpath}')
|
|
80
|
+
return None, inpath
|
|
81
|
+
loaded = utilo.file_read(inpath)
|
|
82
|
+
# rstrip to enable spaces as empty content of a expected tabel for
|
|
83
|
+
# example.
|
|
84
|
+
result = loaded.rstrip()
|
|
85
|
+
return result, inpath
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class BaseLiner(BaseLineMixin):
|
|
89
|
+
|
|
90
|
+
def __init__( # pylint:disable=R0913
|
|
91
|
+
self,
|
|
92
|
+
program,
|
|
93
|
+
step,
|
|
94
|
+
pages,
|
|
95
|
+
workdir,
|
|
96
|
+
source,
|
|
97
|
+
archive,
|
|
98
|
+
loader,
|
|
99
|
+
index=None,
|
|
100
|
+
convert_source: bool = True,
|
|
101
|
+
onfailure: callable = None,
|
|
102
|
+
):
|
|
103
|
+
"""\
|
|
104
|
+
onfailure(callable): run with given data if data differes from
|
|
105
|
+
expected
|
|
106
|
+
"""
|
|
107
|
+
super().__init__(
|
|
108
|
+
cmd=self.tocmd(program, step, pages, source, workdir,
|
|
109
|
+
convert_source),
|
|
110
|
+
workdir=workdir,
|
|
111
|
+
index=index if index else utilo.file_name(source),
|
|
112
|
+
archive=archive,
|
|
113
|
+
onfailure=onfailure,
|
|
114
|
+
)
|
|
115
|
+
self.loader = loader
|
|
116
|
+
self.source = source
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def tocmd(program, step, pages, source, workdir, convert_source=True):
|
|
120
|
+
source = convert_ifpossible(source, convert=convert_source)
|
|
121
|
+
assert not source or utilo.exists(source), str(source)
|
|
122
|
+
pages = f'--pages={pages}' if pages else ''
|
|
123
|
+
source = f'-i={source}' if source else ''
|
|
124
|
+
workdir = f'-o={workdir}' if workdir else ''
|
|
125
|
+
step = f'--{step}' if step else ''
|
|
126
|
+
todo = f'{step} {pages} {source} {workdir}'
|
|
127
|
+
if isinstance(program, str): # pylint:disable=W0160
|
|
128
|
+
result = f'{program} {todo}'
|
|
129
|
+
else:
|
|
130
|
+
result = functools.partial(program, todo)
|
|
131
|
+
return result
|
|
132
|
+
|
|
133
|
+
def load(self) -> str:
|
|
134
|
+
loaded = self.loader(self.workdir)
|
|
135
|
+
return loaded
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def convert_ifpossible(source, convert: bool = False):
|
|
139
|
+
if not source:
|
|
140
|
+
return ''
|
|
141
|
+
if not convert:
|
|
142
|
+
return source
|
|
143
|
+
source = resinf.link(source)
|
|
144
|
+
return source
|
utilotest/call.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import contextlib
|
|
11
|
+
import http
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
import utilo
|
|
16
|
+
|
|
17
|
+
API_PREFIX = 'UTILATEST_API_PREFIX'
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def decode(response, expected=None) -> dict:
|
|
21
|
+
"""Read binary data from response and convert them to str."""
|
|
22
|
+
assert expected is None or response.status_code == expected
|
|
23
|
+
result = response.data.decode('utf8')
|
|
24
|
+
with contextlib.suppress(json.decoder.JSONDecodeError):
|
|
25
|
+
# json format
|
|
26
|
+
return json.loads(result)
|
|
27
|
+
# html format
|
|
28
|
+
return result
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get(
|
|
32
|
+
client,
|
|
33
|
+
request: str,
|
|
34
|
+
expected=http.HTTPStatus.OK,
|
|
35
|
+
raw: bool = False,
|
|
36
|
+
):
|
|
37
|
+
response = client.get(request, follow_redirects=True)
|
|
38
|
+
assert response.status_code == expected, f'{request}:{response.status_code}\n{response}'
|
|
39
|
+
if raw:
|
|
40
|
+
return response
|
|
41
|
+
return decode(response)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def post(
|
|
45
|
+
client,
|
|
46
|
+
page: str,
|
|
47
|
+
data: dict,
|
|
48
|
+
expected=http.HTTPStatus.OK,
|
|
49
|
+
):
|
|
50
|
+
response = client.post(page, data=data, follow_redirects=True)
|
|
51
|
+
assert response.status_code == expected, f'{page}:{response.status_code}\n{response}'
|
|
52
|
+
return decode(response, expected=expected)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def delete(
|
|
56
|
+
client,
|
|
57
|
+
request: str,
|
|
58
|
+
expected=http.HTTPStatus.OK,
|
|
59
|
+
):
|
|
60
|
+
response = client.delete(request, follow_redirects=True)
|
|
61
|
+
assert response.status_code == expected, f'{request}:{response.status_code}\n{response}'
|
|
62
|
+
return decode(response, expected=expected)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def upload(client, page: str, file):
|
|
66
|
+
result = apiupload(client, page, 'file', file)
|
|
67
|
+
return result
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def apipost(
|
|
71
|
+
client,
|
|
72
|
+
page: str,
|
|
73
|
+
data: dict,
|
|
74
|
+
prefix='',
|
|
75
|
+
expected=http.HTTPStatus.OK,
|
|
76
|
+
):
|
|
77
|
+
prefix = prefix if prefix else default()
|
|
78
|
+
request = prefix + page
|
|
79
|
+
return post(client, page=request, data=data, expected=expected)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def apicall(
|
|
83
|
+
client,
|
|
84
|
+
request: str,
|
|
85
|
+
prefix='',
|
|
86
|
+
expected=http.HTTPStatus.OK,
|
|
87
|
+
):
|
|
88
|
+
prefix = prefix if prefix else default()
|
|
89
|
+
cmd = prefix + request
|
|
90
|
+
response = client.get(cmd, follow_redirects=True)
|
|
91
|
+
assert response.status_code == expected, f'{request}:{response.status_code}\n{response}'
|
|
92
|
+
return decode(response, expected=expected)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def apidelete(
|
|
96
|
+
client,
|
|
97
|
+
request: str,
|
|
98
|
+
prefix='',
|
|
99
|
+
expected=http.HTTPStatus.OK,
|
|
100
|
+
):
|
|
101
|
+
prefix = prefix if prefix else default()
|
|
102
|
+
cmd = prefix + request
|
|
103
|
+
return delete(client, cmd, expected=expected)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def apiupload(
|
|
107
|
+
client,
|
|
108
|
+
page: str,
|
|
109
|
+
field: str,
|
|
110
|
+
path: str,
|
|
111
|
+
prefix='',
|
|
112
|
+
expected=http.HTTPStatus.OK,
|
|
113
|
+
):
|
|
114
|
+
"""Upload file via http post command"""
|
|
115
|
+
prefix = prefix if prefix else default()
|
|
116
|
+
assert field, path
|
|
117
|
+
assert os.path.exists(path), path
|
|
118
|
+
request = prefix + page
|
|
119
|
+
try:
|
|
120
|
+
import werkzeug # pylint:disable=import-outside-toplevel
|
|
121
|
+
fields = werkzeug.datastructures.MultiDict([(field, open(path, 'rb'))]) # pylint:disable=R1732
|
|
122
|
+
except ImportError as error:
|
|
123
|
+
utilo.error('install werkzeug')
|
|
124
|
+
raise error
|
|
125
|
+
response = client.post(request, data=fields, follow_redirects=True)
|
|
126
|
+
assert response.status_code == expected, f'{page}:{response.status_code}\n{response}'
|
|
127
|
+
return decode(response, expected=expected)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def apiput(
|
|
131
|
+
client,
|
|
132
|
+
page: str,
|
|
133
|
+
data: dict,
|
|
134
|
+
prefix='',
|
|
135
|
+
expected=http.HTTPStatus.OK,
|
|
136
|
+
):
|
|
137
|
+
prefix = prefix if prefix else default()
|
|
138
|
+
request = prefix + page
|
|
139
|
+
response = client.put(request, data=data, follow_redirects=True)
|
|
140
|
+
assert response.status_code == expected, f'{page}:{response.status_code}\n{response}'
|
|
141
|
+
return decode(response, expected=expected)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def default():
|
|
145
|
+
return os.environ.get(API_PREFIX, '')
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def setup(prefix: str):
|
|
149
|
+
# ensure that prefix is str, linux requires str as os.environ-var.
|
|
150
|
+
prefix = str(prefix)
|
|
151
|
+
os.environ[API_PREFIX] = prefix
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
utilotest/cli/tracer.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import utilo
|
|
13
|
+
|
|
14
|
+
LOG_FILES = utilo.splitlines("""
|
|
15
|
+
done
|
|
16
|
+
failed
|
|
17
|
+
generated.log
|
|
18
|
+
inprogress
|
|
19
|
+
""")
|
|
20
|
+
OUTPUTDIR = '__traceback__'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@utilo.saveme
|
|
24
|
+
def main():
|
|
25
|
+
cwd = os.getcwd()
|
|
26
|
+
utilo.log(f'collect: {cwd}')
|
|
27
|
+
files = utilo.file_list(
|
|
28
|
+
path=cwd,
|
|
29
|
+
absolute=True,
|
|
30
|
+
)
|
|
31
|
+
files = [item for item in files if with_error(item)]
|
|
32
|
+
outdir = os.path.join(cwd, OUTPUTDIR)
|
|
33
|
+
utilo.log(f'write to: {outdir}')
|
|
34
|
+
os.makedirs(outdir, exist_ok=True)
|
|
35
|
+
for index, item in enumerate(files):
|
|
36
|
+
utilo.log(item)
|
|
37
|
+
index = str(index).zfill(2)
|
|
38
|
+
outpath = os.path.join(outdir, index)
|
|
39
|
+
utilo.file_copy(item, outpath, timestamp=True)
|
|
40
|
+
return utilo.SUCCESS
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
TRACEBACK = utilo.compiles(r"""
|
|
44
|
+
(
|
|
45
|
+
Traceback[ ]\(most[ ]recent[ ]call[ ]last\)\:|
|
|
46
|
+
error\:[ ]unrecognized[ ]arguments\:
|
|
47
|
+
)
|
|
48
|
+
""")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def with_error(path) -> bool:
|
|
52
|
+
# file name with extension
|
|
53
|
+
filename = utilo.file_name(path, ext=True).lower()
|
|
54
|
+
if OUTPUTDIR in path:
|
|
55
|
+
return False
|
|
56
|
+
if filename not in LOG_FILES:
|
|
57
|
+
return False
|
|
58
|
+
content = utilo.file_read(path)
|
|
59
|
+
if TRACEBACK.search(content):
|
|
60
|
+
# detect error inside log file
|
|
61
|
+
return True
|
|
62
|
+
return False
|
utilotest/config.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2022-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import utilo
|
|
13
|
+
|
|
14
|
+
GIT_REPLACE = utilo.parse_state(os.environ.get('BASELINE_REPLACE', None))
|
|
15
|
+
# TODO: REMOVE LATER
|
|
16
|
+
GIT_REPLACE |= utilo.parse_state(os.environ.get('DEV_GIT_REPLACE', None))
|
utilotest/file.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import contextlib
|
|
11
|
+
import glob
|
|
12
|
+
import os
|
|
13
|
+
|
|
14
|
+
import utilo
|
|
15
|
+
import utilo.file
|
|
16
|
+
import utilo.logger
|
|
17
|
+
import utilo.string
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def simplify_testfile_names(files, ext='pdf', sort: bool = True) -> tuple:
|
|
21
|
+
"""Make path relative, remove folder structure due replacing `/`
|
|
22
|
+
with `_` and remove selected file extention `ext`.
|
|
23
|
+
|
|
24
|
+
>>> simplify_testfile_names(('/c/abc/www/second.pdf', '/c/abc/def/first.pdf'))
|
|
25
|
+
('def_first', 'www_second')
|
|
26
|
+
|
|
27
|
+
Determine relative files against an resource folder:
|
|
28
|
+
|
|
29
|
+
>>> simplify_testfile_names(('/c/abc', '/c/abc/def/first.pdf'))
|
|
30
|
+
('def_first',)
|
|
31
|
+
"""
|
|
32
|
+
# ensure to compute prefix correctly
|
|
33
|
+
assert len(set(files)) > 1, 'require at least two unique items.'
|
|
34
|
+
assert isinstance(files, (list, tuple)), f'unsupported type: {type(files)}'
|
|
35
|
+
files = [utilo.forward_slash(item) for item in files]
|
|
36
|
+
prefix = utilo.forward_slash(os.path.commonpath(files))
|
|
37
|
+
# remove prefix
|
|
38
|
+
files = [item.replace(prefix, '') for item in files]
|
|
39
|
+
# remove empty path
|
|
40
|
+
files = [item for item in files if item]
|
|
41
|
+
# remove first slash
|
|
42
|
+
files = [item[1:] if item[0] == '/' else item for item in files]
|
|
43
|
+
# remove extension
|
|
44
|
+
files = [item.replace(f'.{ext}', '') for item in files]
|
|
45
|
+
# simplify name
|
|
46
|
+
files = [item.replace('/', '_') for item in files]
|
|
47
|
+
if sort:
|
|
48
|
+
files = utilo.files_sort(files)
|
|
49
|
+
return tuple(files)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@contextlib.contextmanager
|
|
53
|
+
def increased_filecount(
|
|
54
|
+
path: str = None,
|
|
55
|
+
ext: str = None,
|
|
56
|
+
mindiff: int = None,
|
|
57
|
+
maxdiff: int = None,
|
|
58
|
+
):
|
|
59
|
+
"""Ensure that some files were created while yielded operation.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
path(str): path to check for file creation, if path is None use cwd
|
|
63
|
+
ext(str): look for a special file extention
|
|
64
|
+
mindiff(int): minimal number of created files, if None: 1 is used
|
|
65
|
+
maxdiff(int): maximal number of created files, if None: utilo.INF is used
|
|
66
|
+
Raises:
|
|
67
|
+
AssertionError: if to few or less files are created
|
|
68
|
+
Yields:
|
|
69
|
+
None: to run file creation operation
|
|
70
|
+
"""
|
|
71
|
+
if path is None:
|
|
72
|
+
path = os.getcwd()
|
|
73
|
+
utilo.exists_assert(path)
|
|
74
|
+
assert mindiff is None or mindiff >= 0, str(mindiff)
|
|
75
|
+
assert maxdiff is None or maxdiff >= 0, str(maxdiff)
|
|
76
|
+
pattern = '**/*.*' if ext is None else f'**/*.{ext}'
|
|
77
|
+
path = utilo.forward_slash(str(path), newline=False)
|
|
78
|
+
pattern = f'{path}/{pattern}'
|
|
79
|
+
before = list(glob.glob(pattern, recursive=True))
|
|
80
|
+
yield
|
|
81
|
+
after = list(glob.glob(pattern, recursive=True))
|
|
82
|
+
mindiff = 1 if mindiff is None else mindiff
|
|
83
|
+
maxdiff = utilo.INF if maxdiff is None else maxdiff
|
|
84
|
+
current = len(after) - len(before)
|
|
85
|
+
assert mindiff <= current <= maxdiff, (
|
|
86
|
+
f'mindiff: {mindiff} <= {current} <= maxdiff: {maxdiff}\n'
|
|
87
|
+
f'{before}\n\n{after}')
|
utilotest/install.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import utilo
|
|
11
|
+
|
|
12
|
+
import utilotest
|
|
13
|
+
|
|
14
|
+
UNINSTALL = 'pip uninstall %s -y'
|
|
15
|
+
INSTALL = 'python setup.py install'
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def install_package(root):
|
|
19
|
+
utilo.exists_assert(root)
|
|
20
|
+
completed = utilo.run(INSTALL, cwd=root)
|
|
21
|
+
error = utilotest.stdout(completed) + utilotest.stderr(completed)
|
|
22
|
+
assert completed.returncode == utilo.SUCCESS, error
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def clean(package):
|
|
26
|
+
completed = utilo.run(UNINSTALL % package)
|
|
27
|
+
error = utilotest.stdout(completed) + utilotest.stderr(completed)
|
|
28
|
+
assert completed.returncode == utilo.SUCCESS, error
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def clean_install(root, package):
|
|
32
|
+
clean(package)
|
|
33
|
+
install_package(root)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def install_and_run(
|
|
37
|
+
root,
|
|
38
|
+
package,
|
|
39
|
+
executable=None,
|
|
40
|
+
cleanx: bool = True,
|
|
41
|
+
):
|
|
42
|
+
"""Install and run --help to ensure basic function"""
|
|
43
|
+
executable = executable if executable else package
|
|
44
|
+
install = f'python setup.py install && {executable} --help'
|
|
45
|
+
if cleanx:
|
|
46
|
+
clean(package)
|
|
47
|
+
completed = utilo.run(install, cwd=root)
|
|
48
|
+
error = utilotest.stdout(completed) + utilotest.stderr(completed)
|
|
49
|
+
assert completed.returncode == utilo.SUCCESS, error
|
utilotest/log.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import subprocess # nosec
|
|
11
|
+
import warnings
|
|
12
|
+
|
|
13
|
+
import utilo
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def write_capsys(capsys, path: str = None):
|
|
17
|
+
"""Save logged capsys to filespace."""
|
|
18
|
+
stdout_, stderr_ = stdout(capsys), stderr(capsys)
|
|
19
|
+
change = utilo.chdir if path else utilo.nothing
|
|
20
|
+
with change(path):
|
|
21
|
+
utilo.file_create('logging.txt', stdout_)
|
|
22
|
+
utilo.file_create('error.txt', stderr_)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def log_raw(content: str):
|
|
26
|
+
"""Print `content` which raises an AssertError. Fix encoding if
|
|
27
|
+
non-utf8 character are printed.
|
|
28
|
+
|
|
29
|
+
Hint: Avoid using print() to reduse finding 'print' when searching
|
|
30
|
+
in code base.
|
|
31
|
+
|
|
32
|
+
Example:
|
|
33
|
+
asssert len(abc) > 100, utilo.log_raw(abc)
|
|
34
|
+
"""
|
|
35
|
+
warnings.warn('use utilo.log_raw, will removed with utilotest 1.0.0')
|
|
36
|
+
utilo.log_raw(content)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def stderr(capsys) -> str:
|
|
40
|
+
if isinstance(capsys, subprocess.CompletedProcess):
|
|
41
|
+
return capsys.stderr
|
|
42
|
+
return capsys.readouterr().err
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def stdout(capsys) -> str:
|
|
46
|
+
if isinstance(capsys, subprocess.CompletedProcess):
|
|
47
|
+
return capsys.stdout
|
|
48
|
+
return capsys.readouterr().out
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def print_return(user_function):
|
|
52
|
+
|
|
53
|
+
def decorator(*args, **kwds):
|
|
54
|
+
result = user_function(*args, **kwds)
|
|
55
|
+
utilo.debug(result)
|
|
56
|
+
return result
|
|
57
|
+
|
|
58
|
+
return decorator
|
utilotest/runner.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import contextlib
|
|
11
|
+
import functools
|
|
12
|
+
import importlib
|
|
13
|
+
import inspect
|
|
14
|
+
import os
|
|
15
|
+
import subprocess # nosec
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
import utilo
|
|
20
|
+
|
|
21
|
+
import utilotest
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def run(
|
|
25
|
+
cmd: str,
|
|
26
|
+
cwd: str = None,
|
|
27
|
+
env: dict = None,
|
|
28
|
+
expect: bool = True,
|
|
29
|
+
verbose: bool = False,
|
|
30
|
+
) -> subprocess.CompletedProcess:
|
|
31
|
+
"""Run external process.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
cmd(str): command to run
|
|
35
|
+
cwd(str): current working directory
|
|
36
|
+
env(dict): modify environment variable for test run. If nothing is
|
|
37
|
+
passed, the global environment variable is used.
|
|
38
|
+
expect(bool): if True: fail on error
|
|
39
|
+
if False: fail on success
|
|
40
|
+
if None: return completed process
|
|
41
|
+
verbose(bool): log executed command and location
|
|
42
|
+
Returns:
|
|
43
|
+
Completed process.
|
|
44
|
+
"""
|
|
45
|
+
cwd = cwd if cwd else os.getcwd()
|
|
46
|
+
assert os.path.exists(cwd)
|
|
47
|
+
msg = f'cwd {cwd} is not a valid directory'
|
|
48
|
+
assert os.path.isdir(cwd), msg
|
|
49
|
+
env = os.environ if env is None else env
|
|
50
|
+
if verbose:
|
|
51
|
+
utilo.log(f'cd {cwd}')
|
|
52
|
+
utilo.log(cmd)
|
|
53
|
+
# run process
|
|
54
|
+
completed = subprocess.run( # nosec, pylint:disable=subprocess-run-check
|
|
55
|
+
cmd,
|
|
56
|
+
cwd=cwd,
|
|
57
|
+
env=env,
|
|
58
|
+
errors='replace',
|
|
59
|
+
shell=True,
|
|
60
|
+
stderr=subprocess.PIPE,
|
|
61
|
+
stdout=subprocess.PIPE,
|
|
62
|
+
universal_newlines=True,
|
|
63
|
+
)
|
|
64
|
+
if expect is True:
|
|
65
|
+
utilotest.assert_success(completed)
|
|
66
|
+
if expect is False: # pylint:disable=C2001
|
|
67
|
+
utilotest.assert_failure(completed)
|
|
68
|
+
return completed
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@utilo.rename(monkeypatch='mp', success='expect')
|
|
72
|
+
def run_cov(
|
|
73
|
+
cmd: str,
|
|
74
|
+
process: str,
|
|
75
|
+
main: callable,
|
|
76
|
+
expect: bool,
|
|
77
|
+
mp,
|
|
78
|
+
) -> int:
|
|
79
|
+
"""Run `main` with `cmd`.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
cmd(str): command to run
|
|
83
|
+
process(str): name of executed tool
|
|
84
|
+
main(callable): method to run
|
|
85
|
+
expect(bool): expectation that process succeeds or fails,
|
|
86
|
+
use None to skip check
|
|
87
|
+
mp(fixture): pytest patch/mp feature
|
|
88
|
+
Returns:
|
|
89
|
+
Return code of completed process.
|
|
90
|
+
"""
|
|
91
|
+
with contextlib.suppress(AttributeError):
|
|
92
|
+
cmd = cmd.split()
|
|
93
|
+
assert callable(main), str(main)
|
|
94
|
+
with mp.context() as context:
|
|
95
|
+
# process is removed as first argument
|
|
96
|
+
context.setattr(sys, 'argv', [process] + cmd)
|
|
97
|
+
with pytest.raises(SystemExit) as result:
|
|
98
|
+
main()
|
|
99
|
+
code = utilo.returncode(result)
|
|
100
|
+
assert (code == utilo.SUCCESS) == expect or expect is None, str(result)
|
|
101
|
+
return code
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@contextlib.contextmanager
|
|
105
|
+
def assert_run(command: str, cwd: str = None):
|
|
106
|
+
done = utilo.run(command, cwd)
|
|
107
|
+
assert done.returncode == utilo.SUCCESS, f'{done.stderr}\n{done.stdout}'
|
|
108
|
+
yield done
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@contextlib.contextmanager
|
|
112
|
+
def assert_run_fail(command: str, cwd: str = None):
|
|
113
|
+
done = utilo.run(command, cwd, expect=False)
|
|
114
|
+
assert done.returncode, f'{done.stderr}\n{done.stdout}'
|
|
115
|
+
yield done
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def single_execution() -> bool:
|
|
119
|
+
"""Check that test method is executed as single test.
|
|
120
|
+
|
|
121
|
+
You can use this method to open the result in a web browser if test is
|
|
122
|
+
executed with a human in front of the machine e.g. as a single test.
|
|
123
|
+
|
|
124
|
+
>>> single_execution()
|
|
125
|
+
False
|
|
126
|
+
"""
|
|
127
|
+
frame = inspect.currentframe()
|
|
128
|
+
caller = [item.function for item in inspect.getouterframes(frame)[0:9]]
|
|
129
|
+
return any(item in sys.argv for item in caller)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def assert_success(process: subprocess.CompletedProcess):
|
|
133
|
+
"""Ensure that `process` completed correctly.
|
|
134
|
+
|
|
135
|
+
If not a formatted information is logged
|
|
136
|
+
"""
|
|
137
|
+
assert process, str(process)
|
|
138
|
+
assert process.returncode == utilo.SUCCESS, utilo.format_completed(process)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def assert_failure(process: subprocess.CompletedProcess):
|
|
142
|
+
"""Ensure that `process` fails.
|
|
143
|
+
|
|
144
|
+
If process completed correctly, a formatted information is logged.
|
|
145
|
+
"""
|
|
146
|
+
assert process, str(process)
|
|
147
|
+
assert process.returncode != utilo.SUCCESS, utilo.format_completed(process)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def create_cli_runner(package) -> '[typing.Callable, typing.Callable]':
|
|
151
|
+
importlib.import_module(f'{package.__name__}.cli')
|
|
152
|
+
main: callable = package.cli.main
|
|
153
|
+
process: str = package.PROCESS
|
|
154
|
+
# success
|
|
155
|
+
success = functools.partial(
|
|
156
|
+
run_cov,
|
|
157
|
+
main=main,
|
|
158
|
+
process=process,
|
|
159
|
+
expect=True,
|
|
160
|
+
)
|
|
161
|
+
# failure
|
|
162
|
+
failure = functools.partial(
|
|
163
|
+
run_cov,
|
|
164
|
+
main=main,
|
|
165
|
+
process=process,
|
|
166
|
+
expect=False,
|
|
167
|
+
)
|
|
168
|
+
return success, failure
|
utilotest/select.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#==============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
#------------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2019-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
#==============================================================================
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
import resinf
|
|
15
|
+
import utilo
|
|
16
|
+
|
|
17
|
+
VIRTUAL_ENVKEY = 'VIRTUAL'
|
|
18
|
+
VIRTUAL = VIRTUAL_ENVKEY in os.environ
|
|
19
|
+
NONVIRTUAL = not VIRTUAL
|
|
20
|
+
|
|
21
|
+
FAST = 'FAST' in os.environ
|
|
22
|
+
NIGHTLY = 'NIGHTLY' in os.environ
|
|
23
|
+
LONGRUN = 'LONGRUN' in os.environ or NIGHTLY
|
|
24
|
+
MONDAY = 'MONDAY' in os.environ
|
|
25
|
+
FASTRUN = FAST and not NIGHTLY and not MONDAY
|
|
26
|
+
|
|
27
|
+
VIRTUAL_REASON = 'require venv'
|
|
28
|
+
NONVIRTUAL_REASON = 'require non-venv'
|
|
29
|
+
MONDAY_REASON = 'its not monday'
|
|
30
|
+
|
|
31
|
+
WIN = 'win' in sys.platform
|
|
32
|
+
LIN = not WIN
|
|
33
|
+
COV = 'coverage' in sys.modules
|
|
34
|
+
|
|
35
|
+
# pylint: disable=invalid-name
|
|
36
|
+
monday = pytest.mark.skipif(not MONDAY, reason=MONDAY_REASON)
|
|
37
|
+
nonvirtual = pytest.mark.skipif(NONVIRTUAL, reason=VIRTUAL_REASON)
|
|
38
|
+
virtual = pytest.mark.skipif(VIRTUAL, reason=NONVIRTUAL_REASON)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def hasprog(prog, msg=''):
|
|
42
|
+
if not msg:
|
|
43
|
+
msg = f'install {prog}'
|
|
44
|
+
has = pytest.mark.skipif(
|
|
45
|
+
not utilo.hasprog(prog),
|
|
46
|
+
reason=msg,
|
|
47
|
+
)
|
|
48
|
+
return has
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
hasgit = hasprog('git')
|
|
52
|
+
hasbaw = hasprog('baw')
|
|
53
|
+
|
|
54
|
+
linux = pytest.mark.skipif(not LIN, reason='linux only')
|
|
55
|
+
win = pytest.mark.skipif(not WIN, reason='windows only')
|
|
56
|
+
no_win = pytest.mark.skipif(WIN, reason='no windows')
|
|
57
|
+
no_linux = pytest.mark.skipif(LIN, reason='no linux')
|
|
58
|
+
no_cov = pytest.mark.skipif(COV, reason='skip on cov run')
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def register_marker(name: str):
|
|
62
|
+
"""After upgrading pytest, markers must be registered in pytest
|
|
63
|
+
config. To avoid putting holyvalue markers in every pytest.ini we
|
|
64
|
+
bypass them by directly acessing the pytest API. This may fail in
|
|
65
|
+
the future."""
|
|
66
|
+
pytest.mark._markers.add(name) # pylint:disable=W0212
|
|
67
|
+
return getattr(pytest.mark, name)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
longrun = register_marker('longrun')
|
|
71
|
+
nightly = register_marker('nightly')
|
|
72
|
+
|
|
73
|
+
# mark tests to optimize holy value parameters
|
|
74
|
+
# old: holyvalue = pytest.mark.holyvalue
|
|
75
|
+
holyvalue = register_marker('holyvalue')
|
|
76
|
+
displayed = register_marker('displayed')
|
|
77
|
+
# TODO: SUPPORT holyvalue('rawmaker.features.text.MAX_WIDTH')
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def requires(resource, folder=None):
|
|
81
|
+
exists = _exists(resource, folder)
|
|
82
|
+
if utilo.iterable(resource): # pylint:disable=W0160
|
|
83
|
+
resource = [utilo.forward_slash(item) for item in resource]
|
|
84
|
+
else:
|
|
85
|
+
resource = utilo.forward_slash(resource)
|
|
86
|
+
marker = pytest.mark.skipif(
|
|
87
|
+
not exists,
|
|
88
|
+
reason=f'require/generated: {resource}; folder: {folder}',
|
|
89
|
+
)
|
|
90
|
+
return marker
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def fixture_requires(resource, folder=None):
|
|
94
|
+
if _exists(resource, folder):
|
|
95
|
+
return
|
|
96
|
+
if utilo.iterable(resource): # pylint:disable=W0160
|
|
97
|
+
resource = [utilo.forward_slash(item) for item in resource]
|
|
98
|
+
else:
|
|
99
|
+
resource = utilo.forward_slash(resource)
|
|
100
|
+
pytest.skip(f'require/generated: {resource}; folder: {folder}')
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _exists(resource, folder=None):
|
|
104
|
+
if utilo.iterable(resource):
|
|
105
|
+
return all(_exists(item, folder=folder) for item in resource)
|
|
106
|
+
exists = os.path.exists(resinf.link(resource, folder=folder))
|
|
107
|
+
# non generated resources
|
|
108
|
+
import power # pylint:disable=import-outside-toplevel
|
|
109
|
+
exists |= os.path.exists(resource) and resource not in power.RESOURCES
|
|
110
|
+
return exists
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def step(source, pages: tuple = None, reason=None, marks=None, ids=None):
|
|
114
|
+
if ids is None:
|
|
115
|
+
ids = utilo.file_name(source)
|
|
116
|
+
if reason:
|
|
117
|
+
if marks:
|
|
118
|
+
# fail = pytest.mark.xfail(reason=reason)
|
|
119
|
+
assert 0, 'not implemented yet'
|
|
120
|
+
else:
|
|
121
|
+
marks = pytest.mark.xfail(reason=reason)
|
|
122
|
+
if marks: # pylint:disable=W0160
|
|
123
|
+
result = pytest.param(source, pages, marks=marks, id=ids)
|
|
124
|
+
else:
|
|
125
|
+
result = pytest.param(source, pages, id=ids)
|
|
126
|
+
return result
|
utilotest/shortcuts.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2022-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.fixture
|
|
14
|
+
def mp(monkeypatch):
|
|
15
|
+
return monkeypatch
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.fixture
|
|
19
|
+
def td(testdir):
|
|
20
|
+
return testdir
|
utilotest/utils.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import binascii
|
|
11
|
+
import contextlib
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import webbrowser
|
|
15
|
+
|
|
16
|
+
import pytest
|
|
17
|
+
import resinf
|
|
18
|
+
import utilo
|
|
19
|
+
|
|
20
|
+
import utilotest
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@contextlib.contextmanager
|
|
24
|
+
def open_webbrowser(path: str):
|
|
25
|
+
"""Open webbrowser on `give` path if test is used as single
|
|
26
|
+
execution.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
path(str): path to located html file
|
|
30
|
+
Yields:
|
|
31
|
+
None: to run operation to create website
|
|
32
|
+
"""
|
|
33
|
+
yield
|
|
34
|
+
assert os.path.exists(path), str(str)
|
|
35
|
+
if utilotest.single_execution():
|
|
36
|
+
webbrowser.open(path)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
SIMPLIFY = str.maketrans({item: '' for item in ' _-=+,.;\'/"()!@#$%^&&*'})
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def simple(item: str, maxlength: int = 25) -> str:
|
|
43
|
+
"""Simplify test name to ease selecting generated tests by test name.
|
|
44
|
+
|
|
45
|
+
>>> simple('No spaces _+; 133')
|
|
46
|
+
'Nospaces133'
|
|
47
|
+
"""
|
|
48
|
+
item = utilo.fix_encoding(item)
|
|
49
|
+
item = item.translate(SIMPLIFY)
|
|
50
|
+
item = item[-maxlength:]
|
|
51
|
+
return item
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def binhash(data: bytes) -> int:
|
|
55
|
+
"""\
|
|
56
|
+
>>> binhash(b'hello')
|
|
57
|
+
907060870
|
|
58
|
+
"""
|
|
59
|
+
result = binascii.crc32(data)
|
|
60
|
+
return result
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def assert_bin(data: bytes, expected: int):
|
|
64
|
+
"""\
|
|
65
|
+
>>> HELLO, TELLO = binhash(b'hello'), binhash(b'tello')
|
|
66
|
+
>>> assert_bin(b'hello', HELLO)
|
|
67
|
+
>>> assert_bin(b'tello', (HELLO, TELLO))
|
|
68
|
+
"""
|
|
69
|
+
current = binhash(data)
|
|
70
|
+
if isinstance(expected, int):
|
|
71
|
+
assert current == expected, f'{current}=={expected}'
|
|
72
|
+
else:
|
|
73
|
+
assert current in expected, f'{current}=={expected}'
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def testid() -> str:
|
|
77
|
+
"""\
|
|
78
|
+
>>> testid()
|
|
79
|
+
'utilotest.utils.testid'
|
|
80
|
+
"""
|
|
81
|
+
# TODO: DIRTY
|
|
82
|
+
test = os.environ['PYTEST_CURRENT_TEST']
|
|
83
|
+
try:
|
|
84
|
+
result = re.search(r'\[(.+)\]', test)[1]
|
|
85
|
+
except TypeError:
|
|
86
|
+
result = re.search(r'\:\:(.+)[ ]', test)[1]
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_resources(resources, marker: callable = None):
|
|
91
|
+
"""Remove `pages` from resource definition.
|
|
92
|
+
|
|
93
|
+
>>> import power;import resinf;import utilotest;resinf.setup(utilotest.ROOT);
|
|
94
|
+
>>> test_resources([power.BACHELOR090_PDF, (power.MASTER116_PDF, ':')])
|
|
95
|
+
[ParameterSet(values=(...bachelor090.pdf',),...missing:...master116.pdf'...id='master116')]
|
|
96
|
+
>>> test_resources(['first', 'second', 'first'])
|
|
97
|
+
Traceback (most recent call last):
|
|
98
|
+
...
|
|
99
|
+
ValueError: duplicate value: ['first']
|
|
100
|
+
"""
|
|
101
|
+
unique = [item if isinstance(item, str) else item[0] for item in resources]
|
|
102
|
+
utilo.assert_unique(unique)
|
|
103
|
+
result = []
|
|
104
|
+
for item in unique:
|
|
105
|
+
generated = resinf.link(item)
|
|
106
|
+
skip = not utilo.exists(generated)
|
|
107
|
+
marks = [pytest.mark.skipif(skip, reason=f'missing: {generated}')]
|
|
108
|
+
testname = utilo.file_name(item)
|
|
109
|
+
if marker:
|
|
110
|
+
if markme := marker(item):
|
|
111
|
+
marks.append(markme)
|
|
112
|
+
result.append(pytest.param(
|
|
113
|
+
item,
|
|
114
|
+
id=testname,
|
|
115
|
+
marks=marks,
|
|
116
|
+
))
|
|
117
|
+
return result
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def worker_count(
|
|
121
|
+
number: int,
|
|
122
|
+
onci: int,
|
|
123
|
+
worker_max: int = None,
|
|
124
|
+
) -> int:
|
|
125
|
+
"""Determine worker depending running on ci or not.
|
|
126
|
+
|
|
127
|
+
>>> str(worker_count(5, onci=10))
|
|
128
|
+
'...'
|
|
129
|
+
"""
|
|
130
|
+
if is_ci():
|
|
131
|
+
if worker_max is None:
|
|
132
|
+
worker_max = os.cpu_count()
|
|
133
|
+
return min([onci, worker_max])
|
|
134
|
+
return number
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def is_ci() -> bool:
|
|
138
|
+
"""\
|
|
139
|
+
>>> str(is_ci())
|
|
140
|
+
'...'
|
|
141
|
+
"""
|
|
142
|
+
if os.environ.get('JENKINS_HOME', False):
|
|
143
|
+
return True
|
|
144
|
+
return False
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: utilotest
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Author-email: Helmut Konrad Schewe <helmutus@outlook.com>
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/anaticulae/utilotest
|
|
7
|
+
Project-URL: Repository, https://github.com/anaticulae/utilotest
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: utilo<3.0.0,>=2.107.0
|
|
14
|
+
Requires-Dist: configos<2.0.0,>=1.0.2
|
|
15
|
+
Requires-Dist: resinf<2.0.0,>=1.0.2
|
|
16
|
+
Requires-Dist: pytest<10.0.0,>=9.0.2
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: selenium==4.41.0; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest_localserver==0.7.0; extra == "dev"
|
|
20
|
+
|
|
21
|
+
# utilotest
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
power/__init__.py,sha256=GxONh93BqErlkgcTeO3Mfk6lpKeb9bAiK7FoEDI6KQY,345
|
|
2
|
+
utilotest/__init__.py,sha256=qICv1LR_fQz3h3EVeqjI1hdiFFvnyi9KHGUDgenv4eI,3511
|
|
3
|
+
utilotest/baseline.py,sha256=KRP4yhLMrAaBUalSFilVpGaif-lDCN14xOQckErarEY,4452
|
|
4
|
+
utilotest/call.py,sha256=YzWl7lRLveUBvhpkBhTKCou5rmq2iiAohwEiQcXjyS4,4247
|
|
5
|
+
utilotest/config.py,sha256=YPXTYFuC_0B2e3M9hOet7Q09ub8-g02QDRw9dZB1mvo,747
|
|
6
|
+
utilotest/file.py,sha256=r1TL81hz-9o1UVv6-UozB6xSqeJqJkmP8pVUFzmYHOc,3312
|
|
7
|
+
utilotest/install.py,sha256=22n2sSBoklR35BNtcLkC_S6xE2O25KZGalC5GPbByBE,1642
|
|
8
|
+
utilotest/log.py,sha256=hoD5tKjzqb6tH80g2q35nHbH_N4JTR1KQDm8FhDaBOE,1809
|
|
9
|
+
utilotest/runner.py,sha256=W9XQMkooWEJF3ePkrIKGiKxu8OEjckX7f01e1a68As8,5015
|
|
10
|
+
utilotest/select.py,sha256=AFsYwvWbHU75cwWpmhfZvZTMMj_7KNg5SSrMoWX6MUg,4139
|
|
11
|
+
utilotest/shortcuts.py,sha256=ag-HSc6Ano3NDz2pxwUKPSbJBKp7b_cmru5-RZMwuFM,683
|
|
12
|
+
utilotest/utils.py,sha256=A-gMdFf2e2zOIrVBOsYRURiioy8oSvGww1v879KlODI,3884
|
|
13
|
+
utilotest/cli/__init__.py,sha256=ZnAmZoM8YS7O_aZREOZiaHHCsO1ctWvQVu__JGFNWCc,552
|
|
14
|
+
utilotest/cli/tracer.py,sha256=6eZEvzBXiTGAH2XiSTuGNdJbyrGypzPQrhRpQzgP9o8,1759
|
|
15
|
+
viewvisitor/__init__.py,sha256=OBkVw474qY1NKcVI6EnmXg5wzlJTejnRAf-VjaOlxfo,853
|
|
16
|
+
viewvisitor/fixture.py,sha256=fmFaHnWe4KUG5AOTqISZmmyPUZKxBgMnRspSxVcKdqA,1377
|
|
17
|
+
viewvisitor/fuchs/geckodriver.exe,sha256=KFO61gch1al7q9xYV-mkdRIKJCXJ46XPV2H9krs64vM,3500752
|
|
18
|
+
utilotest-1.0.1.dist-info/METADATA,sha256=K5WkgkDZ8LAtzqFQvffNcr9bULP0qEAVehjigk-vcU4,766
|
|
19
|
+
utilotest-1.0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
20
|
+
utilotest-1.0.1.dist-info/entry_points.txt,sha256=4UhxT8errJBG98dakGp0ts_CsU4SHo-YQGN7ZU_uztc,60
|
|
21
|
+
utilotest-1.0.1.dist-info/top_level.txt,sha256=eEwf6pW2QWyc3xrsI_6q9uh1IZoUzSahQ20q0-ZJs2Y,28
|
|
22
|
+
utilotest-1.0.1.dist-info/RECORD,,
|
viewvisitor/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import utilotest
|
|
13
|
+
from viewvisitor.fixture import selenium_driver # pylint:disable=W0611
|
|
14
|
+
|
|
15
|
+
sdriver = selenium_driver
|
|
16
|
+
|
|
17
|
+
ROOT = os.path.join(utilotest.ROOT, 'viewvisitor')
|
|
18
|
+
|
|
19
|
+
FIREFOX_DRIVER = os.path.join(ROOT, 'fuchs/geckodriver.exe')
|
|
20
|
+
FIREFOX_BINARY = os.getenv('FIREFOX_BINARY', default=None)
|
viewvisitor/fixture.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2021-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
import configos
|
|
13
|
+
import pytest
|
|
14
|
+
import selenium.webdriver
|
|
15
|
+
import utilo
|
|
16
|
+
|
|
17
|
+
import viewvisitor
|
|
18
|
+
|
|
19
|
+
linux = not sys.platform.startswith("win")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture(scope='session')
|
|
23
|
+
def selenium_driver():
|
|
24
|
+
if linux:
|
|
25
|
+
pytest.skip('install selenium on linux.')
|
|
26
|
+
if viewvisitor.FIREFOX_BINARY is None:
|
|
27
|
+
utilo.error('DEFINE `FIREFOX_BINARY`')
|
|
28
|
+
sys.exit(utilo.FAILURE)
|
|
29
|
+
add_firefox_path()
|
|
30
|
+
driver = selenium.webdriver.Firefox(
|
|
31
|
+
firefox_binary=viewvisitor.FIREFOX_BINARY,
|
|
32
|
+
executable_path=viewvisitor.FIREFOX_DRIVER,
|
|
33
|
+
)
|
|
34
|
+
yield driver
|
|
35
|
+
# Teardown
|
|
36
|
+
driver.quit()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def add_firefox_path():
|
|
40
|
+
for item in (viewvisitor.FIREFOX_BINARY, viewvisitor.FIREFOX_DRIVER):
|
|
41
|
+
utilo.exists_assert(item)
|
|
42
|
+
base = utilo.path_parent(item)
|
|
43
|
+
configos.env_path_append(base)
|
|
Binary file
|