diff options
| author | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2011-02-02 11:49:57 +0100 |
|---|---|---|
| committer | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2011-02-02 11:49:57 +0100 |
| commit | b22ac9d912f61f8f2f9e6ce155a40415018ca3b2 (patch) | |
| tree | ada20f54d5014502a1de62d6c1d221af99dc5cfa /distutils2/tests/test_util.py | |
| parent | 6e1e6463fa755554444f76ce1c447172622f0392 (diff) | |
| download | disutils2-b22ac9d912f61f8f2f9e6ce155a40415018ca3b2.tar.gz | |
merge test_glob.py into test_util.py
Diffstat (limited to 'distutils2/tests/test_util.py')
| -rw-r--r-- | distutils2/tests/test_util.py | 153 |
1 files changed, 151 insertions, 2 deletions
diff --git a/distutils2/tests/test_util.py b/distutils2/tests/test_util.py index 61d1013..582e24c 100644 --- a/distutils2/tests/test_util.py +++ b/distutils2/tests/test_util.py @@ -18,7 +18,7 @@ from distutils2.util import (convert_path, change_root, _find_exe_version, _MAC_OS_X_LD_VERSION, byte_compile, find_packages, spawn, find_executable, _nt_quote_args, get_pypirc_path, generate_pypirc, - read_pypirc, resolve_name) + read_pypirc, resolve_name, iglob, RICH_GLOB) from distutils2 import util from distutils2.tests import unittest, support @@ -479,9 +479,158 @@ class UtilTestCase(support.EnvironGuard, content = open(rc).read() self.assertEqual(content, WANTED) +class GlobTestCaseBase(support.TempdirManager, + support.LoggingCatcher, + unittest.TestCase): + + def build_files_tree(self, files): + tempdir = self.mkdtemp() + for filepath in files: + is_dir = filepath.endswith('/') + filepath = os.path.join(tempdir, *filepath.split('/')) + if is_dir: + dirname = filepath + else: + dirname = os.path.dirname(filepath) + if dirname and not os.path.exists(dirname): + os.makedirs(dirname) + if not is_dir: + self.write_file(filepath, 'babar') + return tempdir + + @staticmethod + def os_dependant_path(path): + path = path.rstrip('/').split('/') + return os.path.join(*path) + + def clean_tree(self, spec): + files = [] + for path, includes in list(spec.items()): + if includes: + files.append(self.os_dependant_path(path)) + return files + +class GlobTestCase(GlobTestCaseBase): + + + def assertGlobMatch(self, glob, spec): + """""" + tempdir = self.build_files_tree(spec) + expected = self.clean_tree(spec) + self.addCleanup(os.chdir, os.getcwd()) + os.chdir(tempdir) + result = list(iglob(glob)) + self.assertItemsEqual(expected, result) + + def test_regex_rich_glob(self): + matches = RICH_GLOB.findall(r"babar aime les {fraises} est les {huitres}") + self.assertEquals(["fraises","huitres"], matches) + + def test_simple_glob(self): + glob = '*.tp?' + spec = {'coucou.tpl': True, + 'coucou.tpj': True, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + + def test_simple_glob_in_dir(self): + glob = 'babar/*.tp?' + spec = {'babar/coucou.tpl': True, + 'babar/coucou.tpj': True, + 'babar/toto.bin': False, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + + def test_recursive_glob_head(self): + glob = '**/tip/*.t?l' + spec = {'babar/zaza/zuzu/tip/coucou.tpl': True, + 'babar/z/tip/coucou.tpl': True, + 'babar/tip/coucou.tpl': True, + 'babar/zeop/tip/babar/babar.tpl': False, + 'babar/z/tip/coucou.bin': False, + 'babar/toto.bin': False, + 'zozo/zuzu/tip/babar.tpl': True, + 'zozo/tip/babar.tpl': True, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + + def test_recursive_glob_tail(self): + glob = 'babar/**' + spec = {'babar/zaza/': True, + 'babar/zaza/zuzu/': True, + 'babar/zaza/zuzu/babar.xml': True, + 'babar/zaza/zuzu/toto.xml': True, + 'babar/zaza/zuzu/toto.csv': True, + 'babar/zaza/coucou.tpl': True, + 'babar/bubu.tpl': True, + 'zozo/zuzu/tip/babar.tpl': False, + 'zozo/tip/babar.tpl': False, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + + def test_recursive_glob_middle(self): + glob = 'babar/**/tip/*.t?l' + spec = {'babar/zaza/zuzu/tip/coucou.tpl': True, + 'babar/z/tip/coucou.tpl': True, + 'babar/tip/coucou.tpl': True, + 'babar/zeop/tip/babar/babar.tpl': False, + 'babar/z/tip/coucou.bin': False, + 'babar/toto.bin': False, + 'zozo/zuzu/tip/babar.tpl': False, + 'zozo/tip/babar.tpl': False, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + + def test_glob_set_tail(self): + glob = 'bin/*.{bin,sh,exe}' + spec = {'bin/babar.bin': True, + 'bin/zephir.sh': True, + 'bin/celestine.exe': True, + 'bin/cornelius.bat': False, + 'bin/cornelius.xml': False, + 'toto/yurg': False, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + + def test_glob_set_middle(self): + glob = 'xml/{babar,toto}.xml' + spec = {'xml/babar.xml': True, + 'xml/toto.xml': True, + 'xml/babar.xslt': False, + 'xml/cornelius.sgml': False, + 'xml/zephir.xml': False, + 'toto/yurg.xml': False, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + + def test_glob_set_head(self): + glob = '{xml,xslt}/babar.*' + spec = {'xml/babar.xml': True, + 'xml/toto.xml': False, + 'xslt/babar.xslt': True, + 'xslt/toto.xslt': False, + 'toto/yurg.xml': False, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + + def test_glob_all(self): + glob = '{xml/*,xslt/**}/babar.xml' + spec = {'xml/a/babar.xml': True, + 'xml/b/babar.xml': True, + 'xml/a/c/babar.xml': False, + 'xslt/a/babar.xml': True, + 'xslt/b/babar.xml': True, + 'xslt/a/c/babar.xml': True, + 'toto/yurg.xml': False, + 'Donotwant': False} + self.assertGlobMatch(glob, spec) + def test_suite(): - return unittest.makeSuite(UtilTestCase) + suite = unittest.makeSuite(UtilTestCase) + suite.addTest(unittest.makeSuite(GlobTestCase)) + return suite + if __name__ == "__main__": unittest.main(defaultTest="test_suite") |
