From 4b7c02775e38c6a9f8969dee1f4e35a02561c25a Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 16 Oct 2015 00:12:02 +0200 Subject: [PATCH] benchmarks: test with both the binary and the python code we use forking mode always and either execute python with the archiver module or the "borg.exe" binary. the cmd fixture alternates between 'python' and 'binary' mode and calls exec_cmd accordingly. --- borg/testsuite/archiver.py | 9 +++++++-- borg/testsuite/benchmark.py | 15 +++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py index 00a3a2bd9..81906bf27 100644 --- a/borg/testsuite/archiver.py +++ b/borg/testsuite/archiver.py @@ -71,10 +71,15 @@ class environment_variable: os.environ[k] = v -def exec_cmd(*args, archiver=None, fork=False, **kw): +def exec_cmd(*args, archiver=None, fork=False, exe=None, **kw): if fork: try: - borg = (sys.executable, '-m', 'borg.archiver') + if exe is None: + borg = (sys.executable, '-m', 'borg.archiver') + elif isinstance(exe, str): + borg = (exe, ) + elif not isinstance(exe, tuple): + raise ValueError('exe must be None, a tuple or a str') output = subprocess.check_output(borg + args) ret = 0 except subprocess.CalledProcessError as e: diff --git a/borg/testsuite/benchmark.py b/borg/testsuite/benchmark.py index 5b5c38634..d7bf95bb0 100644 --- a/borg/testsuite/benchmark.py +++ b/borg/testsuite/benchmark.py @@ -13,10 +13,17 @@ import pytest from .archiver import changedir, exec_cmd -# TODO: use fixture params to test python code and binary -@pytest.fixture -def cmd(): - return exec_cmd +@pytest.fixture(params=['python', 'binary']) +def cmd(request): + if request.param == 'python': + exe = None + elif request.param == 'binary': + exe = 'borg.exe' + else: + raise ValueError("param must be 'python' or 'binary'") + def exec_fn(*args, **kw): + return exec_cmd(*args, exe=exe, fork=True, **kw) + return exec_fn @pytest.yield_fixture