author David Douard <david.douard@logilab.fr>
Thu, 10 Jul 2014 10:27:16 +0200
changeset 1549 46be4dfc1070
parent 1501 a45f5a997ab2
child 1606 c7e928c1ed0e
permissions -rw-r--r--
[test] fix unit tests - fix the narval-cw-sources.ini (token_id+secret instead of user+password), - update MockConnection which should not pretend to be a pyro repository any more, but a http connection handler, - code cleanup.

"""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):
            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__':