def test_warning(self): test_journal = [] Logger.warn('baz', 'This baz is bad') test_journal.append( LogEntry(WARNING, 'bar', 'baz', 'This baz is bad')) self.assertListEqual(Logger.journal, test_journal)
def test_checkpoint(self): test_journal = [] Logger.warn('baz', 'This baz is bad') test_journal.append(LogEntry(WARNING, 'bar', 'baz', 'This baz is bad')) self.assertListEqual(Logger.journal, test_journal) self.assertListEqual(Logger.since_checkpoint(), test_journal) Logger.checkpoint() self.assertListEqual(Logger.since_checkpoint(), []) Logger.warn('baz', 'This baz is really bad') test_journal.append( LogEntry(WARNING, 'bar', 'baz', 'This baz is really bad')) partial_journal = [ LogEntry(WARNING, 'bar', 'baz', 'This baz is really bad') ] self.assertListEqual(Logger.journal, test_journal) self.assertListEqual(Logger.since_checkpoint(), partial_journal)
def test_cannot_ignore_error(self): test_journal = [] Logger.add_ignored_code('foo') with self.assertRaises(FooError): Logger.error('foo', 'This foo is bad I have to care') test_journal.append( LogEntry(ERROR, 'bar', 'foo', 'This foo is bad I have to care')) self.assertListEqual(Logger.journal, test_journal)
def test_error(self): test_journal = [] with self.assertRaises(FooError) as cm: Logger.error('foo', 'This foo is bad') self.assertEqual(cm.exception.message, 'This foo is bad') test_journal.append(LogEntry(ERROR, 'bar', 'foo', 'This foo is bad')) self.assertListEqual(Logger.journal, test_journal)
def test_fatal_warnings(self): Logger.fatal_warnings = True test_journal = [] with self.assertRaises(BazError) as cm: Logger.warn('baz', 'This baz is bad') self.assertEqual(cm.exception.message, 'This baz is bad') test_journal.append(LogEntry(ERROR, 'bar', 'baz', 'This baz is bad')) self.assertListEqual(Logger.journal, test_journal)