Example #1
0
    def setUp(self):

        self._subprocess_timeout = 15

        if platform.python_implementation() == 'PyPy':
            self._subprocess_timeout = 30

        self.stderr = NativeStringIO()
        self.stdout = NativeStringIO()

        self.patch(_logging, "_stderr", self.stderr)
        self.patch(_logging, "_stdout", self.stdout)
        self.patch(_logging, "_loggers", WeakKeyDictionary())
        self.patch(_logging, "_loglevel", "info")
        return super(CLITestBase, self).setUp()
Example #2
0
    def test_format_failure(self):
        """
        A traceback will print.
        """
        stream = NativeStringIO()
        observer = make_stderr_observer(_file=stream, format="syslogd")

        try:
            raise ValueError("noooo {0}".format("!!"))
        except:
            err = Failure()

        event = {
            'log_level': LogLevel.error,
            'log_namespace': 'crossbar.test.test_logger.StdoutObserverTests',
            'log_format': None,
            'log_source': None,
            'log_failure': err,
            'log_system': 'foo',
            'log_time': 1434099813.77449
        }

        observer(event)

        result = stream.getvalue()
        self.assertIn("noooo {0}", result)
Example #3
0
    def test_basic(self):

        stream = NativeStringIO()
        observer = make_stderr_observer(_file=stream)
        log = make_logger(observer=observer)

        log.error("Hi!", log_system="foo")

        result = stream.getvalue()
        self.assertIn("[foo]", result)
Example #4
0
    def setUp(self):
        super(CLIMixin, self).setUp()

        self.stdin = NativeStringIO()
        self.stdout = NativeStringIO()
        self.stderr = NativeStringIO()

        self.filesystem = filesystems.memory.FS()

        self.root_dir = Path("virtualenvs")
        self.filesystem.create_directory(self.root_dir)

        self.link_dir = Path("bin")
        self.filesystem.create_directory(self.link_dir)

        self.locator = Locator(
            root=self.root_dir,
            make_virtualenv=lambda **kwargs: VirtualEnv(
                create=self.fake_create, install=self.fake_install, **kwargs),
        )
 def test_invalid_args_returns_error_code(self, value):
     stderr_bytes = NativeStringIO()
     with patch("dxlclient._cli.argparse.ArgumentParser.print_help"), \
             patch("sys.argv", command_args(value)), \
             patch("sys.stderr", new=stderr_bytes), \
             self.assertRaises(SystemExit) as context:
         cli_run()
     stderr_bytes.seek(0)
     stderr_string = stderr_bytes.read()
     self.assertIn("invalid choice", stderr_string)
     self.assertNotEqual(0, context.exception.code)
Example #6
0
    def test_output_syslogd(self):
        """
        The syslogd output format is the system in square brackets, and the
        message.
        """
        stream = NativeStringIO()
        observer = make_stderr_observer(_file=stream, format="syslogd")
        event = {'log_level': LogLevel.error,
                 'log_namespace': 'crossbar.test.test_logger.StdoutObserverTests',
                 'log_source': None, 'log_format': 'Hi there!',
                 'log_system': 'foo', 'log_time': 1434099813.77449}

        observer(event)

        result = stream.getvalue()
        self.assertEqual(result[:-1], "[foo] Hi there!")
Example #7
0
    def test_format_log_category(self):
        """
        A log category in the event will mean the format is replaced with the
        format string referencing it.
        """
        stream = NativeStringIO()
        observer = make_stderr_observer(_file=stream, format="syslogd")

        event = {'log_level': LogLevel.error,
                 'log_namespace': 'crossbar.test.test_logger.StdoutObserverTests',
                 'log_category': "DBG100", 'x': 'x~', 'y': 'z', 'z': 'a',
                 'log_source': None,
                 'log_system': 'foo', 'log_time': 1434099813.77449}

        observer(event)

        result = stream.getvalue()
        self.assertEqual(result[:-1], "[foo] DEBUG x~ z a")
Example #8
0
def _safeFormat(formatter, o):
    """
    Helper function for L{safe_repr} and L{safe_str}.

    Called when C{repr} or C{str} fail. Returns a string containing info about
    C{o} and the latest exception.

    @param formatter: C{str} or C{repr}.
    @type formatter: C{type}
    @param o: Any object.

    @rtype: C{str}
    @return: A string containing information about C{o} and the raised
        exception.
    """
    io = NativeStringIO()
    traceback.print_exc(file=io)
    className = _determineClassName(o)
    tbValue = io.getvalue()
    return "<%s instance at 0x%x with %s error:\n %s>" % (
        className, id(o), formatter.__name__, tbValue)