from bzrlib.tests import TestCaseWithTransport from bzrlib.tests.TestUtil import TestLoader, TestSuite import os import os.path def test_suite(): module_names = [ 'bzrlib.plugins.bzrp4.tests.test_bzr2p4', 'bzrlib.plugins.bzrp4.tests.test_bzr2p4_blackbox', 'bzrlib.plugins.bzrp4.tests.test_git_p4', 'bzrlib.plugins.bzrp4.tests.test_git_p4_imported', 'bzrlib.plugins.bzrp4.tests.test_intermediate_file', 'bzrlib.plugins.bzrp4.tests.test_p4_fast_export', ] loader = TestLoader() return loader.loadTestsFromModuleNames(module_names) class TestCaseForTwoVcs(TestCaseWithTransport): def assertDirectoriesEqualModIgnored( self, lhs, rhs, lhs_ignore_dirents, rhs_ignore_dirents): for lhs_root, dirs, files in os.walk(lhs): for ignore in lhs_ignore_dirents: self._remove_without_exception(ignore, dirs) self._remove_without_exception(ignore, files) root = lhs_root[len(lhs)+1:] dirs_set = set(dirs) files_set = set(files) rhs_root = os.path.join(rhs, root) try: rhs_root, rhs_dirs, rhs_files = os.walk(rhs_root).next() for ignore in rhs_ignore_dirents: self._remove_without_exception(ignore, rhs_dirs) self._remove_without_exception(ignore, rhs_files) except StopIteration: self.fail('Could not read ' + rhs_root) self.assertEqual(0, len(dirs_set.symmetric_difference(rhs_dirs)), str(dirs) + ' != ' + str(rhs_dirs)) self.assertEqual(0, len(files_set.symmetric_difference(rhs_files)), str(files) + ' != ' + str(rhs_files)) # compare each file line-by-line, ignoring eol for file in files: self._assert_files_equal_mod_eol( os.path.join(lhs_root, file), os.path.join(rhs_root, file)) def _assert_files_equal_mod_eol(self, lhs, rhs): try: lhs_f = open(lhs, 'rb') rhs_f = open(rhs, 'rb') for lhs_line in lhs_f: rhs_line = rhs_f.next() self.assertEqual( lhs_line.rstrip('\n\r'), rhs_line.rstrip('\n\r')) try: possible_final_empty_line = rhs_f.next() assertEqual( '', possible_final_empty_line.rstrip('\n\r')) self.assertRaises(StopIteration, rhs_f.next()) except StopIteration: pass finally: lhs_f.close() rhs_f.close() @staticmethod def _remove_without_exception(item, list): if item in list: list.remove(item)