def prefixes_should_apply_to_run(self, Local): runner = Local.return_value c = Context() with c.prefix("cd foo"): c.run("whoami") cmd = "cd foo && whoami" assert runner.run.called, "run() never called runner.run()!" assert runner.run.call_args[0][0] == cmd
def should_occur_before_prefixes(self, Local): runner = Local.return_value c = Context() with c.prefix("source venv"): with c.cd("foo"): c.run("whoami") cmd = "cd foo && source venv && whoami" assert runner.run.called, "run() never called runner.run()!" assert runner.run.call_args[0][0] == cmd
def should_use_finally_to_revert_changes_on_exceptions(self, Local): class Oops(Exception): pass runner = Local.return_value c = Context() try: with c.prefix("cd foo"): c.run("whoami") assert runner.run.call_args[0][0] == "cd foo && whoami" raise Oops except Oops: pass c.run("ls") # When bug present, this would be "cd foo && ls" assert runner.run.call_args[0][0] == "ls"
def nesting_should_retain_order(self, Local): runner = Local.return_value c = Context() with c.prefix("cd foo"): with c.prefix("cd bar"): c.run("whoami") cmd = "cd foo && cd bar && whoami" assert ( runner.run.called ), "run() never called runner.run()!" # noqa assert runner.run.call_args[0][0] == cmd c.run("whoami") cmd = "cd foo && whoami" assert runner.run.called, "run() never called runner.run()!" assert runner.run.call_args[0][0] == cmd # also test that prefixes do not persist c.run("whoami") cmd = "whoami" assert runner.run.called, "run() never called runner.run()!" assert runner.run.call_args[0][0] == cmd
def honors_runner_config_setting(self): runner_class = Mock() config = Config({"runners": {"local": runner_class}}) c = Context(config) c.run("foo") assert runner_class.mock_calls == [call(c), call().run("foo")]
def defaults_to_Local(self, Local): c = Context() c.run("foo") assert Local.mock_calls == [call(c), call().run("foo")]