예제 #1
0
  def test_store(self):
    """Verify we store objects as JSON snapshots."""
    data = TestData('NAME', 1234, TestDetails())
    decoder = json.JSONDecoder()
    snapshot = JsonSnapshot()
    snapshot.add_object(data)

    time_function = lambda: 1.23
    journal = Journal(time_function)
    output = BytesIO()
    journal.open_with_file(output)
    offset = len(output.getvalue())

    journal.store(data)
    contents = output.getvalue()
    got_stream = RecordInputStream(BytesIO(contents[offset:]))
    got_json_str = next(got_stream)
    got = decoder.decode(got_json_str)
    json_object = snapshot.to_json_object()
    json_object['_timestamp'] = time_function()
    json_object['_thread'] = threading.current_thread().ident
    self.assertItemsEqual(json_object, got)
예제 #2
0
    def test_store(self):
        """Verify we store objects as JSON snapshots."""
        data = TestData('NAME', 1234, TestDetails())
        decoder = json.JSONDecoder(encoding='ASCII')
        snapshot = JsonSnapshot()
        snapshot.add_object(data)

        time_function = lambda: 1.23
        journal = Journal(time_function)
        output = StringIO()
        journal.open_with_file(output)
        offset = len(output.getvalue())

        journal.store(data)
        contents = output.getvalue()
        got_stream = RecordInputStream(StringIO(contents[offset:]))
        got_json_str = got_stream.next()
        got = decoder.decode(got_json_str)
        json_object = snapshot.to_json_object()
        json_object['_timestamp'] = time_function()
        json_object['_thread'] = threading.current_thread().ident
        self.assertItemsEqual(json_object, got)
예제 #3
0
from threading import current_thread
from io import BytesIO

from citest.base import (
    JournalLogger,
    JournalLogHandler,
    Journal)
from citest.base import RecordInputStream
from citest.base import set_global_journal

from tests.base.test_clock import TestClock

_journal_clock = TestClock()
_journal_file = BytesIO()
_journal = Journal(now_function=_journal_clock)
_journal.open_with_file(_journal_file)
set_global_journal(_journal)


class JournalLoggerTest(unittest.TestCase):
  @classmethod
  def setUpClass(cls):
    logging.getLogger().handlers = []

  def test_record(self):
      logger = logging.getLogger('testrecord')
      record = logger.makeRecord('NAME', 1, 'PATH', 2, 'MSG',
                                 'ARGS', 'EXC_INFO', 'FUNC')

  def test_journal_logger(self):
      offset = len(_journal_file.getvalue())