test/unittest_writer.py
author David Douard <david.douard@logilab.fr>
Fri, 29 May 2015 11:27:00 +0200
changeset 1819 21c020c077a5
parent 1549 46be4dfc1070
child 1606 c7e928c1ed0e
permissions -rw-r--r--
merge upcoming 3.3 and 3.2.2

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

import os
from logilab.common.testlib import TestCase, unittest_main

import cubicweb.devtools
from cubes.apycot.testutils import MockConnection

from apycotlib.writer import BaseDataWriter


class BaseDataWriterTC(TestCase):

    def setUp(self):
        self.writer = BaseDataWriter(MockConnection('narval0'), 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()