test/unittest_writer.py
author David Douard <david.douard@logilab.fr>
Sun, 09 Nov 2014 20:07:45 +0100
changeset 1773 35a2edaa84e5
parent 1765 3c579657557f
permissions -rw-r--r--
[migration] add a migration script for 4.0.0

#!/usr/bin/python
"""unit tests for the apycotlib.writer module"""

from logilab.common.testlib import TestCase, unittest_main
import cubes.apycot.testutils # required for sys.path black magic
from apycotlib.writer import BaseDataWriter

class BaseDataWriterTC(TestCase):

    def setUp(self):
        self.writer = BaseDataWriter(None, 1)

    def test__msg_info_01(self):
        path, line, msg = self.writer._msg_info('bonjour %s', 'vous')
        self.assertEqual(path, None)
        self.assertEqual(line, None)
        self.assertEqual(msg, 'bonjour vous')

    def test__msg_info_02(self):
        path, line, msg = self.writer._msg_info('bonjour %s', 'vous', path='/tmp', line=1)
        self.assertEqual(path, '/tmp')
        self.assertEqual(line, 1)
        self.assertEqual(msg, 'bonjour vous')

    def test__msg_info_03(self):
        try:
            I_dont_exist
        except:
            path, line, msg = self.writer._msg_info('oops %s', 'badaboum', tb=True)
        self.assertEqual(path, None)
        self.assertEqual(line, None)
        self.assertTrue(msg.startswith('oops badaboum'))
        self.assertTrue('Traceback' in msg)


if __name__ == '__main__':
    unittest_main()