def test_context_can_expand_variable(): context = Context() context.variables["some"] = "value" expected = "just value" actual = context.expand_variable("just $some") assert actual == expected, "Expected %s Actual %s" % (expected, actual)
def run(self, script, target): start_secs = time.time() build_structure = self.parser.parse_script(script) if target.lower() not in build_structure.targets: raise TargetNotFoundError(target) actual_target = build_structure.targets[target.lower()] context = Context(RunResult(), build_structure) context.run_result.start_time = datetime.now() for variable, assignment in build_structure.variable_assignments.iteritems(): context.assign_variable(assignment.variable, assignment.value) self.executer.execute_target(build_structure=build_structure, target=actual_target, context=context) context.run_result.log = "\n".join([entry.render(self.verbosity) for entry in context.log_entries]) context.run_result.status = Successful context.run_result.end_time = datetime.now() context.run_result.ellapsed = time.time() - start_secs return context.run_result
def test_context_assigns_variable_expanded(): context = Context() context.assign_variable("some", "value") context.assign_variable("other", "some $some") assert context.variables["other"] == "some value"
def test_context_can_assign_a_new_variable(): context = Context() context.assign_variable("some", "value") assert "some" in context.variables assert context.variables["some"] == "value"
def test_context_returns_imediately_on_null_variable(): context = Context() assert not context.expand_variable("")
def test_context_does_not_replace_variable_if_two_variable_signs_found(): context = Context() context.variables["some"] = "value" assert context.expand_variable("$$some") == "$some"
def test_context_does_not_expand_unknown_variables(): context = Context() assert context.expand_variable("$some") == "$some"