[Pydev-cvs] org.python.pydev/PySrc/ThirdParty/logilab/common/test unittest_configuration.py,NONE,1.1
Brought to you by:
fabioz
Update of /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/common/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7532/PySrc/ThirdParty/logilab/common/test Modified Files: unittest_astng_manager.py utils.py unittest_astng.py unittest_table.py unittest_ureports_html.py unittest_modutils.py unittest_db.py unittest_ureports_text.py unittest_tree.py unittest_patricia.py unittest_fileutils.py unittest_textutils.py unittest_astng_inspector.py Added Files: unittest_configuration.py unittest_bind.py unittest_testlib.py foomod.py Log Message: New pylint version Index: unittest_modutils.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/common/test/unittest_modutils.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** unittest_modutils.py 21 Jan 2005 17:46:21 -0000 1.1 --- unittest_modutils.py 16 Feb 2005 16:45:45 -0000 1.2 *************** *** 13,19 **** """ unit tests for module modutils (module manipulation utilities) - - Copyright (c) 2002-2004 LOGILAB S.A. (Paris, FRANCE). - http://www.logilab.fr/ -- mailto:co...@lo... """ --- 13,16 ---- *************** *** 29,40 **** from logilab.common import tree ! class load_module_from_name_function_test(unittest.TestCase): def test_knownValues_load_module_from_name_1(self): - """ load a python module from it's name """ self.assertEqual(modutils.load_module_from_name('sys'), sys) def test_knownValues_load_module_from_name_2(self): - """ load a python module from it's name """ self.assertEqual(modutils.load_module_from_name('os.path'), path) --- 26,36 ---- from logilab.common import tree ! class load_module_from_name_tc(unittest.TestCase): ! """ load a python module from it's name """ def test_knownValues_load_module_from_name_1(self): self.assertEqual(modutils.load_module_from_name('sys'), sys) def test_knownValues_load_module_from_name_2(self): self.assertEqual(modutils.load_module_from_name('os.path'), path) *************** *** 43,68 **** modutils.load_module_from_name, 'os.path', use_sys=0) ! class get_module_part_function_test(unittest.TestCase): def test_knownValues_get_module_part_1(self): - """ load a python module from it's name """ self.assertEqual(modutils.get_module_part('logilab.common.modutils'), 'logilab.common.modutils') def test_knownValues_get_module_part_2(self): - """ load a python module from it's name """ self.assertEqual(modutils.get_module_part('logilab.common.modutils.get_module_part'), 'logilab.common.modutils') def test_knownValues_get_module_part_3(self): - """ load a python module from it's name """ self.assertEqual(modutils.get_module_part('db.get_connexion', modutils.__file__), 'db') ! class modpath_from_file_function_test(unittest.TestCase): def test_knownValues_modpath_from_file_1(self): - """ given an absolute file path return the python module's path as a list """ self.assertEqual(modutils.modpath_from_file(modutils.__file__), ['logilab', 'common', 'modutils']) --- 39,71 ---- modutils.load_module_from_name, 'os.path', use_sys=0) ! ! class get_module_part_tc(unittest.TestCase): ! """given a dotted name return the module part of the name""" def test_knownValues_get_module_part_1(self): self.assertEqual(modutils.get_module_part('logilab.common.modutils'), 'logilab.common.modutils') def test_knownValues_get_module_part_2(self): self.assertEqual(modutils.get_module_part('logilab.common.modutils.get_module_part'), 'logilab.common.modutils') def test_knownValues_get_module_part_3(self): self.assertEqual(modutils.get_module_part('db.get_connexion', modutils.__file__), 'db') + + def test_knownValues_get_compiled_module_part(self): + self.assertEqual(modutils.get_module_part('math.log10'), 'math') + self.assertEqual(modutils.get_module_part('math.log10', __file__), 'math') + + def test_knownValues_get_builtin_module_part(self): + self.assertEqual(modutils.get_module_part('sys.path'), 'sys') + self.assertEqual(modutils.get_module_part('sys.path', '__file__'), 'sys') ! class modpath_from_file_tc(unittest.TestCase): ! """ given an absolute file path return the python module's path as a list """ def test_knownValues_modpath_from_file_1(self): self.assertEqual(modutils.modpath_from_file(modutils.__file__), ['logilab', 'common', 'modutils']) *************** *** 71,83 **** self.assertRaises(Exception, modutils.modpath_from_file, '/turlututu') ! class file_from_modpath_function_test(unittest.TestCase): def test_knownValues_file_from_modpath_1(self): - """ given an absolute file path return the python module's path as a list """ self.assertEqual(modutils.file_from_modpath(['logilab', 'common', 'modutils']), modutils.__file__.replace('.pyc', '.py')) def test_knownValues_file_from_modpath_2(self): - """ given an absolute file path return the python module's path as a list """ from os import path self.assertEqual(modutils.file_from_modpath(['os', 'path']).replace('.pyc', '.py'), --- 74,88 ---- self.assertRaises(Exception, modutils.modpath_from_file, '/turlututu') ! ! class file_from_modpath_tc(unittest.TestCase): ! """given a mod path (i.e. splited module / package name), return the ! corresponding file, giving priority to source file over precompiled file ! if it exists""" def test_knownValues_file_from_modpath_1(self): self.assertEqual(modutils.file_from_modpath(['logilab', 'common', 'modutils']), modutils.__file__.replace('.pyc', '.py')) def test_knownValues_file_from_modpath_2(self): from os import path self.assertEqual(modutils.file_from_modpath(['os', 'path']).replace('.pyc', '.py'), *************** *** 85,151 **** def test_knownValues_file_from_modpath_3(self): ! """ given an absolute file path return the python module's path as a list """ ! from xml.dom import ext ! self.assertEqual(modutils.file_from_modpath(['xml', 'dom', 'ext']).replace('.pyc', '.py'), ! ext.__file__.replace('.pyc', '.py')) def test_raise_file_from_modpath_Exception(self): self.assertRaises(ImportError, modutils.file_from_modpath, ['turlututu']) ! class is_standard_module_function_test(unittest.TestCase): def test_knownValues_is_standard_module_0(self): - """ - return true if the module may be considered as a module from the standard - library - """ self.assertEqual(modutils.is_standard_module('__builtin__'), True) def test_knownValues_is_standard_module_1(self): - """ - return true if the module may be considered as a module from the standard - library - """ self.assertEqual(modutils.is_standard_module('sys'), True) def test_knownValues_is_standard_module_2(self): - """ - return true if the module may be considered as a module from the standard - library - """ self.assertEqual(modutils.is_standard_module('logilab'), False) ! class is_relative_function_test(unittest.TestCase): def test_knownValues_is_relative_1(self): - """ - return true if the module may be considered as a module from the standard - library - """ self.assertEqual(modutils.is_relative('modutils', common.__path__[0]), True) def test_knownValues_is_relative_2(self): - """ - return true if the module may be considered as a module from the standard - library - """ self.assertEqual(modutils.is_relative('modutils', tree.__file__), True) def test_knownValues_is_relative_3(self): - """ - return true if the module may be considered as a module from the standard - library - """ self.assertEqual(modutils.is_relative('logilab.common.modutils', common.__path__[0]), False) ! class get_modules_function_test(unittest.TestCase): def test_knownValues_get_modules_1(self): # XXXFIXME: TOWRITE """given a directory return a list of all available python modules, even in subdirectories - """ import data --- 90,162 ---- def test_knownValues_file_from_modpath_3(self): ! try: ! # don't fail if pyxml isn't installed ! from xml.dom import ext ! except ImportError: ! pass ! else: ! self.assertEqual(modutils.file_from_modpath(['xml', 'dom', 'ext']).replace('.pyc', '.py'), ! ext.__file__.replace('.pyc', '.py')) ! ! def test_knownValues_file_from_modpath_4(self): ! self.assertEqual(modutils.file_from_modpath(['sys']), ! None) def test_raise_file_from_modpath_Exception(self): self.assertRaises(ImportError, modutils.file_from_modpath, ['turlututu']) + class get_source_file_tc(unittest.TestCase): ! def test(self): ! from os import path ! self.assertEqual(modutils.get_source_file(path.__file__), ! path.__file__.replace('.pyc', '.py')) ! ! def test_raise(self): ! self.assertRaises(modutils.NoSourceFile, modutils.get_source_file,'whatever') ! ! class is_standard_module_tc(unittest.TestCase): ! """ ! return true if the module may be considered as a module from the standard ! library ! """ def test_knownValues_is_standard_module_0(self): self.assertEqual(modutils.is_standard_module('__builtin__'), True) def test_knownValues_is_standard_module_1(self): self.assertEqual(modutils.is_standard_module('sys'), True) def test_knownValues_is_standard_module_2(self): self.assertEqual(modutils.is_standard_module('logilab'), False) + def test_knownValues_is_standard_module_3(self): + self.assertEqual(modutils.is_standard_module('unknown'), False) + + def test_knownValues_is_standard_module_4(self): + self.assertEqual(modutils.is_standard_module('StringIO'), True) + + def test_knownValues_is_standard_module_5(self): + self.assertEqual(modutils.is_standard_module('data.module', ('data',)), True) + self.assertEqual(modutils.is_standard_module('data.module', (path.abspath('data'),)), True) + ! class is_relative_tc(unittest.TestCase): def test_knownValues_is_relative_1(self): self.assertEqual(modutils.is_relative('modutils', common.__path__[0]), True) def test_knownValues_is_relative_2(self): self.assertEqual(modutils.is_relative('modutils', tree.__file__), True) def test_knownValues_is_relative_3(self): self.assertEqual(modutils.is_relative('logilab.common.modutils', common.__path__[0]), False) ! class get_modules_tc(unittest.TestCase): def test_knownValues_get_modules_1(self): # XXXFIXME: TOWRITE """given a directory return a list of all available python modules, even in subdirectories """ import data *************** *** 156,172 **** 'data.nonregr']) ! def suite(): ! """return the unitest suite""" ! loader = unittest.TestLoader() ! module = sys.modules[__name__] ! if __name__ == '__main__' and len(sys.argv) > 1: ! return loader.loadTestsFromNames(sys.argv[1:], module) ! return loader.loadTestsFromModule(module) ! ! def Run(): ! testsuite = suite() ! runner = unittest.TextTestRunner() ! return runner.run(testsuite) if __name__ == '__main__': ! Run() --- 167,190 ---- 'data.nonregr']) ! ! class get_modules_files_tc(unittest.TestCase): + def test_knownValues_get_module_files_1(self): # XXXFIXME: TOWRITE + """given a directory return a list of all available python module's files, even + in subdirectories + """ + import data + modules = modutils.get_module_files('data', data.__path__[0]) + modules.sort() + self.assertEqual(modules, + [path.join('data', x) for x in ['__init__.py', 'module.py', 'module2.py', 'noendingnewline.py', 'nonregr.py']]) + + from logilab.common.testlib import DocTest + class ModuleDocTest(DocTest): + """test doc test in this module""" + from logilab.common import modutils as module + del DocTest # necessary if we don't want it to be executed (we don't...) + + if __name__ == '__main__': ! unittest.main() Index: unittest_table.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/common/test/unittest_table.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** unittest_table.py 21 Jan 2005 17:46:21 -0000 1.1 --- unittest_table.py 16 Feb 2005 16:45:45 -0000 1.2 *************** *** 7,12 **** import unittest import sys ! from logilab.common.table import Table, TableStyleSheet ! class TableTC(unittest.TestCase): --- 7,13 ---- import unittest import sys ! from logilab.common.table import Table, TableStyleSheet, DocbookTableWriter, \ ! DocbookRenderer, TableStyle, TableWriter, TableCellRenderer ! from cStringIO import StringIO class TableTC(unittest.TestCase): *************** *** 20,24 **** --- 21,44 ---- self.table.create_rows(['row1', 'row2', 'row3']) self.table.create_columns(['col1', 'col2']) + + + def test_indexation(self): + """we should be able to use [] to access rows""" + row0 = self.table.data[0] + row1 = self.table.data[1] + self.assert_(self.table[0] is row0) + self.assert_(self.table[1] is row1) + + def test_get_rows(self): + """tests Table.get_rows()""" + self.assertEquals(self.table.get_rows(), [[0, 0], [0, 0], [0, 0]]) + self.table.insert_column(1, range(3), 'supp') + self.assertEquals(self.table.get_rows(), [[0, 0, 0], [0, 1, 0], [0, 2, 0]]) + def test_dimensions(self): + """tests table dimensions""" + self.assertEquals(self.table.get_dimensions(), (3, 2)) + self.table.insert_column(1, range(3), 'supp') + self.assertEquals(self.table.get_dimensions(), (3, 3)) def test_set_column(self): *************** *** 30,34 **** self.assertEquals(self.table.get_element(2,0), 2) - def test_set_column_by_id(self): """Tests that table.set_column_by_id() works fine. --- 50,53 ---- *************** *** 38,43 **** --- 57,84 ---- self.assertEquals(self.table.get_element(1,0), 1) self.assertEquals(self.table.get_element(2,0), 2) + self.assertRaises(KeyError, self.table.set_column_by_id, 'col123', range(3)) + def test_cells_ids(self): + """tests that we can access cells by giving row/col ids""" + self.assertRaises(KeyError, self.table.set_cell_by_ids, 'row12', 'col1', 12) + self.assertRaises(KeyError, self.table.set_cell_by_ids, 'row1', 'col12', 12) + self.assertEquals(self.table.get_element(0,0), 0) + self.table.set_cell_by_ids('row1', 'col1', 'DATA') + self.assertEquals(self.table.get_element(0,0), 'DATA') + self.assertRaises(KeyError, self.table.set_row_by_id, 'row12', []) + self.table.set_row_by_id('row1', ['1.0', '1.1']) + self.assertEquals(self.table.get_element(0,0), '1.0') + def test_insert_row(self): + """tests a row insertion""" + tmp_data = ['tmp1', 'tmp2'] + self.table.insert_row(1, tmp_data, 'tmprow') + self.assertEquals(self.table.get_row(1), tmp_data) + self.assertEquals(self.table.get_row_by_id('tmprow'), tmp_data) + self.table.delete_row_by_id('tmprow') + self.assertRaises(KeyError, self.table.delete_row_by_id, 'tmprow') + self.assertEquals(self.table.get_row(1), [0, 0]) + self.assertRaises(ValueError, self.table.get_row_by_id, 'tmprow') + def test_get_column(self): """Tests that table.get_column() works fine. *************** *** 45,51 **** self.table.set_cell(0, 1, 12) self.table.set_cell(2, 1, 13) ! column = self.table.get_column(1) ! self.assertEquals(column, [12,0,13]) ! def test_get_columns(self): --- 86,91 ---- self.table.set_cell(0, 1, 12) self.table.set_cell(2, 1, 13) ! self.assertEquals(self.table.get_column(1), [12,0,13]) ! self.assertEquals(self.table.get_column_by_id('col2'), [12,0,13]) def test_get_columns(self): *************** *** 54,60 **** self.table.set_cell(0, 1, 12) self.table.set_cell(2, 1, 13) ! columns = self.table.get_columns() ! self.assertEquals(columns, [[0,0,0], [12,0,13]]) ! def test_insert_column(self): --- 94,98 ---- self.table.set_cell(0, 1, 12) self.table.set_cell(2, 1, 13) ! self.assertEquals(self.table.get_columns(), [[0,0,0], [12,0,13]]) def test_insert_column(self): *************** *** 66,77 **** ['col1', 'inserted_column', 'col2']) - def test_delete_column(self): """Tests that table.delete_column() works fine. """ self.table.delete_column(1) ! self.assertEquals(self.table.col_names,['col1']) self.assertEquals(self.table.get_column(0), [0,0,0]) ! def test_transpose(self): --- 104,116 ---- ['col1', 'inserted_column', 'col2']) def test_delete_column(self): """Tests that table.delete_column() works fine. """ self.table.delete_column(1) ! self.assertEquals(self.table.col_names, ['col1']) self.assertEquals(self.table.get_column(0), [0,0,0]) ! self.assertRaises(KeyError, self.table.delete_column_by_id, 'col2') ! self.table.delete_column_by_id('col1') ! self.assertEquals(self.table.col_names, []) def test_transpose(self): *************** *** 84,89 **** self.assertEquals(ttable.data, [[0,0,0], [0,0,0], [5,6,7]]) - - def test_sort_table(self): """Tests the table sort by column --- 123,126 ---- *************** *** 98,106 **** self.assertEquals(self.table.data, [[2, 3], [1, 2], [3, 1]]) class TableStyleSheetTC(unittest.TestCase): """The Stylesheet test case """ - def setUp(self): """Builds a simple table to test the stylesheet --- 135,159 ---- self.assertEquals(self.table.data, [[2, 3], [1, 2], [3, 1]]) + def test_sort_by_id(self): + """tests sort_by_column_id()""" + self.table.set_column_by_id('col1', [3, 1, 2]) + self.table.set_column_by_id('col2', [1, 2, 3]) + self.table.sort_by_column_id('col1') + self.assertRaises(KeyError, self.table.sort_by_column_id, 'col123') + self.assertEquals(self.table.row_names, ['row2', 'row3', 'row1']) + self.assertEquals(self.table.data, [[1, 2], [2, 3], [3, 1]]) + self.table.sort_by_column_id('col2', 'desc') + self.assertEquals(self.table.row_names, ['row3', 'row2', 'row1']) + self.assertEquals(self.table.data, [[2, 3], [1, 2], [3, 1]]) + + def test_pprint(self): + """only tests pprint doesn't raise an exception""" + self.table.pprint() + str(self.table) + class TableStyleSheetTC(unittest.TestCase): """The Stylesheet test case """ def setUp(self): """Builds a simple table to test the stylesheet *************** *** 110,113 **** --- 163,172 ---- self.table.create_columns(['a','b','c']) self.stylesheet = TableStyleSheet() + # We don't want anything to be printed + self.stdout_backup = sys.stdout + sys.stdout = StringIO() + + def tearDown(self): + sys.stdout = self.stdout_backup def test_add_rule(self): *************** *** 120,125 **** self.assertEquals(self.table.get_row(0), [3,4,5]) ! def test_rowavg_rule(self): """Tests that add_rowavg_rule works as expected --- 179,194 ---- self.assertEquals(self.table.get_row(0), [3,4,5]) + self.assertEquals(len(self.stylesheet.rules), 1) + self.stylesheet.add_rule('some bad rule with bad syntax') + self.assertEquals(len(self.stylesheet.rules), 1, "Ill-formed rule mustn't be added") + self.assertEquals(len(self.stylesheet.instructions), 1, "Ill-formed rule mustn't be added") ! def test_stylesheet_init(self): ! """tests Stylesheet.__init__""" ! rule = '0_2 = 1' ! sheet = TableStyleSheet([rule, 'bad rule']) ! self.assertEquals(len(sheet.rules), 1, "Ill-formed rule mustn't be added") ! self.assertEquals(len(sheet.instructions), 1, "Ill-formed rule mustn't be added") ! def test_rowavg_rule(self): """Tests that add_rowavg_rule works as expected *************** *** 165,169 **** --- 234,333 ---- self.assert_(val == 22) + class TableStyleTC(unittest.TestCase): + """Test suite for TableSuite""" + def setUp(self): + self.table = Table() + self.table.create_rows(['row1', 'row2', 'row3']) + self.table.create_columns(['col1', 'col2']) + self.style = TableStyle(self.table) + self._tested_attrs = (('size', '1*'), + ('alignment', 'right'), + ('unit', '')) + + def test_getset(self): + """tests style's get and set methods""" + for attrname, default_value in self._tested_attrs: + getter = getattr(self.style, 'get_%s' % attrname) + setter = getattr(self.style, 'set_%s' % attrname) + self.assertRaises(KeyError, getter, 'badcol') + self.assertEquals(getter('col1'), default_value) + setter('FOO', 'col1') + self.assertEquals(getter('col1'), 'FOO') + + def test_getset_index(self): + """tests style's get and set by index methods""" + for attrname, default_value in self._tested_attrs: + getter = getattr(self.style, 'get_%s' % attrname) + setter = getattr(self.style, 'set_%s' % attrname) + igetter = getattr(self.style, 'get_%s_by_index' % attrname) + isetter = getattr(self.style, 'set_%s_by_index' % attrname) + self.assertEquals(getter('__row_column__'), default_value) + isetter('FOO', 0) + self.assertEquals(getter('__row_column__'), 'FOO') + self.assertEquals(igetter(0), 'FOO') + self.assertEquals(getter('col1'), default_value) + isetter('FOO', 1) + self.assertEquals(getter('col1'), 'FOO') + self.assertEquals(igetter(1), 'FOO') + + + class RendererTC(unittest.TestCase): + """Test suite for DocbookRenderer""" + def setUp(self): + self.renderer = DocbookRenderer(alignment = True) + self.table = Table() + self.table.create_rows(['row1', 'row2', 'row3']) + self.table.create_columns(['col1', 'col2']) + self.style = TableStyle(self.table) + self.base_renderer = TableCellRenderer() + + def test_cell_content(self): + """test how alignment is rendered""" + entry_xml = self.renderer._render_cell_content('data', self.style, 1) + self.assertEquals(entry_xml, "<entry align='right'>data</entry>\n") + self.style.set_alignment_by_index('left', 1) + entry_xml = self.renderer._render_cell_content('data', self.style, 1) + self.assertEquals(entry_xml, "<entry align='left'>data</entry>\n") + + def test_default_content_rendering(self): + """tests that default rendering just prints the cell's content""" + rendered_cell = self.base_renderer._render_cell_content('data', self.style, 1) + self.assertEquals(rendered_cell, "data") + + def test_replacement_char(self): + """tests that 0 is replaced when asked for""" + cell_content = self.base_renderer._make_cell_content(0, self.style, 1) + self.assertEquals(cell_content, 0) + self.base_renderer.properties['skip_zero'] = '---' + cell_content = self.base_renderer._make_cell_content(0, self.style, 1) + self.assertEquals(cell_content, '---') + def test_unit(self): + """tests if units are added""" + self.base_renderer.properties['units'] = True + self.style.set_unit_by_index('EUR', 1) + cell_content = self.base_renderer._make_cell_content(12, self.style, 1) + self.assertEquals(cell_content, '12 EUR') + + + from logilab.common import testlib + class DocbookTableWriterTC(testlib.TestCase): + """TestCase for table's writer""" + def setUp(self): + self.stream = StringIO() + self.table = Table() + self.table.create_rows(['row1', 'row2', 'row3']) + self.table.create_columns(['col1', 'col2']) + self.writer = DocbookTableWriter(self.stream, self.table, None) + self.writer.set_renderer(DocbookRenderer()) + + def test_write_table(self): + """make sure write_table() doesn't raise any exception""" + self.writer.write_table() + + def test_abstract_writer(self): + """tests that Abstract Writers can't be used !""" + writer = TableWriter(self.stream, self.table, None) + self.assertRaises(NotImplementedError, writer.write_table) def suite(): Index: unittest_astng_manager.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/common/test/unittest_astng_manager.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** unittest_astng_manager.py 21 Jan 2005 17:46:21 -0000 1.1 --- unittest_astng_manager.py 16 Feb 2005 16:45:45 -0000 1.2 *************** *** 2,11 **** import os from os.path import join ! from logilab.common.astng.manager import FileBasedASTNGManager ! class FileBasedASTNGManagerTC(unittest.TestCase): def setUp(self): ! self.manager = FileBasedASTNGManager() def test_from_directory(self): --- 2,11 ---- import os from os.path import join ! from logilab.common.astng.manager import ASTNGManager ! class ASTNGManagerTC(unittest.TestCase): def setUp(self): ! self.manager = ASTNGManager() def test_from_directory(self): Index: unittest_fileutils.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/common/test/unittest_fileutils.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** unittest_fileutils.py 21 Jan 2005 17:46:21 -0000 1.1 --- unittest_fileutils.py 16 Feb 2005 16:45:45 -0000 1.2 *************** *** 6,16 **** import unittest ! import sys from os.path import join ! from os import getcwd, linesep ! from logilab.common import fileutils from logilab.common.fileutils import * - from logilab.common.testlib import DocTest #import data --- 6,14 ---- import unittest ! import sys, os, tempfile, shutil from os.path import join ! from logilab.common.fileutils import * #import data *************** *** 18,27 **** NEWLINES_TXT = join(DATA_DIR,'newlines.txt') - - class RelativePathDocTest(DocTest): - """relative_path embed tests in docstring""" - module = fileutils - - class FirstleveldirectoryTC(unittest.TestCase): --- 16,19 ---- *************** *** 37,40 **** --- 29,33 ---- self.assertEqual(is_binary('toto.bin'), 1) self.assertEqual(is_binary('toto.sxi'), 1) + self.assertEqual(is_binary('toto.whatever'), 1) class GetModeTC(unittest.TestCase): *************** *** 48,52 **** def test_known_values_norm_read(self): data = norm_read(NEWLINES_TXT) ! self.assertEqual(data, linesep.join(['# mixed new lines', '1', '2', '3', ''])) --- 41,45 ---- def test_known_values_norm_read(self): data = norm_read(NEWLINES_TXT) ! self.assertEqual(data.strip(), '\n'.join(['# mixed new lines', '1', '2', '3'])) *************** *** 61,92 **** class GetByExtTC(unittest.TestCase): ! def test_kv_include(self): ! files = get_by_ext(DATA_DIR, include_exts=('.py',)) files.sort() self.assertEquals(files, ! ['data/__init__.py', 'data/module.py', 'data/module2.py', ! 'data/noendingnewline.py', 'data/nonregr.py', 'data/sub/momo.py']) ! def test_kv_exclude(self): ! files = get_by_ext(DATA_DIR, exclude_exts=('.py', '.pyc')) files.sort() self.assertEquals(files, ! ['data/newlines.txt', 'data/sub/doc.txt']) ! def suite(): ! """return the unitest suite""" ! loader = unittest.TestLoader() ! testsuite = loader.loadTestsFromModule(sys.modules[__name__]) ! return testsuite ! def Run(runner=None): ! """run tests""" ! testsuite = suite() ! if runner is None: ! runner = unittest.TextTestRunner() ! # uncomment next line to write tests results in a file ! #runner.__init__(open('tests.log','w+')) ! return runner.run(testsuite) if __name__ == '__main__': unittest.main() --- 54,100 ---- class GetByExtTC(unittest.TestCase): ! def test_include(self): ! files = files_by_ext(DATA_DIR, include_exts=('.py',)) files.sort() self.assertEquals(files, ! [join('data', f) for f in ['__init__.py', 'module.py', 'module2.py', ! 'noendingnewline.py', 'nonregr.py', join('sub', 'momo.py')]]) ! files = files_by_ext(DATA_DIR, include_exts=('.py',), exclude_dirs=('sub',)) ! files.sort() ! self.assertEquals(files, ! [join('data', f) for f in ['__init__.py', 'module.py', 'module2.py', ! 'noendingnewline.py', 'nonregr.py']]) ! def test_exclude(self): ! files = files_by_ext(DATA_DIR, exclude_exts=('.py', '.pyc')) files.sort() self.assertEquals(files, ! [join('data', f) for f in ['newlines.txt', join('sub', 'doc.txt')]]) ! def test_exclude_base_dir(self): ! self.assertEquals(files_by_ext(DATA_DIR, include_exts=('.py',), exclude_dirs=(DATA_DIR)), ! []) ! class ExportTC(unittest.TestCase): ! def setUp(self): ! self.tempdir = tempfile.mktemp() ! os.mkdir(self.tempdir) ! ! def test(self): ! export('data', self.tempdir, verbose=0) ! self.assert_(exists(join(self.tempdir, '__init__.py'))) ! self.assert_(exists(join(self.tempdir, 'sub'))) ! self.assert_(not exists(join(self.tempdir, '__init__.pyc'))) ! self.assert_(not exists(join(self.tempdir, 'CVS'))) + def tearDown(self): + shutil.rmtree(self.tempdir) + + from logilab.common.testlib import DocTest + class ModuleDocTest(DocTest): + """relative_path embed tests in docstring""" + from logilab.common import fileutils as module + del DocTest # necessary if we don't want it to be executed (we don't...) + if __name__ == '__main__': unittest.main() --- NEW FILE: foomod.py --- """fake module for logilb.common.bind's unit tests""" __revision__ = '$Id: foomod.py,v 1.1 2005/02/16 16:45:45 fabioz Exp $' VAR1 = 'var1' VAR2 = 'var2' def f1(): return 'a' def f2(): global VAR1 VAR1 = 'a' def f3(): global VAR1 VAR1 = 'b' Index: unittest_astng.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/common/test/unittest_astng.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** unittest_astng.py 21 Jan 2005 17:46:21 -0000 1.1 --- unittest_astng.py 16 Feb 2005 16:45:45 -0000 1.2 *************** *** 327,333 **** self.assert_(isinstance(_object, astng.Class)) self.assertEquals(_object.name, 'object') ! # check builtin function has argnames == [] _object = yo.resolve('dict') ! self.assertEquals(_object.locals['has_key'].argnames, []) def test_resolve_raise(self): --- 327,333 ---- self.assert_(isinstance(_object, astng.Class)) self.assertEquals(_object.name, 'object') ! # check builtin function has argnames == None _object = yo.resolve('dict') ! self.assertEquals(_object.locals['has_key'].argnames, None) def test_resolve_raise(self): *************** *** 338,341 **** --- 338,352 ---- self.assertRaises(ResolveError, NONREGR.locals['toto'].resolve_dotted, 'v.get') + def test_resolve_package_redirection(self): + sys.path.insert(1, 'astng_data') + try: + m = abuilder.file_build('astng_data/appl/myConnection.py', 'appl.myConnection') + cnx = m.resolve_dotted('SSL1.Connection') + self.assertEquals(cnx.__class__, astng.Class) + self.assertEquals(cnx.name, 'Connection') + self.assertEquals(cnx.root().name, 'Connection1') + finally: + del sys.path[1] + def test_get_assigned_value(self): my_dict = MODULE.locals['MY_DICT'] --- NEW FILE: unittest_testlib.py --- """unittest module for logilab.comon.testlib""" __revision__ = '$Id: unittest_testlib.py,v 1.1 2005/02/16 16:45:45 fabioz Exp $' import unittest from logilab.common import testlib class MockTestCase(testlib.TestCase): def __init__(self): # Do not call unittest.TestCase's __init__ pass def fail(self, msg): raise AssertionError(msg) class TestlibTC(unittest.TestCase): def setUp(self): self.tc = MockTestCase() def test_dict_equals(self): """tests TestCase.assertDictEquals""" d1 = {'a' : 1, 'b' : 2} d2 = {'a' : 1, 'b' : 3} d3 = dict(d1) self.assertRaises(AssertionError, self.tc.assertDictEquals, d1, d2) self.tc.assertDictEquals(d1, d3) self.tc.assertDictEquals(d3, d1) self.tc.assertDictEquals(d1, d1) def test_list_equals(self): """tests TestCase.assertListEquals""" l1 = range(10) l2 = range(5) l3 = range(10) self.assertRaises(AssertionError, self.tc.assertListEquals, l1, l2) self.tc.assertListEquals(l1, l1) self.tc.assertListEquals(l1, l3) self.tc.assertListEquals(l3, l1) def test_lines_equals(self): """tests assertLineEquals""" t1 = """some text """ t2 = """some text""" t3 = """some text""" self.assertRaises(AssertionError, self.tc.assertLinesEquals, t1, t2) self.tc.assertLinesEquals(t1, t3) self.tc.assertLinesEquals(t3, t1) self.tc.assertLinesEquals(t1, t1) def test_xml_valid(self): """tests xml is valid""" valid = """<root> <hello /> <world>Logilab</world> </root>""" invalid = """<root><h2> </root>""" self.tc.assertXMLStringValid(valid) self.assertRaises(AssertionError, self.tc.assertXMLStringValid, invalid) invalid = """<root><h2 </h2> </root>""" self.assertRaises(AssertionError, self.tc.assertXMLStringValid, invalid) if __name__ == '__main__': unittest.main() Index: unittest_textutils.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/common/test/unittest_textutils.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** unittest_textutils.py 21 Jan 2005 17:46:21 -0000 1.1 --- unittest_textutils.py 16 Feb 2005 16:45:45 -0000 1.2 *************** *** 27,34 **** return string ! class NormalizeTextFunctionTest(unittest.TestCase): def test_known_values(self): ! self.assertEqual(ulines(normalize_text('''some really malformated text. With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes --- 27,34 ---- return string ! class NormalizeTextTC(unittest.TestCase): def test_known_values(self): ! self.assertEquals(ulines(normalize_text('''some really malformated text. With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes *************** *** 45,49 **** def test_known_values(self): ! self.assertEqual(ulines(normalize_text("""This package contains test files shared by the logilab-common package. It isn't necessary to install this package unless you want to execute or look at the tests.""", indent=' ', line_len=70)), --- 45,49 ---- def test_known_values(self): ! self.assertEquals(ulines(normalize_text("""This package contains test files shared by the logilab-common package. It isn't necessary to install this package unless you want to execute or look at the tests.""", indent=' ', line_len=70)), *************** *** 54,69 **** ! class GetCsvFunctionTest(unittest.TestCase): def test_known(self): ! self.assertEqual(get_csv('a, b,c '), ['a', 'b', 'c']) RGX = re.compile('abcd') ! class PrettyMatchFunctionTest(unittest.TestCase): def test_known(self): string = 'hiuherabcdef' ! self.assertEqual(ulines(pretty_match(RGX.search(string), string)), 'hiuherabcdef\n ^^^^') def test_known_values_1(self): --- 54,69 ---- ! class GetCsvTC(unittest.TestCase): def test_known(self): ! self.assertEquals(get_csv('a, b,c '), ['a', 'b', 'c']) RGX = re.compile('abcd') ! class PrettyMatchTC(unittest.TestCase): def test_known(self): string = 'hiuherabcdef' ! self.assertEquals(ulines(pretty_match(RGX.search(string), string)), 'hiuherabcdef\n ^^^^') def test_known_values_1(self): *************** *** 71,75 **** string = 'toto' match = rgx.search(string) ! self.assertEqual(ulines(pretty_match(match, string)), '''toto ^^''') --- 71,75 ---- string = 'toto' match = rgx.search(string) ! self.assertEquals(ulines(pretty_match(match, string)), '''toto ^^''') *************** *** 79,83 **** ... ... ''' match = rgx.search(string) ! self.assertEqual(ulines(pretty_match(match, string)), ''' ... ... to to ^^ ... ...''') --- 79,83 ---- ... ... ''' match = rgx.search(string) ! self.assertEquals(ulines(pretty_match(match, string)), ''' ... ... to to ^^ ... ...''') *************** *** 86,110 **** ! class SearchAllFunctionTest(unittest.TestCase): def test_known(self): string = 'hiuherabcdefabcd' ! self.assertEqual(len(searchall(RGX, string)), 2) - def suite(): - """return the unitest suite""" - loader = unittest.TestLoader() - testsuite = loader.loadTestsFromModule(sys.modules[__name__]) - return testsuite ! def Run(runner=None): ! """run tests""" ! testsuite = suite() ! if runner is None: ! runner = unittest.TextTestRunner() ! # uncomment next line to write tests results in a file ! #runner.__init__(open('tests.log','w+')) ! return runner.run(testsuite) if __name__ == '__main__': ! Run() --- 86,120 ---- ! class SearchAllTC(unittest.TestCase): def test_known(self): string = 'hiuherabcdefabcd' ! self.assertEquals(len(searchall(RGX, string)), 2) ! class UnquoteTC(unittest.TestCase): ! def test(self): ! self.assertEquals(unquote('"toto"'), 'toto') ! self.assertEquals(unquote("'l'inenarrable toto'"), "l'inenarrable toto") ! self.assertEquals(unquote("no quote"), "no quote") ! ! ! class ColorizeAnsiTC(unittest.TestCase): ! def test_known(self): ! self.assertEquals(colorize_ansi('hello', 'blue', 'strike'), '\x1b[9;34mhello\x1b[0m') ! self.assertEquals(colorize_ansi('hello', style='strike, inverse'), '\x1b[9;7mhello\x1b[0m') ! self.assertEquals(colorize_ansi('hello', None, None), 'hello') ! self.assertEquals(colorize_ansi('hello', '', ''), 'hello') ! def test_raise(self): ! self.assertRaises(KeyError, colorize_ansi, 'hello', 'bleu', None) ! self.assertRaises(KeyError, colorize_ansi, 'hello', None, 'italique') ! ! ! from logilab.common.testlib import DocTest ! class ModuleDocTest(DocTest): ! """test doc test in this module""" ! from logilab.common import textutils as module ! del DocTest # necessary if we don't want it to be executed (we don't...) if __name__ == '__main__': ! unittest.main() --- NEW FILE: unittest_configuration.py --- import unittest from logilab.common import testlib import tempfile import os from cStringIO import StringIO from logilab.common.configuration import Configuration, OptionValueError options = [('dothis', {'type':'yn', 'default': True, 'metavar': '<y or n>'}), ('value', {'type': 'string', 'metavar': '<string>', 'short': 'v'}), ('multiple', {'type': 'csv', 'default': ('yop',), 'metavar': '<comma separated values>', 'help': 'you can also document the option'}), ('number', {'type': 'int', 'default':2, 'metavar':'<int>'}), ('choice', {'type': 'choice', 'default':'yo', 'choices': ('yo', 'ye'), 'metavar':'<yo|ye>'}), ('multiple-choice', {'type': 'multiple_choice', 'default':('yo', 'ye'), 'choices': ('yo', 'ye', 'yu', 'yi', 'ya'), 'metavar':'<yo|ye>'}), ] class ConfigurationTC(testlib.TestCase): def setUp(self): self.cfg = Configuration(name='test', options=options, usage='Just do it ! (tm)') def test_default(self): cfg = self.cfg self.assertEquals(cfg['dothis'], True) self.assertEquals(cfg['value'], None) self.assertEquals(cfg['multiple'], ('yop',)) self.assertEquals(cfg['number'], 2) self.assertEquals(cfg['choice'], 'yo') self.assertEquals(cfg['multiple-choice'], ('yo', 'ye')) def test_base(self): cfg = self.cfg cfg.set_option('number', '0') self.assertEquals(cfg['number'], 0) self.assertRaises(OptionValueError, cfg.set_option, 'number', 'youpi') self.assertRaises(OptionValueError, cfg.set_option, 'choice', 'youpi') self.assertRaises(OptionValueError, cfg.set_option, 'multiple-choice', ('yo', 'y', 'ya')) cfg.set_option('multiple-choice', 'yo, ya') self.assertEquals(cfg['multiple-choice'], ['yo', 'ya']) self.assertEquals(cfg.get('multiple-choice'), ['yo', 'ya']) self.assertEquals(cfg.get('whatever'), None) def test_load_command_line_configuration(self): cfg = self.cfg args = cfg.load_command_line_configuration(['--choice', 'ye', '--number', '4', '--multiple=1,2,3', '--dothis=n', 'other', 'arguments']) self.assertEquals(args, ['other', 'arguments']) self.assertEquals(cfg['dothis'], False) self.assertEquals(cfg['multiple'], ['1', '2', '3']) self.assertEquals(cfg['number'], 4) self.assertEquals(cfg['choice'], 'ye') self.assertEquals(cfg['value'], None) args = cfg.load_command_line_configuration(['-v', 'duh']) self.assertEquals(args, []) self.assertEquals(cfg['value'], 'duh') self.assertEquals(cfg['dothis'], False) self.assertEquals(cfg['multiple'], ['1', '2', '3']) self.assertEquals(cfg['number'], 4) self.assertEquals(cfg['choice'], 'ye') def test_load_configuration(self): cfg = self.cfg args = cfg.load_configuration(choice='ye', number='4', multiple='1,2,3', dothis='n', multiple_choice=('yo', 'ya')) self.assertEquals(cfg['dothis'], False) self.assertEquals(cfg['multiple'], ['1', '2', '3']) self.assertEquals(cfg['number'], 4) self.assertEquals(cfg['choice'], 'ye') self.assertEquals(cfg['value'], None) self.assertEquals(cfg['multiple-choice'], ('yo', 'ya')) def test_generate_config(self): stream = StringIO() self.cfg.generate_config(stream) self.assertLinesEquals(stream.getvalue().strip(), """# class for simple configurations which don't need the # manager / providers model and prefer delegation to inheritance # # configuration values are accessible through a dict like interface # [TEST] dothis=yes # you can also document the option multiple=yop number=2 choice=yo multiple-choice=yo,ye """) def test_generate_config_with_space_string(self): self.cfg['value'] = ' ' stream = StringIO() self.cfg.generate_config(stream) self.assertLinesEquals(stream.getvalue().strip(), """# class for simple configurations which don't need the # manager / providers model and prefer delegation to inheritance # # configuration values are accessible through a dict like interface # [TEST] dothis=yes value=' ' # you can also document the option multiple=yop number=2 choice=yo multiple-choice=yo,ye """) def test_loopback(self): cfg = self.cfg f = tempfile.mktemp() stream = open(f, 'w') try: cfg.generate_config(stream) stream.close() new_cfg = Configuration(name='testloop', options=options) new_cfg.load_file_configuration(f) self.assertEquals(cfg['dothis'], new_cfg['dothis']) self.assertEquals(cfg['multiple'], new_cfg['multiple']) self.assertEquals(cfg['number'], new_cfg['number']) self.assertEquals(cfg['choice'], new_cfg['choice']) self.assertEquals(cfg['value'], new_cfg['value']) self.assertEquals(cfg['multiple-choice'], new_cfg['multiple-choice']) finally: os.remove(f) def test_help(self): self.cfg.add_help_section('bonus', 'a nice additional help') self.assertLinesEquals(self.cfg.help().strip(), """usage: Just do it ! (tm) options: -h, --help show this help message and exit --dothis=<y or n> -v<string>, --value=<string> --multiple=<comma separated values> you can also document the option --number=<int> --choice=<yo|ye> --multiple-choice=<yo|ye> Bonus: a nice additional help """.strip()) if __name__ == '__main__': unittest.main() --- NEW FILE: unittest_bind.py --- """unit tests for logilab.common.bind module""" __revision__ = '$Id: unittest_bind.py,v 1.1 2005/02/16 16:45:45 fabioz Exp $' import unittest from sets import Set from logilab.common import bind HELLO = 'Hello' def f(): return HELLO def modify_hello(): global HELLO HELLO = 'hacked !' import foomod class BindTC(unittest.TestCase): """Test suite for bind module""" def test_simple_bind(self): """tests a simple global variable becomes a local one""" self.assertEquals(f(), HELLO) d = {'HELLO' : HELLO} new_f = bind.bind(f, d) self.assertEquals(new_f(), f()) f_consts = f.func_code.co_consts newf_consts = new_f.func_code.co_consts self.assertEquals(f_consts, (None,)) self.assert_(newf_consts, (None, HELLO)) def test_optimize_on_a_func(self): """make sure optimize only workds for modules""" self.assertRaises(TypeError, bind.optimize_module, f, ('c1', 'c2')) self.assertRaises(TypeError, bind.optimize_module_2, f, ('c1', 'c2')) self.assertRaises(TypeError, bind.optimize_module, [], ('c1', 'c2')) self.assertRaises(TypeError, bind.optimize_module_2, [], ('c1', 'c2')) def test_analyze_code(self): """tests bind.analyze_code()""" consts_dict, consts_list = {}, [] globs = {'HELLO' : "some global value"} modified = bind.analyze_code(modify_hello.func_code, globs, consts_dict, consts_list) self.assertEquals(consts_list, [None, 'hacked !']) self.assertEquals(modified, ['HELLO']) def test_optimize_module2(self): """test optimize_module_2()""" f1_consts = Set(foomod.f1.func_code.co_consts) f2_consts = Set(foomod.f2.func_code.co_consts) f3_consts = Set(foomod.f3.func_code.co_consts) bind.optimize_module_2(foomod, ['f1', 'f2', 'f3']) newf1_consts = Set(foomod.f1.func_code.co_consts) newf2_consts = Set(foomod.f2.func_code.co_consts) newf3_consts = Set(foomod.f3.func_code.co_consts) self.assert_(newf1_consts == newf2_consts == newf3_consts) self.assertEquals(newf1_consts, f1_consts | f2_consts | f3_consts) if __name__ == '__main__': unittest.main() Index: unittest_db.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/common/test/unittest_db.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** unittest_db.py 21 Jan 2005 17:46:21 -0000 1.1 --- unittest_db.py 16 Feb 2005 16:45:45 -0000 1.2 *************** *** 44,48 **** def setUp(self): self.host = 'crater.logilab.fr' ! self.db = 'bugtracker' self.user = 'adim' self.passwd = 'adim' --- 44,48 ---- def setUp(self): self.host = 'crater.logilab.fr' ! self.db = 'gincotest2' self.user = 'adim' self.passwd = 'adim' *************** *** 97,101 **** self.old_drivers = PREFERED_DRIVERS['postgres'][:] self.host = 'crater.logilab.fr' ! self.db = 'bugtracker' self.user = 'adim' self.passwd = 'adim' --- 97,101 ---- self.old_drivers = PREFERED_DRIVERS['postgres'][:] self.host = 'crater.logilab.fr' ! self.db = 'gincotest2' self.user = 'adim' self.passwd = 'adim' |