test/unittest_writer.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Nov 2011 18:04:25 +0100
branchstable
changeset 791 5ac76ce656dd
parent 783 caf114cc9c86
child 1202 8807cd7adc32
permissions -rw-r--r--
update to cw 3.14 api. Closes #2063529

"""unit tests for the apycotlib.writer module"""
import os
from logilab.common.testlib import TestCase, unittest_main

import utils

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:
            os.path.isdir(1)
        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()