sys.stderr.getvalue

Here are the examples of the python api sys.stderr.getvalue taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

67 Examples 7

Example 1

Project: utter-pool
Source File: frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 2

Project: log4mongo-python
Source File: test_handlers.py
View license
    def test_emit_fail(self):
        self.handler.collection = ''
        self.log.warn('test warning')
        self.force_flush()
        val = sys.stderr.getvalue()
        self.assertRegexpMatches(val, r"AttributeError: 'str' object has no attribute '{}'".format(write_many_method))

Example 3

Project: hue
Source File: frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 4

Project: stor
Source File: test_cli.py
View license
    @mock.patch.object(PosixPath, 'list', autospec=True)
    @mock.patch('sys.stderr', new=StringIO())
    def test_not_implemented_error_path(self, mock_list):
        mock_list.side_effect = NotImplementedError
        with self.assertRaisesRegexp(SystemExit, '1'):
            self.parse_args('stor list some_path')
        self.assertIn('not a valid command', sys.stderr.getvalue())

Example 5

Project: fabric
Source File: test_network.py
View license
    @mock_streams('stderr')
    @server(pubkeys=True)
    def test_passphrase_prompt_displays_host_string(self):
        """
        Passphrase prompt lines should include the user/host in question
        """
        env.password = None
        env.no_agent = env.no_keys = True
        env.key_filename = CLIENT_PRIVKEY
        output.everything = False
        with password_response(CLIENT_PRIVKEY_PASSPHRASE, silent=False):
            run("ls /simple")
        regex = r'^\[%s\] Login password for \'%s\': ' % (env.host_string, env.user)
        assert_contains(regex, sys.stderr.getvalue())

Example 6

Project: python-novaclient
Source File: test_shell.py
View license
    @mock.patch.object(sys, 'stderr', six.StringIO())
    @mock.patch.object(novaclient.shell.DeprecatedAction, '_get_action')
    def test_call_unemitted_nouse(self, mock_get_action):
        obj = novaclient.shell.DeprecatedAction(
            'option_strings', 'dest')

        obj('parser', 'namespace', 'values', 'option_string')

        self.assertEqual(obj.emitted, set(['option_string']))
        mock_get_action.assert_called_once_with('parser')
        mock_get_action.return_value.assert_called_once_with(
            'parser', 'namespace', 'values', 'option_string')
        self.assertEqual(sys.stderr.getvalue(),
                         'WARNING: Option "option_string" is deprecated\n')

Example 7

Project: stor
Source File: test_cli.py
View license
    @mock.patch.object(SwiftPath, 'isdir', return_value=False, autospec=True)
    @mock.patch('sys.stderr', new=StringIO())
    def test_cd_not_dir_swift(self, mock_isdir):
        with self.assertRaisesRegexp(SystemExit, '1'):
            self.parse_args('stor cd swift://test/container/file')
        self.assertIn('not a directory', sys.stderr.getvalue())

Example 8

Project: bomfu
Source File: frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 9

Project: eliot
Source File: test_filter.py
View license
    def test_noArguments(self):
        """
        If given no arguments, usage documentation is printed to stderr and C{1}
        is returned.
        """
        sys = FakeSys(["eliotfilter"], b"")
        result = main(sys)
        self.assertEqual(sys.stderr.getvalue(), USAGE)
        self.assertEqual(result, 1)

Example 10

Project: vcs
Source File: test_cli.py
View license
    def test_default_stderr(self):
        stream = StringIO()
        with mock.patch.object(sys, 'stderr', stream):
            command = BaseCommand()
            command.stderr.write(u'foobar')
            self.assertEqual(sys.stderr.getvalue(), u'foobar')

Example 11

Project: fabric
Source File: test_utils.py
View license
    @mock_streams('stderr')
    def test_warnings_print_magenta_if_colorize_on(self):
        with settings(colorize_errors=True):
            error("oh god", func=utils.warn, stderr="oops")
        # can't use assert_contains as ANSI codes contain regex specialchars
        eq_(magenta("\nWarning: oh god\n\n"), sys.stderr.getvalue())

Example 12

Project: fabric
Source File: test_operations.py
View license
    @server()
    @mock_streams('stderr')
    def _invalid_file_obj_situations(self, remote_path):
        with settings(hide('running'), warn_only=True):
            get(remote_path, StringIO())
        assert_contains('is a glob or directory', sys.stderr.getvalue())

Example 13

Project: rootpy
Source File: __init__.py
View license
    def finish(self):
        'Puts the ProgressBar bar in the finished state.'

        self.finished = True
        self.update(self.maxval)
        self.fd.write('\n')
        if self.signal_set:
            signal.signal(signal.SIGWINCH, signal.SIG_DFL)

        if self.redirect_stderr:
            self._stderr.write(sys.stderr.getvalue())
            sys.stderr = self._stderr

        if self.redirect_stdout:
            self._stdout.write(sys.stdout.getvalue())
            sys.stdout = self._stdout

Example 14

Project: stor
Source File: test_cli.py
View license
    @mock.patch('sys.stderr', new=StringIO())
    @mock.patch.object(S3Path, 'list', autospec=True)
    def test_list_not_found(self, mock_list):
        mock_list.side_effect = exceptions.NotFoundError('not found')
        with self.assertRaisesRegexp(SystemExit, '1'):
            self.parse_args('stor list s3://bucket/path')
        self.assertIn('s3://bucket/path', sys.stderr.getvalue())

Example 15

Project: python-novaclient
Source File: test_shell.py
View license
    @mock.patch.object(sys, 'stderr', six.StringIO())
    @mock.patch.object(novaclient.shell.DeprecatedAction, '_get_action')
    def test_call_emitted_withuse(self, mock_get_action):
        obj = novaclient.shell.DeprecatedAction(
            'option_strings', 'dest', use='use this instead')
        obj.emitted.add('option_string')

        obj('parser', 'namespace', 'values', 'option_string')

        self.assertEqual(obj.emitted, set(['option_string']))
        mock_get_action.assert_called_once_with('parser')
        mock_get_action.return_value.assert_called_once_with(
            'parser', 'namespace', 'values', 'option_string')
        self.assertEqual(sys.stderr.getvalue(), '')

Example 16

Project: gsync
Source File: test_output.py
View license
    def test_call(self):
        channel = Critical()

        try:
            raise Exception("CriticalException")
        except Exception, ex:
            channel(ex)

        import re
        pat = re.compile(
            r'^gsync: CriticalException\n' \
            r'gsync error: Exception at .*\(\d+\) \[client=[\d.]+\]\n$',
            re.M | re.S
        )

        self.assertIsNotNone(pat.search(sys.stderr.getvalue()))
        self.assertEqual("", sys.stdout.getvalue())

Example 17

Project: python-novaclient
Source File: test_shell.py
View license
    @mock.patch.object(sys, 'stderr', six.StringIO())
    def test_get_action_nolookup(self):
        action_class = mock.Mock()
        parser = mock.Mock(**{
            '_registry_get.return_value': action_class,
        })
        obj = novaclient.shell.DeprecatedAction(
            'option_strings', 'dest', real_action='nothing', const=1)
        obj.real_action = 'action'

        result = obj._get_action(parser)

        self.assertEqual(result, 'action')
        self.assertEqual(obj.real_action, 'action')
        self.assertFalse(parser._registry_get.called)
        self.assertFalse(action_class.called)
        self.assertEqual(sys.stderr.getvalue(), '')

Example 18

Project: coal-mine
Source File: test_cli.py
View license
    def test_no_command(self):
        with patch('sys.stderr', StringIO()):
            with self.assertRaises(SystemExit):
                cli.doit((), '/dev/null')
            self.assertRegexpMatches(sys.stderr.getvalue(),
                                     r'No command specified')

Example 19

Project: python-novaclient
Source File: test_shell.py
View license
    @mock.patch.object(sys, 'stderr', six.StringIO())
    def test_get_action_lookup_withresult(self):
        action_class = mock.Mock()
        parser = mock.Mock(**{
            '_registry_get.return_value': action_class,
        })
        obj = novaclient.shell.DeprecatedAction(
            'option_strings', 'dest', real_action='store', const=1)

        result = obj._get_action(parser)

        self.assertEqual(result, action_class.return_value)
        self.assertEqual(obj.real_action, action_class.return_value)
        parser._registry_get.assert_called_once_with(
            'action', 'store')
        action_class.assert_called_once_with(
            'option_strings', 'dest', help='Deprecated', const=1)
        self.assertEqual(sys.stderr.getvalue(), '')

Example 20

Project: luci-py
Source File: isolateserver_test.py
View license
  def checkOutput(self, expected_out, expected_err):
    try:
      self.assertEqual(expected_err, sys.stderr.getvalue())
      self.assertEqual(expected_out, sys.stdout.getvalue())
    finally:
      # Prevent double-fail.
      self.mock(sys, 'stdout', StringIO.StringIO())
      self.mock(sys, 'stderr', StringIO.StringIO())

Example 21

Project: imgdiff
Source File: tests.py
View license
    def test_wrong_number_of_arguments(self):
        self.main('foo.png')
        self.assertIn("error: expecting two arguments, got 1",
                      sys.stderr.getvalue())
        self.main('foo.png', 'bar.png', 'baz.png')
        self.assertIn("error: expecting two arguments, got 3",
                      sys.stderr.getvalue())

Example 22

Project: fabric
Source File: test_network.py
View license
    @mock_streams('stderr')
    @server()
    def test_password_prompt_displays_host_string(self):
        """
        Password prompt lines should include the user/host in question
        """
        env.password = None
        env.no_agent = env.no_keys = True
        output.everything = False
        with password_response(PASSWORDS[env.user], silent=False):
            run("ls /simple")
        regex = r'^\[%s\] Login password for \'%s\': ' % (env.host_string, env.user)
        assert_contains(regex, sys.stderr.getvalue())

Example 23

View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 24

Project: fabric
Source File: test_operations.py
View license
@mock_streams('stderr')
def test_require_mixed_state_keys_prints_missing_only():
    """
    When given mixed-state keys, require() prints missing keys only
    """
    try:
        require('foo', 'version')
    except SystemExit:
        err = sys.stderr.getvalue()
        assert 'version' not in err
        assert 'foo' in err

Example 25

Project: gae-boilerplate
Source File: frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 26

Project: fabric
Source File: test_utils.py
View license
@mock_streams('stderr')
@with_patched_object(output, 'aborts', True)
def test_abort_message():
    """
    abort() should print 'Fatal error' plus exception value
    """
    try:
        abort("Test")
    except SystemExit:
        pass
    result = sys.stderr.getvalue()
    eq_("\nFatal error: Test\n\nAborting.\n", result)

Example 27

Project: fabric
Source File: test_operations.py
View license
    @server()
    @mock_streams('stderr')
    def test_get_file_with_existing_file_target(self):
        """
        Clobbering existing local file should overwrite, with warning
        """
        local = self.path('target.txt')
        target = 'file.txt'
        with open(local, 'w') as fd:
            fd.write("foo")
        with hide('stdout', 'running'):
            get(target, local)
        assert "%s already exists" % local in sys.stderr.getvalue()
        eq_contents(local, FILES[target])

Example 28

Project: stor
Source File: test_cli.py
View license
    @mock.patch('stor.cli._clear_env', autospec=True)
    @mock.patch('sys.stderr', new=StringIO())
    def test_not_implemented_error_no_args(self, mock_clear):
        mock_clear.side_effect = NotImplementedError
        with self.assertRaisesRegexp(SystemExit, '1'):
            self.parse_args('stor clear')
        self.assertIn('not a valid command', sys.stderr.getvalue())

Example 29

Project: fabric
Source File: test_utils.py
View license
    @mock_streams('stderr')
    @raises(SystemExit)
    def test_errors_print_red_if_colorize_on(self):
        with settings(colorize_errors=True):
            error("oh god", func=utils.abort, stderr="oops")
        # can't use assert_contains as ANSI codes contain regex specialchars
        eq_(red("\Error: oh god\n\n"), sys.stderr.getvalue())

Example 30

Project: python-novaclient
Source File: test_shell.py
View license
    @mock.patch.object(novaclient.shell.OpenStackComputeShell, 'main')
    def test_main_error_handling(self, mock_compute_shell):
        class MyException(Exception):
            pass
        with mock.patch('sys.stderr', six.StringIO()):
            mock_compute_shell.side_effect = MyException('message')
            self.assertRaises(SystemExit, novaclient.shell.main)
            err = sys.stderr.getvalue()
        self.assertEqual(err, 'ERROR (MyException): message\n')

Example 31

Project: python-novaclient
Source File: test_shell.py
View license
    @mock.patch.object(sys, 'stderr', six.StringIO())
    @mock.patch.object(novaclient.shell.DeprecatedAction, '_get_action')
    def test_call_unemitted_withuse(self, mock_get_action):
        obj = novaclient.shell.DeprecatedAction(
            'option_strings', 'dest', use='use this instead')

        obj('parser', 'namespace', 'values', 'option_string')

        self.assertEqual(obj.emitted, set(['option_string']))
        mock_get_action.assert_called_once_with('parser')
        mock_get_action.return_value.assert_called_once_with(
            'parser', 'namespace', 'values', 'option_string')
        self.assertEqual(sys.stderr.getvalue(),
                         'WARNING: Option "option_string" is deprecated; '
                         'use this instead\n')

Example 32

Project: python-novaclient
Source File: test_shell.py
View license
    @mock.patch.object(sys, 'stderr', six.StringIO())
    @mock.patch.object(novaclient.shell.DeprecatedAction, '_get_action')
    def test_call_emitted_nouse(self, mock_get_action):
        obj = novaclient.shell.DeprecatedAction(
            'option_strings', 'dest')
        obj.emitted.add('option_string')

        obj('parser', 'namespace', 'values', 'option_string')

        self.assertEqual(obj.emitted, set(['option_string']))
        mock_get_action.assert_called_once_with('parser')
        mock_get_action.return_value.assert_called_once_with(
            'parser', 'namespace', 'values', 'option_string')
        self.assertEqual(sys.stderr.getvalue(), '')

Example 33

Project: babel
Source File: test_frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]

        # in case the log message is not duplicated we should get the same
        # output as before
        self.assertEqual(first_output, second_output)

Example 34

Project: coursebuilder
Source File: frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 35

Project: hortonworks-sandbox
Source File: frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 36

Project: stor
Source File: test_cli.py
View license
    @mock.patch.object(S3Path, 'isdir', return_value=False, autospec=True)
    @mock.patch('sys.stderr', new=StringIO())
    def test_cd_not_dir_s3(self, mock_isdir):
        with self.assertRaisesRegexp(SystemExit, '1'):
            self.parse_args('stor cd s3://test/file')
        self.assertIn('not a directory', sys.stderr.getvalue())

Example 37

Project: bomfu
Source File: frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 38

Project: python-novaclient
Source File: test_shell.py
View license
    @mock.patch.object(sys, 'stderr', six.StringIO())
    def test_get_action_lookup_noresult(self):
        parser = mock.Mock(**{
            '_registry_get.return_value': None,
        })
        obj = novaclient.shell.DeprecatedAction(
            'option_strings', 'dest', real_action='store', const=1)

        result = obj._get_action(parser)

        self.assertIsNone(result)
        self.assertIsNone(obj.real_action)
        parser._registry_get.assert_called_once_with(
            'action', 'store')
        self.assertEqual(sys.stderr.getvalue(),
                         'WARNING: Programming error: Unknown real action '
                         '"store"\n')

Example 39

Project: fjord
Source File: test_frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]

        # in case the log message is not duplicated we should get the same
        # output as before
        self.assertEqual(first_output, second_output)

Example 40

Project: fjord
Source File: test_frontend.py
View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]

        # in case the log message is not duplicated we should get the same
        # output as before
        self.assertEqual(first_output, second_output)

Example 41

Project: log4mongo-python
Source File: test_handlers.py
View license
    def test_emit_fail(self):
        self.handler.collection = ''
        self.log.warn('test warning')
        self.force_flush()
        val = sys.stderr.getvalue()
        self.assertRegexpMatches(val, r"AttributeError: 'str' object has no attribute '{}'".format(write_many_method))

Example 42

Project: coal-mine
Source File: test_cli.py
View license
    @responses.activate
    def test_create(self):
        with patch('sys.stderr', StringIO()):
            with self.assertRaises(SystemExit):
                cli.doit(('create', '--name', 'froodle'), '/dev/null')
            self.assertRegexpMatches(
                sys.stderr.getvalue(),
                r'error: the following arguments are required: --periodicity')

        add_response('create?paused=False&name=froodle&periodicity=60.0')
        cli.doit(('create', '--name', 'froodle', '--periodicity', '60'),
                 '/dev/null')

Example 43

Project: luci-py
Source File: isolateserver_test.py
View license
  def checkOutput(self, expected_out, expected_err):
    try:
      self.assertEqual(expected_err, sys.stderr.getvalue())
      self.assertEqual(expected_out, sys.stdout.getvalue())
    finally:
      # Prevent double-fail.
      self.mock(sys, 'stdout', StringIO.StringIO())
      self.mock(sys, 'stderr', StringIO.StringIO())

Example 44

View license
    def test_no_duplicated_output_for_multiple_runs(self):
        self._run_init_catalog()
        first_output = sys.stderr.getvalue()
        self._run_init_catalog()
        second_output = sys.stderr.getvalue()[len(first_output):]
        
        # in case the log message is not duplicated we should get the same 
        # output as before
        self.assertEqual(first_output, second_output)

Example 45

Project: invoke
Source File: runners.py
View license
        @trap
        def err_can_be_overridden(self):
            "err_stream can be overridden"
            err = StringIO()
            self._runner(err="sup").run(_, err_stream=err)
            eq_(err.getvalue(), "sup")
            eq_(sys.stderr.getvalue(), "")

Example 46

Project: stor
Source File: test_cli.py
View license
    @mock.patch('stor.copy', autospec=True)
    @mock.patch('sys.stderr', new=StringIO())
    def test_not_implemented_error(self, mock_copy):
        mock_copy.side_effect = NotImplementedError
        with self.assertRaisesRegexp(SystemExit, '1'):
            self.parse_args('stor cp some/path some/where')
        self.assertIn('not a valid command', sys.stderr.getvalue())

Example 47

Project: fabric
Source File: test_utils.py
View license
@mock_streams('stderr')
@with_patched_object(output, 'warnings', True)
def test_warn():
    """
    warn() should print 'Warning' plus given text
    """
    warn("Test")
    eq_("\nWarning: Test\n\n", sys.stderr.getvalue())

Example 48

Project: lettuce
Source File: asserts.py
View license
def assert_stderr(expected):
    string = sys.stderr.getvalue()
    assert_unicode_equals(string, expected)

Example 49

Project: lettuce
Source File: asserts.py
View license
def assert_stderr_lines(other):
    assert_lines(sys.stderr.getvalue(), other)

Example 50

Project: lettuce
Source File: asserts.py
View license
def assert_stderr_lines_with_traceback(other):
    assert_lines_with_traceback(sys.stderr.getvalue(), other)