def test_formatter_with_tuples(self):
     record = (5, 'pikos', 'apikos')
     output = '5 pikos apikos\n'
     recorder = TextStreamRecorder(self.temp, formatted=True)
     recorder.prepare(tuple)
     recorder.record(record)
     self.assertMultiLineEqual(self.temp.getvalue(), output)
 def test_formatter_with_namedtuples(self):
     record = DummyRecord(5, 'pikos', 'apikos')
     output = 'one   two   three\n-----------------\n5     pikos apikos\n'
     recorder = TextStreamRecorder(self.temp, formatted=True)
     recorder.prepare(DummyRecord)
     recorder.record(record)
     self.assertMultiLineEqual(self.temp.getvalue(), output)
 def test_record(self):
     record = DummyRecord(5, 'pikos', 'apikos')
     output = 'one two three\n-------------\n5 pikos apikos\n'
     recorder = TextStreamRecorder(self.temp)
     recorder.prepare(DummyRecord)
     recorder.record(record)
     self.assertMultiLineEqual(self.temp.getvalue(), output)
 def test_finalize(self):
     header = 'one two three\n-------------\n'
     recorder = TextStreamRecorder(self.temp)
     # all calls do nothing
     recorder.prepare(DummyRecord)
     for x in range(10):
         recorder.finalize()
     self.assertMultiLineEqual(self.temp.getvalue(), header)
 def test_formater(self):
     record = MockRecord(5, 'pikos','apikos')
     output = ('one   two   three{newline}-----------------{newline}'
               '5     pikos apikos{newline}'.format(newline=os.linesep))
     recorder = TextStreamRecorder(self.temp, formated=True)
     recorder.prepare(MockRecord)
     recorder.record(record)
     self.assertMultiLineEqual(self.temp.getvalue(), output)
    def test_exceptions(self):
        record = MockRecord(5, 'pikos','apikos')
        recorder = TextStreamRecorder(self.temp)

        with self.assertRaises(RecorderError):
            recorder.record(record)

        with self.assertRaises(RecorderError):
            recorder.finalize()
 def test_finalize(self):
     header = 'one two three{newline}-------------{newline}'.\
              format(newline=os.linesep)
     recorder = TextStreamRecorder(self.temp)
     # all calls do nothing
     recorder.prepare(MockRecord)
     for x in range(10):
         recorder.finalize()
     self.assertMultiLineEqual(self.temp.getvalue(), header)
 def test_filter(self):
     records = [MockRecord(5, 'pikos','apikos'),
              MockRecord(12, 'emilios','milo')]
     output = ('one two three{newline}-------------{newline}'
               '12 emilios milo{newline}'.format(newline=os.linesep))
     def not_pikos(values):
         return not 'pikos' in values
     recorder = TextStreamRecorder(self.temp, filter_=not_pikos)
     recorder.prepare(MockRecord)
     for record in records:
         recorder.record(record)
     self.assertMultiLineEqual(self.temp.getvalue(), output)
    def test_filter(self):
        records = [
            DummyRecord(5, 'pikos', 'apikos'),
            DummyRecord(12, 'emilios', 'milo')]
        output = 'one two three\n-------------\n12 emilios milo\n'

        def not_pikos(values):
            return not ('pikos' in values)

        recorder = TextStreamRecorder(self.temp, filter_=not_pikos)
        recorder.prepare(DummyRecord)
        for record in records:
            recorder.record(record)
        self.assertMultiLineEqual(self.temp.getvalue(), output)
Example #10
0
def baserecorder(filter_=None):
    """ Factory function that returns a basic recorder.
    """
    import sys
    from pikos.recorders.text_stream_recorder import TextStreamRecorder
    return TextStreamRecorder(sys.stdout,
                              filter_=filter_,
                              auto_flush=True,
                              formatted=True)
Example #11
0
    def test_prepare(self):
        header = 'one two three{newline}-------------{newline}'.\
                 format(newline=os.linesep)
        recorder = TextStreamRecorder(self.temp)
        recorder.prepare(MockRecord)

        # the first call writes the header
        self.assertMultiLineEqual(self.temp.getvalue(), header)
        recorder.prepare(MockRecord)
        # all calls after that do nothing
        for x in range(10):
            recorder.prepare(MockRecord)
        self.assertMultiLineEqual(self.temp.getvalue(), header)
Example #12
0
 def test_formater(self):
     record = MockRecord(5, 'pikos', 'apikos')
     output = ('one   two   three{newline}-----------------{newline}'
               '5     pikos apikos{newline}'.format(newline=os.linesep))
     recorder = TextStreamRecorder(self.temp, formatted=True)
     recorder.prepare(MockRecord)
     recorder.record(record)
     self.assertMultiLineEqual(self.temp.getvalue(), output)
    def test_prepare(self):
        header = 'one two three\n-------------\n'
        recorder = TextStreamRecorder(self.temp)
        recorder.prepare(DummyRecord)

        # the first call writes the header
        self.assertMultiLineEqual(self.temp.getvalue(), header)
        recorder.prepare(DummyRecord)
        # all calls after that do nothing
        for x in range(10):
            recorder.prepare(DummyRecord)
        self.assertMultiLineEqual(self.temp.getvalue(), header)
Example #14
0
    def test_exceptions(self):
        record = MockRecord(5, 'pikos', 'apikos')
        recorder = TextStreamRecorder(self.temp)

        with self.assertRaises(RecorderError):
            recorder.record(record)

        with self.assertRaises(RecorderError):
            recorder.finalize()
Example #15
0
 def test_finalize(self):
     header = 'one two three{newline}-------------{newline}'.\
              format(newline=os.linesep)
     recorder = TextStreamRecorder(self.temp)
     # all calls do nothing
     recorder.prepare(MockRecord)
     for x in range(10):
         recorder.finalize()
     self.assertMultiLineEqual(self.temp.getvalue(), header)
    def test_prepare(self):
        header = 'one two three{newline}-------------{newline}'.\
                 format(newline=os.linesep)
        recorder = TextStreamRecorder(self.temp)
        recorder.prepare(MockRecord)

        # the first call writes the header
        self.assertMultiLineEqual(self.temp.getvalue(), header)
        recorder.prepare(MockRecord)
        # all calls after that do nothing
        for x in range(10):
            recorder.prepare(MockRecord)
        self.assertMultiLineEqual(self.temp.getvalue(), header)
Example #17
0
    def test_filter(self):
        records = [
            MockRecord(5, 'pikos', 'apikos'),
            MockRecord(12, 'emilios', 'milo')
        ]
        output = ('one two three{newline}-------------{newline}'
                  '12 emilios milo{newline}'.format(newline=os.linesep))

        def not_pikos(values):
            return not 'pikos' in values

        recorder = TextStreamRecorder(self.temp, filter_=not_pikos)
        recorder.prepare(MockRecord)
        for record in records:
            recorder.record(record)
        self.assertMultiLineEqual(self.temp.getvalue(), output)