Exemple #1
0
    def load_hooks(self, filename=None):
        filename = filename or self.config.environment_file
        hooks_path = os.path.join(self.base_dir, filename)
        if os.path.exists(hooks_path):
            exec_file(hooks_path, self.hooks)

        if "before_all" not in self.hooks:
            self.hooks["before_all"] = self.before_all_default_hook
Exemple #2
0
    def load_hooks(self, filename=None):
        filename = filename or self.config.environment_file
        hooks_path = os.path.join(self.base_dir, filename)
        if os.path.exists(hooks_path):
            exec_file(hooks_path, self.hooks)

        if "before_all" not in self.hooks:
            self.hooks["before_all"] = self.before_all_default_hook
Exemple #3
0
 def test_exec_file(self):
     fn = tempfile.mktemp()
     with open(fn, "w") as f:
         f.write("spam = __file__\n")
     g = {}
     l = {}
     runner_util.exec_file(fn, g, l)
     assert "__file__" in l
     # pylint: disable=too-many-format-args
     assert "spam" in l, '"spam" variable not set in locals (%r)' % (g, l)
     # pylint: enable=too-many-format-args
     eq_(l["spam"], fn)
Exemple #4
0
 def test_exec_file(self):
     fn = tempfile.mktemp()
     with open(fn, "w") as f:
         f.write("spam = __file__\n")
     g = {}
     l = {}
     runner_util.exec_file(fn, g, l)
     assert "__file__" in l
     # pylint: disable=too-many-format-args
     assert "spam" in l, '"spam" variable not set in locals (%r)' % (g, l)
     # pylint: enable=too-many-format-args
     eq_(l["spam"], fn)
Exemple #5
0
def import_step_modules(paths, modules):
    """Import any python module under 'paths', store its names in 'modules/xx'
    
        This is used to implicitly register ServiceMeta classes defined in these
        step modules.
    """
    dglobals = globals().copy()
    for key in ('given', 'when', 'then', 'step'):
        dglobals[key] = dglobals[key.title()] = _dummy_decorator

    for p in paths:
        if os.path.isdir(p):
            for name in sorted(os.listdir(p)):
                if name.endswith(".py"):
                    globs = modules[p + '/' + name] = dglobals.copy()
                    exec_file(os.path.join(p, name), globs)
        elif os.path.isfile(p):
            assert p.endswith('.py')
            modules[p] = dglobals.copy()
            exec_file(p, modules[p])
Exemple #6
0
def get_step_definition(feature, input):
    parsed_input = " ".join(input.lstrip().split(" ")[1:]).lstrip()
    base_path = os.path.dirname(os.path.abspath(feature))
    steps_paths = [os.path.join(base_path, "steps")]

    runner_util.exec_file(os.path.join(base_path, "environment.py"))
    runner_util.load_step_modules(steps_paths)

    for step_type in registry.steps.keys():
        steps = list(registry.steps[step_type])
        if not steps:
            continue

        for step in registry.steps[step_type]:
            if step.match(parsed_input):
                file = step.location.abspath()
                line = step.location.line
                print(f"edit +{line} {file}")
                exit(0)
                return
    print("echo 'Not found'")
    exit(1)