예제 #1
0
파일: program.py 프로젝트: revolter/invoke
        def shows_UnexpectedExit_str_when_streams_hidden(self, mock_exit):
            p = Program()
            oops = UnexpectedExit(
                Result(
                    command="meh",
                    exited=54,
                    stdout="things!",
                    stderr="ohnoz!",
                    encoding="utf-8",
                    hide=("stdout", "stderr"),
                ))
            p.execute = Mock(side_effect=oops)
            p.run("myapp foo")
            # Expect repr() of exception prints to stderr
            # NOTE: this partially duplicates a test in runners.py; whatever.
            stderr = sys.stderr.getvalue()
            assert (stderr == """Encountered a bad command exit code!

Command: 'meh'

Exit code: 54

Stdout:

things!

Stderr:

ohnoz!

""")
            # And exit with expected code (vs e.g. 1 or 0)
            mock_exit.assert_called_with(54)
예제 #2
0
파일: program.py 프로젝트: revolter/invoke
        def UnexpectedExit_str_encodes_stdout_and_err(self, mock_exit):
            p = Program()
            oops = UnexpectedExit(
                Result(
                    command="meh",
                    exited=54,
                    stdout=u"this is not ascii: \u1234",
                    stderr=u"this is also not ascii: \u4321",
                    encoding="utf-8",
                    hide=("stdout", "stderr"),
                ))
            p.execute = Mock(side_effect=oops)
            p.run("myapp foo")
            # NOTE: using explicit binary ASCII here, & accessing raw
            # getvalue() of the faked sys.stderr (spec.trap auto-decodes it
            # normally) to have a not-quite-tautological test. otherwise we'd
            # just be comparing unicode to unicode. shrug?
            expected = b"""Encountered a bad command exit code!

Command: 'meh'

Exit code: 54

Stdout:

this is not ascii: \xe1\x88\xb4

Stderr:

this is also not ascii: \xe4\x8c\xa1

"""
            got = six.BytesIO.getvalue(sys.stderr)
            assert got == expected
예제 #3
0
파일: program.py 프로젝트: gtback/invoke
        def shows_UnexpectedExit_repr_when_streams_hidden(self, mock_exit):
            p = Program()
            oops = UnexpectedExit(Result(
                command='meh',
                exited=54,
                stdout='things!',
                stderr='ohnoz!',
                hide=('stdout', 'stderr'),
            ))
            p.execute = Mock(side_effect=oops)
            p.run("myapp foo")
            # Expect repr() of exception prints to stderr
            # NOTE: this partially duplicates a test in runners.py; whatever.
            eq_(sys.stderr.getvalue(), """Encountered a bad command exit code!

Command: 'meh'

Exit code: 54

Stdout:

things!

Stderr:

ohnoz!

""")
            # And exit with expected code (vs e.g. 1 or 0)
            mock_exit.assert_called_with(54)
예제 #4
0
파일: program.py 프로젝트: offbyone/invoke
        def UnexpectedExit_str_encodes_stdout_and_err(self, mock_exit):
            p = Program()
            oops = UnexpectedExit(Result(
                command='meh',
                exited=54,
                stdout=u'this is not ascii: \u1234',
                stderr=u'this is also not ascii: \u4321',
                encoding='utf-8',
                hide=('stdout', 'stderr'),
            ))
            p.execute = Mock(side_effect=oops)
            p.run("myapp foo")
            # NOTE: using explicit binary ASCII here, & accessing raw
            # getvalue() of the faked sys.stderr (spec.trap auto-decodes it
            # normally) to have a not-quite-tautological test. otherwise we'd
            # just be comparing unicode to unicode. shrug?
            expected = b"""Encountered a bad command exit code!

Command: 'meh'

Exit code: 54

Stdout:

this is not ascii: \xe1\x88\xb4

Stderr:

this is also not ascii: \xe4\x8c\xa1

"""
            got = six.BytesIO.getvalue(sys.stderr)
            assert got == expected
예제 #5
0
파일: program.py 프로젝트: thebjorn/invoke
 def expected_failure_types_dont_raise_exceptions(self, mock_exit):
     "expected failure types don't raise exceptions"
     for side_effect in (
         SimpleFailure,
         ParseError("boo!"),
     ):
         p = Program()
         p.execute = Mock(side_effect=side_effect)
         p.run("myapp -c foo mytask") # valid task name for parse step
         # Make sure we still exited fail-wise
         mock_exit.assert_called_with(1)
예제 #6
0
파일: program.py 프로젝트: revolter/invoke
 def UnexpectedExit_exits_with_code_when_no_hiding(self, mock_exit):
     p = Program()
     oops = UnexpectedExit(
         Result(command="meh", exited=17, hide=tuple()))
     p.execute = Mock(side_effect=oops)
     p.run("myapp foo")
     # Expect NO repr printed, because stdout/err were not hidden, so we
     # don't want to add extra annoying verbosity - we want to be more
     # Make-like here.
     assert sys.stderr.getvalue() == ""
     # But we still exit with expected code (vs e.g. 1 or 0)
     mock_exit.assert_called_with(17)
예제 #7
0
파일: program.py 프로젝트: miradam/invoke
 def UnexpectedExit_exits_with_code_when_no_hiding(self, mock_exit):
     p = Program()
     oops = UnexpectedExit(
         Result(command="meh", exited=17, hide=tuple())
     )
     p.execute = Mock(side_effect=oops)
     p.run("myapp foo")
     # Expect NO repr printed, because stdout/err were not hidden, so we
     # don't want to add extra annoying verbosity - we want to be more
     # Make-like here.
     assert sys.stderr.getvalue() == ""
     # But we still exit with expected code (vs e.g. 1 or 0)
     mock_exit.assert_called_with(17)
예제 #8
0
파일: program.py 프로젝트: revolter/invoke
 def turns_KeyboardInterrupt_into_exit_code_1(self, mock_exit):
     p = Program()
     p.execute = Mock(side_effect=KeyboardInterrupt)
     p.run("myapp -c foo mytask")
     mock_exit.assert_called_with(1)
예제 #9
0
파일: program.py 프로젝트: revolter/invoke
 def _test_flag(self, flag, key, value=True):
     p = Program()
     p.execute = Mock()  # neuter
     p.run("inv {} foo".format(flag))
     assert p.config.run[key] == value
예제 #10
0
파일: program.py 프로젝트: thebjorn/invoke
 def _test_flag(self, flag, key, value=True):
     p = Program()
     p.execute = Mock() # neuter
     p.run('inv {0} foo'.format(flag))
     eq_(p.config.run[key], value)
예제 #11
0
 def turns_KeyboardInterrupt_into_exit_code_130(self, mock_exit):
     p = Program()
     p.execute = Mock(side_effect=KeyboardInterrupt)
     p.run("myapp -c foo mytask")
     mock_exit.assert_called_with(130)
예제 #12
0
파일: program.py 프로젝트: miradam/invoke
 def _test_flag(self, flag, key, value=True):
     p = Program()
     p.execute = Mock()  # neuter
     p.run("inv {} foo".format(flag))
     assert p.config.run[key] == value