コード例 #1
0
ファイル: test_base.py プロジェクト: dmreiland/caravan
    def test_args_optional(self):
        with captured(out(), err()) as (stdout, stderr):
            with mock_args([]):
                TestCommand.main()
        self.assertIn('opt=None', stdout.getvalue())

        with captured(out(), err()) as (stdout, stderr):
            with mock_args(['--opt', 'OPT']):
                TestCommand.main()
        self.assertIn('opt=OPT', stdout.getvalue())
コード例 #2
0
ファイル: test_main.py プロジェクト: hongzhonglu/wc_sim
    def test_get_version(self):
        with abduct.captured(abduct.out(), abduct.err()) as (stdout, stderr):
            with __main__.App(argv=['-v']) as app:
                with self.assertRaises(SystemExit):
                    app.run()
            self.assertEqual(stdout.getvalue().strip(), wc_sim.__version__)
            self.assertEqual(stderr.getvalue(), '')

        with abduct.captured(abduct.out(), abduct.err()) as (stdout, stderr):
            with __main__.App(argv=['--version']) as app:
                with self.assertRaises(SystemExit):
                    app.run()
            self.assertEqual(stdout.getvalue().strip(), wc_sim.__version__)
            self.assertEqual(stderr.getvalue(), '')
コード例 #3
0
ファイル: test_base.py プロジェクト: dmreiland/caravan
    def test_args_logging_level(self):
        with captured(out(), err()) as (stdout, stderr):
            with mock_args([]):
                TestCommand.main()
        self.assertIn('logging_level=%s' % logging.WARNING, stdout.getvalue())

        with captured(out(), err()) as (stdout, stderr):
            with mock_args(['--verbose']):
                TestCommand.main()
        self.assertIn('logging_level=%s' % logging.INFO, stdout.getvalue())

        with captured(out(), err()) as (stdout, stderr):
            with mock_args(['--debug']):
                TestCommand.main()
        self.assertIn('logging_level=%s' % logging.DEBUG, stdout.getvalue())
コード例 #4
0
def test_captured_stderr(stdout, stderr):
    with captured(err()) as stderr_cap:
        write()

    eq_(stderr_cap.getvalue(), 'stderr')
    eq_(stdout.getvalue(), 'stdout')
    eq_(stderr.getvalue(), '')
コード例 #5
0
def test_captured_stderr(stdout, stderr):
    with captured(err()) as stderr_cap:
        write()

    eq_(stderr_cap.getvalue(), 'stderr')
    eq_(stdout.getvalue(), 'stdout')
    eq_(stderr.getvalue(), '')
コード例 #6
0
def test_capture_stdout_and_stderr(stdout, stderr):
    @captured(out(), err())
    def run():
        write()

    run()
    eq_(stdout.getvalue(), '')
    eq_(stderr.getvalue(), '')
コード例 #7
0
def test_capture_stdout_and_stderr(stdout, stderr):
    @captured(out(), err())
    def run():
        write()

    run()
    eq_(stdout.getvalue(), '')
    eq_(stderr.getvalue(), '')
コード例 #8
0
def test_captured_stdout_and_stderr(stdout, stderr):
    with captured(out(), err()) as (stdout_cap, stderr_cap):
        write()

    eq_(stdout_cap.getvalue(), 'stdout')
    eq_(stderr_cap.getvalue(), 'stderr')
    eq_(stdout.getvalue(), '')
    eq_(stderr.getvalue(), '')
コード例 #9
0
def test_captured_stdout_and_stderr(stdout, stderr):
    with captured(out(), err()) as (stdout_cap, stderr_cap):
        write()

    eq_(stdout_cap.getvalue(), 'stdout')
    eq_(stderr_cap.getvalue(), 'stderr')
    eq_(stdout.getvalue(), '')
    eq_(stderr.getvalue(), '')
コード例 #10
0
ファイル: test_base.py プロジェクト: dmreiland/caravan
    def test_args_missing(self):
        with captured(out(), err()) as (stdout, stderr):
            with mock_args([]):
                with self.assertRaises(SystemExit):
                    RequiredArgCommand.main()

        # Py2 and Py3 argparse have different messages
        self.assertIn('error: ', stderr.getvalue())
        self.assertIn('-r/--req', stderr.getvalue())
        self.assertIn('required', stderr.getvalue())
コード例 #11
0
ファイル: test_start.py プロジェクト: dmreiland/caravan
def run_command(additional_args):
    httpretty_register()

    args = ['-d', 'DOMAIN', '-n', 'NAME', '-v', 'VERSION', '-i', 'ID']
    args += additional_args
    with captured(out(), err()) as (stdout, stderr):
        with mock_args(args):
            Command.main()

    return stdout, stderr
コード例 #12
0
ファイル: test_list.py プロジェクト: dmreiland/caravan
def run_command(additional_args):
    httpretty_register()

    args = ["-d", "DOMAIN"]
    args += additional_args
    with captured(out(), err()) as (stdout, stderr):
        with mock_args(args):
            Command.main()

    return stdout, stderr
コード例 #13
0
ファイル: test_base.py プロジェクト: dmreiland/caravan
    def test_args_logging_config(self):
        with InTempDir():
            with open('logging.conf', 'w') as fd:
                fd.write(LOGGING_CONFIG_FILE_DATA)

            args = ['--logging-config', 'logging.conf']
            with captured(out(), err()) as (stdout, stderr):
                with mock_args(args):
                    TestCommand.main()

        self.assertIn('EndOfOutput', stdout.getvalue())
コード例 #14
0
ファイル: test_main.py プロジェクト: hongzhonglu/wc_sim
    def test_raw_cli(self):
        with mock.patch('sys.argv', ['wc-sim', '--help']):
            with self.assertRaises(SystemExit) as context:
                __main__.main()
                self.assertRegex(context.Exception, 'usage: wc-sim')

        with mock.patch('sys.argv', ['wc-sim']):
            with abduct.captured(abduct.out(),
                                 abduct.err()) as (stdout, stderr):
                __main__.main()
                self.assertRegex(stdout.getvalue().strip(), 'usage: wc-sim')
                self.assertEqual(stderr.getvalue(), '')
コード例 #15
0
    def test_nominal(self):
        args = ["--name", "DOMAIN", "--retention-days", "10"]

        headers = {"x-amzn-RequestId": "d68969c7-3f0d-11e1-9b11-7182192d0b57"}
        httpretty.register_uri(
            httpretty.POST,
            "https://swf.us-east-1.amazonaws.com/",
            content_type="application/json",
            adding_headers=headers,
            body="",
        )

        with captured(out(), err()) as (stdout, stderr):
            with mock_args(args):
                Command.main()

        request = httpretty.last_request()
        self.assertEqual(request.headers.get("x-amz-target"), "SimpleWorkflowService.RegisterDomain")
        expected = {"name": "DOMAIN", "workflowExecutionRetentionPeriodInDays": "10"}
        self.assertEqual(json.loads(request.parsed_body), expected)

        self.assertIn("Success.", stdout.getvalue())
コード例 #16
0
ファイル: e2e_tests.py プロジェクト: zlobolet/yturl
def test_quality_as_word_ok(quality_word, expected_itag):
    '''
    Test that qualities are correctly parsed into their equivalent itags.

    A unit test for this is not enough, as this involves configuration of the
    argument parser, and determination of output from the program. This is
    essentially our "everything is generally ok" end to end test.
    '''
    # expected_raw is a sequence of (itag, url) pairs. Since we're specifically
    # looking for the itag corresponding to to the quality word, we convert
    # these tuples to a dict and pull out the URL for the expected itag.
    expected_raw = _test_utils.read_fixture('files/success_output')
    expected_url = dict(json.loads(expected_raw))[expected_itag]

    fake_api_output = _test_utils.read_fixture('files/success_input', 'rb')
    _test_utils.mock_get_video_info_api_response(fake_api_output)

    with captured(out(), err()) as (stdout, stderr):
        yturl.main(['-q', quality_word, _test_utils.FAKE_URL], )

    eq(stderr.getvalue(), 'Using itag %d.\n' % expected_itag)
    eq(stdout.getvalue(), expected_url + '\n')
コード例 #17
0
    def assert_scenario(stdout, stderr, scenario):
        context_out = 'stdout' if scenario.real_output_in_context else ''
        context_err = 'stderr' if scenario.real_output_in_context else ''
        except_out = 'stdout' if scenario.real_output_in_except else ''
        except_err = 'stderr' if scenario.real_output_in_except else ''

        o = out(release_on_exception=scenario.release, tee=scenario.tee)
        e = err(release_on_exception=scenario.release, tee=scenario.tee)

        try:
            with captured(o, e) as (stdout_cap, stderr_cap):
                write()

                eq_(stdout_cap.getvalue(), 'stdout')
                eq_(stderr_cap.getvalue(), 'stderr')
                eq_(stdout.getvalue(), context_out)
                eq_(stderr.getvalue(), context_err)

                raise MyCustomException()

        except MyCustomException:
            eq_(stdout.getvalue(), except_out)
            eq_(stderr.getvalue(), except_err)
コード例 #18
0
    def assert_scenario(stdout, stderr, scenario):
        context_out = 'stdout' if scenario.real_output_in_context else ''
        context_err = 'stderr' if scenario.real_output_in_context else ''
        except_out = 'stdout' if scenario.real_output_in_except else ''
        except_err = 'stderr' if scenario.real_output_in_except else ''

        o = out(release_on_exception=scenario.release, tee=scenario.tee)
        e = err(release_on_exception=scenario.release, tee=scenario.tee)

        try:
            with captured(o, e) as (stdout_cap, stderr_cap):
                write()

                eq_(stdout_cap.getvalue(), 'stdout')
                eq_(stderr_cap.getvalue(), 'stderr')
                eq_(stdout.getvalue(), context_out)
                eq_(stderr.getvalue(), context_err)

                raise MyCustomException()

        except MyCustomException:
            eq_(stdout.getvalue(), except_out)
            eq_(stderr.getvalue(), except_err)
コード例 #19
0
ファイル: test_base.py プロジェクト: dmreiland/caravan
 def test_args_help(self):
     with captured(out(), err()) as (stdout, stderr):
         with mock_args(['--help']):
             with self.assertRaises(SystemExit):
                 TestCommand.main()
     self.assertIn(TestCommand.description, stdout.getvalue())
コード例 #20
0
ファイル: test_base.py プロジェクト: dmreiland/caravan
 def test_keyboard_interrupt(self):
     with captured(out(), err()) as (stdout, stderr):
         with mock_args([]):
             with self.assertRaises(SystemExit) as exc:
                 KeyboardInterruptCommand.main()
     self.assertEqual(str(exc.exception), '1')