def test_format(self, tmpdir): record = logging.makeLogRecord(dict( created=1547704837.4, msg='hello\nworld', )) f = IndentingFormatter(fmt="%(message)s") assert f.format(record) == 'hello\nworld'
def test_format(self, level_name, expected): """ Args: level_name: a logging level name (e.g. "WARNING"). """ record = self.make_record('hello\nworld', level_name=level_name) f = IndentingFormatter(fmt="%(message)s") assert f.format(record) == expected
def test_format_with_timestamp(self, tmpdir): record = logging.makeLogRecord(dict( created=1547704837.4, msg='hello\nworld', )) f = IndentingFormatter(fmt="%(message)s", add_timestamp=True) expected = '2019-01-17T06:00:37 hello\n2019-01-17T06:00:37 world' assert f.format(record) == expected
def test_format_deprecated(self, level_name, expected): """ Test that logged deprecation warnings coming from deprecated() don't get another prefix. """ record = self.make_record( 'DEPRECATION: hello\nworld', level_name=level_name, ) f = IndentingFormatter(fmt="%(message)s") assert f.format(record) == expected
def test_format_deprecated(self, level_name, expected, utc): """ Test that logged deprecation warnings coming from deprecated() don't get another prefix. """ record = self.make_record( 'DEPRECATION: hello\nworld', level_name=level_name, ) f = IndentingFormatter(fmt="%(message)s") assert f.format(record) == expected
def test_thread_safety_base(self, utc): record = self.make_record( 'DEPRECATION: hello\nworld', level_name='WARNING', ) f = IndentingFormatter(fmt="%(message)s") results = [] def thread_function(): results.append(f.format(record)) thread_function() thread = Thread(target=thread_function) thread.start() thread.join() assert results[0] == results[1]
def test_thread_safety_indent_log(self, utc: None) -> None: record = self.make_record( "DEPRECATION: hello\nworld", level_name="WARNING", ) f = IndentingFormatter(fmt="%(message)s") results = [] def thread_function() -> None: with indent_log(): results.append(f.format(record)) thread_function() thread = Thread(target=thread_function) thread.start() thread.join() assert results[0] == results[1]
def test_format_with_timestamp(self, level_name, expected): record = self.make_record('hello\nworld', level_name=level_name) f = IndentingFormatter(fmt="%(message)s", add_timestamp=True) assert f.format(record) == expected
def test_format_with_timestamp(self, level_name: str, expected: str, utc: None) -> None: record = self.make_record("hello\nworld", level_name=level_name) f = IndentingFormatter(fmt="%(message)s", add_timestamp=True) assert f.format(record) == expected