Browse Source

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.
Thomas Waldmann 9 years ago
parent
commit
4b7c02775e
2 changed files with 18 additions and 6 deletions
  1. 7 2
      borg/testsuite/archiver.py
  2. 11 4
      borg/testsuite/benchmark.py

+ 7 - 2
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:

+ 11 - 4
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