aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-07-12 05:48:42 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-07-12 05:48:42 +0200
commit8d83b67c2feb539af7566d05e84b1cc154732996 (patch)
tree544dcc73821ee5dafd36cfc161ede74fcc17a291
parenttest: use namedtuple where appropriate (diff)
downloadcimple-8d83b67c2feb539af7566d05e84b1cc154732996.tar.gz
cimple-8d83b67c2feb539af7566d05e84b1cc154732996.zip
test: move some code to lib/
-rw-r--r--test/py/lib/tests.py21
-rw-r--r--test/py/test_repo.py35
2 files changed, 31 insertions, 25 deletions
diff --git a/test/py/lib/tests.py b/test/py/lib/tests.py
new file mode 100644
index 0000000..a676021
--- /dev/null
+++ b/test/py/lib/tests.py
@@ -0,0 +1,21 @@
+# Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "cimple" project.
+# For details, see https://github.com/egor-tensin/cimple.
+# Distributed under the MIT License.
+
+import pytest
+
+
+# Reference: https://github.com/pytest-dev/pytest/issues/3628
+# Automatic generation of readable test IDs.
+def my_parametrize(names, values, ids=None, **kwargs):
+ _names = names.split(',') if isinstance(names, str) else names
+ if not ids:
+ if len(_names) == 1:
+ ids = [f'{names}={v}' for v in values]
+ else:
+ ids = [
+ '-'.join(f'{k}={v}' for k, v in zip(_names, combination))
+ for combination in values
+ ]
+ return pytest.mark.parametrize(names, values, ids=ids, **kwargs)
diff --git a/test/py/test_repo.py b/test/py/test_repo.py
index aa89261..4fd6b09 100644
--- a/test/py/test_repo.py
+++ b/test/py/test_repo.py
@@ -11,6 +11,13 @@ import pytest
from lib.logging import child_logging_thread, configure_logging_in_child
from lib.process import LoggingEvent
+from lib.tests import my_parametrize
+
+
+def test_sigsegv(sigsegv):
+ ec, output = sigsegv.try_run()
+ assert ec == -11
+ assert output == 'Started the test program.\n'
class LoggingEventRunComplete(LoggingEvent):
@@ -29,7 +36,7 @@ class LoggingEventRunComplete(LoggingEvent):
super().set()
-def client_runner(log_queue, client, runs_per_process, repo):
+def client_runner_process(log_queue, client, runs_per_process, repo):
with configure_logging_in_child(log_queue):
logging.info('Executing %s clients', runs_per_process)
for i in range(runs_per_process):
@@ -46,12 +53,11 @@ def _test_repo_internal(env, repo, numof_processes, runs_per_process):
with child_logging_thread() as log_queue:
ctx = mp.get_context('spawn')
args = (log_queue, env.client, runs_per_process, repo)
- processes = [ctx.Process(target=client_runner, args=args) for i in range(numof_processes)]
+ processes = [ctx.Process(target=client_runner_process, args=args) for i in range(numof_processes)]
+
for proc in processes:
proc.start()
-
event.wait()
-
for proc in processes:
proc.join()
@@ -66,27 +72,6 @@ def _test_repo_internal(env, repo, numof_processes, runs_per_process):
assert repo.run_output_matches(output), f"Output doesn't match: {output}"
-# Reference: https://github.com/pytest-dev/pytest/issues/3628
-# Automatic generation of readable test IDs.
-def my_parametrize(names, values, ids=None, **kwargs):
- _names = names.split(',') if isinstance(names, str) else names
- if not ids:
- if len(_names) == 1:
- ids = [f'{names}={v}' for v in values]
- else:
- ids = [
- '-'.join(f'{k}={v}' for k, v in zip(_names, combination))
- for combination in values
- ]
- return pytest.mark.parametrize(names, values, ids=ids, **kwargs)
-
-
-def test_sigsegv(sigsegv):
- ec, output = sigsegv.try_run()
- assert ec == -11
- assert output == 'Started the test program.\n'
-
-
@my_parametrize('runs_per_client', [1, 5])
@my_parametrize('numof_clients', [1, 5])
def test_repo(env, test_repo, numof_clients, runs_per_client):