def should_apply_to_sudo(self, Local): runner = Local.return_value c = Context() with c.cd("foo"): c.sudo("whoami") cmd = "sudo -S -p '[sudo] password: ' cd foo && whoami" assert runner.run.called, "sudo() never called runner.run()!" assert runner.run.call_args[0][0] == cmd
def should_apply_to_run(self, Local): runner = Local.return_value c = Context() with c.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.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"