Exemplo n.º 1
0
def find_test_suite(test_file: str) -> TestSuite:
    """
    Assume one test suite per file
    """
    assert os.path.isfile(test_file)
    test_module = smuggle(test_file)
    return build_test_suite(test_module)
Exemplo n.º 2
0
    def create_experiment_app(self):
        script = smuggle(str(self.expdir / "script.py"))

        localserver.Script.expdir = self.expdir
        localserver.Script.config = self.config
        localserver.Script.secrets = self.secrets
        localserver.Script.exp = script.exp

        self.app = localserver.app
        secret_key = self.secrets.get("flask", "secret_key", fallback=None)
        if not secret_key:
            import secrets
            secret_key = secrets.token_urlsafe(16)
        self.app.secret_key = secret_key

        return self.app
Exemplo n.º 3
0
    def load_plugins_from_path(self, module_path):
        if not os.path.exists(module_path):
            LOG.error("plugin path '{}' doesn't exist.".format(module_path))
            return None

        dir_path = os.path.realpath(module_path)
        pattern = "*.py"

        self.obj_list = []

        for path, subdirs, files in os.walk(dir_path):
            for name in files:
                if fnmatch.fnmatch(name, pattern):
                    LOG.debug("MODULE? '{}' '{}'".format(name, path))
                    module = smuggle("{}/{}".format(path, name))
                    for mem_name, obj in inspect.getmembers(module):
                        if inspect.isclass(obj) and self.is_plugin(obj):
                            self.obj_list.append(
                                {"name": mem_name, "obj": obj(self.config)}
                            )

        return self.obj_list
Exemplo n.º 4
0
def get_exp_session(tmp_path,
                    script_path: str,
                    config_path: str = "",
                    secrets_path: str = "tests/res/secrets-default.conf",
                    sid: str = None,
                    **urlargs):
    """
    Returns an alfred3.experiment.ExperimentSession object based on the
    given script.py.
    """
    prepare_script(tmp_path, script_path)
    config = prepare_config(tmp_path, config_path)
    secrets = prepare_secrets(tmp_path, secrets_path)

    script = smuggle(tmp_path / "script.py")
    exp = script.exp
    sid = uuid4().hex if sid is None else sid

    session = exp.create_session(session_id=sid,
                                 config=config,
                                 secrets=secrets,
                                 **urlargs)
    return session
Exemplo n.º 5
0
from thesmuggler import smuggle

doll = smuggle('inner_russian_doll.py')

DRUGS = doll.DRUGS
Exemplo n.º 6
0
def test_smuggle_from_bare_path():
    contraband = smuggle('fixtures/fake_drugs.py')
    assert contraband.COCAINE == 'baking soda'
Exemplo n.º 7
0
def test_smuggle_from_relative_path():
    contraband = smuggle('./fixtures/fake_drugs.py')
    assert contraband.ECSTACY == 'candy hearts'
Exemplo n.º 8
0
def test_smuggle_specific():
    marijuana, whippets = smuggle('MARIJUANA', 'WHIPPETS',
                                  source='fixtures/fake_drugs.py')
    assert marijuana == 'oregano'
    assert whippets == 'bottled farts'
Exemplo n.º 9
0
def test_smuggle_nested():
    doll = smuggle('fixtures/outer_russian_doll.py')
    assert doll.DRUGS.MARIJUANA == 'oregano'
Exemplo n.º 10
0
def test_smuggle_from_parent_path():
    contraband = smuggle('../fixtures/contraband.py')
    assert contraband.CUBAN_CIGARS == 'cohiba'
Exemplo n.º 11
0
from thesmuggler import smuggle

DRUGS = smuggle('fake_drugs.py')