[tor-commits] [sbws/master] Add fixtures for unit tests

pastly at torproject.org pastly at torproject.org
Wed Jul 11 15:05:40 UTC 2018


commit 89ed8ace6ef2d6e3d0dd68ee5d671fcdf96005fd
Author: juga0 <juga at riseup.net>
Date:   Mon Jun 25 16:09:41 2018 +0000

    Add fixtures for unit tests
---
 tests/unit/conftest.py | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
index c9002eb..002987c 100644
--- a/tests/unit/conftest.py
+++ b/tests/unit/conftest.py
@@ -2,7 +2,7 @@ from sbws.lib.resultdump import ResultError
 from sbws.lib.resultdump import ResultSuccess
 from sbws.lib.resultdump import Result
 from sbws.lib.resultdump import write_result_to_datadir
-from sbws.util.config import get_config
+from sbws.util.config import get_config, _get_default_config
 from sbws.util.parser import create_parser
 import sbws.core.init
 from tempfile import TemporaryDirectory
@@ -50,6 +50,39 @@ def datadir(request):
     return D(request.fspath.dirpath("data"))
 
 
+ at pytest.fixture
+def tmpdir(tmpdir_factory, request):
+    """Create a tmp dir for the tests"""
+    base = str(hash(request.node.nodeid))[:3]
+    bn = tmpdir_factory.mktemp(base)
+    return bn
+
+
+ at pytest.fixture
+def tmpdir_sbwshome(tmpdir):
+    """Create .sbws inside of the tests tmp dir"""
+    home = tmpdir.join('.sbws')
+    os.makedirs(home.strpath, exist_ok=True)
+    return home
+
+
+ at pytest.fixture()
+def unittest_args(tmpdir_sbwshome, parser):
+    """Args with sbws home in the tests tmp dir"""
+    return _PseudoArguments(directory=tmpdir_sbwshome.strpath,
+                            output=tmpdir_sbwshome.strpath,
+                            scale=False)
+
+
+ at pytest.fixture()
+def unittest_conf(tmpdir_sbwshome):
+    """Default configuration with sbws home in the tmp test dir"""
+    conf = _get_default_config()
+    conf['paths']['sbwshome'] = tmpdir_sbwshome.strpath
+    conf['paths']['started_filepath'] = ""
+    return conf
+
+
 @pytest.fixture(scope='session')
 def parser():
     return create_parser()





More information about the tor-commits mailing list