예제 #1
0
파일: context.py 프로젝트: nhoening/invoke
        def _expect_responses(
            self,
            expected,
            Local,
            getpass,
            config=None,
            kwargs=None,
            getpass_reply=None,
        ):
            """
            Execute mocked sudo(), expecting watchers= kwarg in its run().

            * expected: list of 2-tuples of FailingResponder prompt/response
            * config: Config object, if an overridden one is needed
            * kwargs: sudo() kwargs, if needed
            * getpass_reply: return value of getpass.getpass, if needed

            (Local and getpass are just mock injections.)
            """
            if kwargs is None:
                kwargs = {}
            getpass.getpass.return_value = getpass_reply
            runner = Local.return_value
            context = Context(config=config) if config else Context()
            context.sudo('whoami', **kwargs)
            # Tease out the interesting bits - pattern/response - ignoring the
            # sentinel, etc for now.
            prompt_responses = [
                (watcher.pattern, watcher.response)
                for watcher in runner.run.call_args[1]['watchers']
            ]
            eq_(prompt_responses, expected)
예제 #2
0
파일: context.py 프로젝트: gtback/invoke
        def _expect_responses(self,
            expected, Local, getpass,
            config=None, kwargs=None, getpass_reply=None,
        ):
            """
            Execute mocked sudo(), expecting watchers= kwarg in its run().

            * expected: list of 2-tuples of FailingResponder prompt/response
            * config: Config object, if an overridden one is needed
            * kwargs: sudo() kwargs, if needed
            * getpass_reply: return value of getpass.getpass, if needed

            (Local and getpass are just mock injections.)
            """
            if kwargs is None:
                kwargs = {}
            getpass.getpass.return_value = getpass_reply
            runner = Local.return_value
            context = Context(config=config) if config else Context()
            context.sudo('whoami', **kwargs)
            # Tease out the interesting bits - pattern/response - ignoring the
            # sentinel, etc for now.
            prompt_responses = [
                (watcher.pattern, watcher.response)
                for watcher in runner.run.call_args[1]['watchers']
            ]
            eq_(prompt_responses, expected)
예제 #3
0
        def prefixes_should_apply_to_sudo(self, Local):
            runner = Local.return_value
            c = Context()
            with c.prefix("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
예제 #4
0
파일: context.py 프로젝트: yws/invoke
        def prefixes_should_apply_to_sudo(self, Local):
            runner = Local.return_value
            ctx = Context()
            with ctx.prefix('cd foo'):
                ctx.sudo('whoami')

            cmd = "sudo -S -p '[sudo] password: ' cd foo && whoami"
            ok_(runner.run.called, "sudo() never called runner.run()!")
            eq_(runner.run.call_args[0][0], cmd)
예제 #5
0
        def cd_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
예제 #6
0
파일: context.py 프로젝트: lmiphay/invoke
        def prefixes_should_apply_to_sudo(self, Local):
            runner = Local.return_value
            ctx = Context()
            with ctx.prefix('cd foo'):
                ctx.sudo('whoami')

            cmd = "sudo -S -p '[sudo] password: ' cd foo && whoami"
            ok_(runner.run.called, "sudo() never called runner.run()!")
            eq_(runner.run.call_args[0][0], cmd)
예제 #7
0
파일: context.py 프로젝트: offbyone/invoke
        def cd_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
예제 #8
0
 def kwarg_only_adds_to_kwarg(self, Local):
     runner = Local.return_value
     context = Context()
     watcher = self.watcher_klass()
     context.sudo("whoami", watchers=[watcher])
     # When sudo() called w/ user-specified watchers, we add ours to
     # that list
     watchers = runner.run.call_args[1]["watchers"]
     # Will raise ValueError if not in the list
     watchers.remove(watcher)
     # Only remaining item in list should be our sudo responder
     assert len(watchers) == 1
     assert isinstance(watchers[0], FailingResponder)
     assert watchers[0].pattern == self.escaped_prompt
예제 #9
0
        def _expect_responses(self, expected, config=None, kwargs=None):
            """
            Execute mocked sudo(), expecting watchers= kwarg in its run().

            * expected: list of 2-tuples of FailingResponder prompt/response
            * config: Config object, if an overridden one is needed
            * kwargs: sudo() kwargs, if needed
            """
            if kwargs is None:
                kwargs = {}
            Local = Mock()
            runner = Local.return_value
            context = Context(config=config) if config else Context()
            context.config.runners.local = Local
            context.sudo("whoami", **kwargs)
            # Tease out the interesting bits - pattern/response - ignoring the
            # sentinel, etc for now.
            prompt_responses = [
                (watcher.pattern, watcher.response)
                for watcher in runner.run.call_args[1]["watchers"]
            ]
            assert prompt_responses == expected