コード例 #1
0
ファイル: context.py プロジェクト: crazy-penguins/raft
        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
コード例 #2
0
ファイル: context.py プロジェクト: crazy-penguins/raft
        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
コード例 #3
0
ファイル: context.py プロジェクト: crazy-penguins/raft
        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"
コード例 #4
0
ファイル: context.py プロジェクト: crazy-penguins/raft
        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
コード例 #5
0
ファイル: context.py プロジェクト: crazy-penguins/raft
 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")]
コード例 #6
0
ファイル: context.py プロジェクト: crazy-penguins/raft
 def defaults_to_Local(self, Local):
     c = Context()
     c.run("foo")
     assert Local.mock_calls == [call(c), call().run("foo")]