summaryrefslogtreecommitdiff
path: root/distutils2/tests
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2011-02-13 23:29:08 +0000
committerAlexis Metaireau <alexis@notmyidea.org>2011-02-13 23:29:08 +0000
commitbdf07a2a753c412d8917f4301eb76f5824d47ec0 (patch)
tree1f3ff68808f0c69180269ca17a6fbe38e858a4d7 /distutils2/tests
parent2aaf56ad04182526643c55533941c854a9dfee32 (diff)
parente8e24f0af1df9fe9e9f32704756dabcc185754eb (diff)
downloaddisutils2-bdf07a2a753c412d8917f4301eb76f5824d47ec0.tar.gz
Merge Kelsey changes
Diffstat (limited to 'distutils2/tests')
-rw-r--r--distutils2/tests/test_command_install_data.py32
-rw-r--r--distutils2/tests/test_command_sdist.py9
-rw-r--r--distutils2/tests/test_config.py26
-rw-r--r--distutils2/tests/test_mkcfg.py17
-rw-r--r--distutils2/tests/test_resources.py174
-rw-r--r--distutils2/tests/test_util.py181
6 files changed, 406 insertions, 33 deletions
diff --git a/distutils2/tests/test_command_install_data.py b/distutils2/tests/test_command_install_data.py
index f2ee74c..b02a7d4 100644
--- a/distutils2/tests/test_command_install_data.py
+++ b/distutils2/tests/test_command_install_data.py
@@ -1,4 +1,5 @@
"""Tests for distutils.command.install_data."""
+import cmd
import os
from distutils2.command.install_data import install_data
@@ -10,21 +11,29 @@ class InstallDataTestCase(support.TempdirManager,
unittest.TestCase):
def test_simple_run(self):
+ from distutils2._backport.sysconfig import _SCHEMES as sysconfig_SCHEMES
+ from distutils2._backport.sysconfig import _get_default_scheme
+ #dirty but hit marmoute
+
+ old_scheme = sysconfig_SCHEMES
+
pkg_dir, dist = self.create_dist()
cmd = install_data(dist)
cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
- # data_files can contain
- # - simple files
- # - a tuple with a path, and a list of file
+ sysconfig_SCHEMES.set(_get_default_scheme(), 'inst',
+ os.path.join(pkg_dir, 'inst'))
+ sysconfig_SCHEMES.set(_get_default_scheme(), 'inst2',
+ os.path.join(pkg_dir, 'inst2'))
+
one = os.path.join(pkg_dir, 'one')
self.write_file(one, 'xxx')
inst2 = os.path.join(pkg_dir, 'inst2')
two = os.path.join(pkg_dir, 'two')
self.write_file(two, 'xxx')
- cmd.data_files = [one, (inst2, [two])]
- self.assertEqual(cmd.get_inputs(), [one, (inst2, [two])])
+ cmd.data_files = {one : '{inst}/one', two : '{inst2}/two'}
+ self.assertItemsEqual(cmd.get_inputs(), [one, two])
# let's run the command
cmd.ensure_finalized()
@@ -54,17 +63,22 @@ class InstallDataTestCase(support.TempdirManager,
inst4 = os.path.join(pkg_dir, 'inst4')
three = os.path.join(cmd.install_dir, 'three')
self.write_file(three, 'xx')
- cmd.data_files = [one, (inst2, [two]),
- ('inst3', [three]),
- (inst4, [])]
+
+ sysconfig_SCHEMES.set(_get_default_scheme(), 'inst3', cmd.install_dir)
+
+ cmd.data_files = {one : '{inst}/one',
+ two : '{inst2}/two',
+ three : '{inst3}/three'}
cmd.ensure_finalized()
cmd.run()
# let's check the result
- self.assertEqual(len(cmd.get_outputs()), 4)
+ self.assertEqual(len(cmd.get_outputs()), 3)
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
+ sysconfig_SCHEMES = old_scheme
+
def test_suite():
return unittest.makeSuite(InstallDataTestCase)
diff --git a/distutils2/tests/test_command_sdist.py b/distutils2/tests/test_command_sdist.py
index 4f74876..f43e6cc 100644
--- a/distutils2/tests/test_command_sdist.py
+++ b/distutils2/tests/test_command_sdist.py
@@ -202,11 +202,10 @@ class SDistTestCase(support.TempdirManager, support.LoggingCatcher,
self.write_file((some_dir, 'file.txt'), '#')
self.write_file((some_dir, 'other_file.txt'), '#')
- dist.data_files = [('data', ['data/data.dt',
- 'inroot.txt',
- 'notexisting']),
- 'some/file.txt',
- 'some/other_file.txt']
+ dist.data_files = {'data/data.dt' : '{appdata}/data.dt',
+ 'inroot.txt' : '{appdata}/inroot.txt',
+ 'some/file.txt' : '{appdata}/file.txt',
+ 'some/other_file.txt' : '{appdata}/other_file.txt'}
# adding a script
script_dir = join(self.tmp_dir, 'scripts')
diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py
index d4f5776..9ee2514 100644
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -65,11 +65,6 @@ scripts =
package_data =
cheese = data/templates/*
-data_files =
- bitmaps = bm/b1.gif, bm/b2.gif
- config = cfg/data.cfg
- /etc/init.d = init-script
-
extra_files = %(extra-files)s
# Replaces MANIFEST.in
@@ -78,6 +73,11 @@ sdist_extra =
recursive-include examples *.txt *.py
prune examples/sample?/build
+resources=
+ bm/ {b1,b2}.gif = {icon}
+ Cf*/ *.CFG = {config}/baBar/
+ init_script = {script}/JunGle/
+
[global]
commands =
distutils2.tests.test_config.FooBarBazTest
@@ -193,6 +193,12 @@ class ConfigTestCase(support.TempdirManager,
def test_config(self):
self.write_setup()
self.write_file('README', 'yeah')
+ os.mkdir('bm')
+ self.write_file(os.path.join('bm', 'b1.gif'), '')
+ self.write_file(os.path.join('bm', 'b2.gif'), '')
+ os.mkdir('Cfg')
+ self.write_file(os.path.join('Cfg', 'data.CFG'), '')
+ self.write_file('init_script', '')
# try to load the metadata now
dist = self.run_setup('--version')
@@ -237,10 +243,12 @@ class ConfigTestCase(support.TempdirManager,
self.assertEqual(dist.packages, ['one', 'two', 'three'])
self.assertEqual(dist.py_modules, ['haven'])
self.assertEqual(dist.package_data, {'cheese': 'data/templates/*'})
- self.assertEqual(dist.data_files,
- [('bitmaps ', ['bm/b1.gif', 'bm/b2.gif']),
- ('config ', ['cfg/data.cfg']),
- ('/etc/init.d ', ['init-script'])])
+ self.assertEqual(
+ {'bm/b1.gif' : '{icon}/b1.gif',
+ 'bm/b2.gif' : '{icon}/b2.gif',
+ 'Cfg/data.CFG' : '{config}/baBar/data.CFG',
+ 'init_script' : '{script}/JunGle/init_script'},
+ dist.data_files)
self.assertEqual(dist.package_dir, 'src')
diff --git a/distutils2/tests/test_mkcfg.py b/distutils2/tests/test_mkcfg.py
index b289b49..c49a877 100644
--- a/distutils2/tests/test_mkcfg.py
+++ b/distutils2/tests/test_mkcfg.py
@@ -153,9 +153,9 @@ class MkcfgTestCase(support.TempdirManager,
' pyxfoil/fengine.so',
'scripts = my_script',
' bin/run',
- '[resources]',
- 'README.rst = {doc}',
- 'pyxfoil.1 = {man}',
+ 'resources =',
+ ' README.rst = {doc}',
+ ' pyxfoil.1 = {man}',
]))
def test_convert_setup_py_to_cfg_with_description_in_readme(self):
@@ -173,7 +173,7 @@ class MkcfgTestCase(support.TempdirManager,
url='http://www.python-science.org/project/pyxfoil',
license='GPLv2',
packages=['pyxfoil'],
- package_data={'pyxfoil' : ['fengine.so']},
+ package_data={'pyxfoil' : ['fengine.so', 'babar.so']},
data_files=[
('share/doc/pyxfoil', ['README.rst']),
('share/man', ['pyxfoil.1']),
@@ -191,7 +191,7 @@ ho, baby !
main()
fp = open(os.path.join(self.wdir, 'setup.cfg'))
try:
- lines = set([line.strip() for line in fp])
+ lines = set([line.rstrip() for line in fp])
finally:
fp.close()
self.assertEqual(lines, set(['',
@@ -207,9 +207,10 @@ ho, baby !
'[files]',
'packages = pyxfoil',
'extra_files = pyxfoil/fengine.so',
- '[resources]',
- 'README.rst = {doc}',
- 'pyxfoil.1 = {man}',
+ ' pyxfoil/babar.so',
+ 'resources =',
+ ' README.rst = {doc}',
+ ' pyxfoil.1 = {man}',
]))
diff --git a/distutils2/tests/test_resources.py b/distutils2/tests/test_resources.py
new file mode 100644
index 0000000..6678006
--- /dev/null
+++ b/distutils2/tests/test_resources.py
@@ -0,0 +1,174 @@
+# -*- encoding: utf-8 -*-
+"""Tests for distutils.data."""
+import pkgutil
+import sys
+
+from distutils2._backport.pkgutil import resource_open
+from distutils2._backport.pkgutil import resource_path
+from distutils2._backport.pkgutil import disable_cache
+from distutils2._backport.pkgutil import enable_cache
+from distutils2.command.install_dist import install_dist
+from distutils2.resources import resources_dests
+from distutils2.tests import run_unittest
+from distutils2.tests import unittest
+from distutils2.tests.test_util import GlobTestCaseBase
+import os
+import tempfile
+
+
+class DataFilesTestCase(GlobTestCaseBase):
+
+ def assertRulesMatch(self, rules, spec):
+ tempdir = self.build_files_tree(spec)
+ expected = self.clean_tree(spec)
+ result = resources_dests(tempdir, rules)
+ self.assertEquals(expected, result)
+
+ def clean_tree(self, spec):
+ files = {}
+ for path, value in spec.items():
+ if value is not None:
+ path = self.os_dependant_path(path)
+ files[path] = value
+ return files
+
+ def test_simple_glob(self):
+ rules = [('', '*.tpl', '{data}')]
+ spec = {'coucou.tpl': '{data}/coucou.tpl',
+ 'Donotwant': None}
+ self.assertRulesMatch(rules, spec)
+
+ def test_multiple_match(self):
+ rules = [('scripts', '*.bin', '{appdata}'),
+ ('scripts', '*', '{appscript}')]
+ spec = {'scripts/script.bin': '{appscript}/script.bin',
+ 'Babarlikestrawberry': None}
+ self.assertRulesMatch(rules, spec)
+
+ def test_set_match(self):
+ rules = [('scripts', '*.{bin,sh}', '{appscript}')]
+ spec = {'scripts/script.bin': '{appscript}/script.bin',
+ 'scripts/babar.sh': '{appscript}/babar.sh',
+ 'Babarlikestrawberry': None}
+ self.assertRulesMatch(rules, spec)
+
+ def test_set_match_multiple(self):
+ rules = [('scripts', 'script{s,}.{bin,sh}', '{appscript}')]
+ spec = {'scripts/scripts.bin': '{appscript}/scripts.bin',
+ 'scripts/script.sh': '{appscript}/script.sh',
+ 'Babarlikestrawberry': None}
+ self.assertRulesMatch(rules, spec)
+
+ def test_set_match_exclude(self):
+ rules = [('scripts', '*', '{appscript}'),
+ ('', '**/*.sh', None)]
+ spec = {'scripts/scripts.bin': '{appscript}/scripts.bin',
+ 'scripts/script.sh': None,
+ 'Babarlikestrawberry': None}
+ self.assertRulesMatch(rules, spec)
+
+ def test_glob_in_base(self):
+ rules = [('scrip*', '*.bin', '{appscript}')]
+ spec = {'scripts/scripts.bin': '{appscript}/scripts.bin',
+ 'scripouille/babar.bin': '{appscript}/babar.bin',
+ 'scriptortu/lotus.bin': '{appscript}/lotus.bin',
+ 'Babarlikestrawberry': None}
+ self.assertRulesMatch(rules, spec)
+
+ def test_recursive_glob(self):
+ rules = [('', '**/*.bin', '{binary}')]
+ spec = {'binary0.bin': '{binary}/binary0.bin',
+ 'scripts/binary1.bin': '{binary}/scripts/binary1.bin',
+ 'scripts/bin/binary2.bin': '{binary}/scripts/bin/binary2.bin',
+ 'you/kill/pandabear.guy': None}
+ self.assertRulesMatch(rules, spec)
+
+ def test_final_exemple_glob(self):
+ rules = [
+ ('mailman/database/schemas/', '*', '{appdata}/schemas'),
+ ('', '**/*.tpl', '{appdata}/templates'),
+ ('', 'developer-docs/**/*.txt', '{doc}'),
+ ('', 'README', '{doc}'),
+ ('mailman/etc/', '*', '{config}'),
+ ('mailman/foo/', '**/bar/*.cfg', '{config}/baz'),
+ ('mailman/foo/', '**/*.cfg', '{config}/hmm'),
+ ('', 'some-new-semantic.sns', '{funky-crazy-category}')
+ ]
+ spec = {
+ 'README': '{doc}/README',
+ 'some.tpl': '{appdata}/templates/some.tpl',
+ 'some-new-semantic.sns': '{funky-crazy-category}/some-new-semantic.sns',
+ 'mailman/database/mailman.db': None,
+ 'mailman/database/schemas/blah.schema': '{appdata}/schemas/blah.schema',
+ 'mailman/etc/my.cnf': '{config}/my.cnf',
+ 'mailman/foo/some/path/bar/my.cfg': '{config}/hmm/some/path/bar/my.cfg',
+ 'mailman/foo/some/path/other.cfg': '{config}/hmm/some/path/other.cfg',
+ 'developer-docs/index.txt': '{doc}/developer-docs/index.txt',
+ 'developer-docs/api/toc.txt': '{doc}/developer-docs/api/toc.txt',
+ }
+ self.maxDiff = None
+ self.assertRulesMatch(rules, spec)
+
+ def test_resource_open(self):
+
+
+ #Create a fake-dist
+ temp_site_packages = tempfile.mkdtemp()
+
+ dist_name = 'test'
+ dist_info = os.path.join(temp_site_packages, 'test-0.1.dist-info')
+ os.mkdir(dist_info)
+
+ metadata_path = os.path.join(dist_info, 'METADATA')
+ resources_path = os.path.join(dist_info, 'RESOURCES')
+
+ metadata_file = open(metadata_path, 'w')
+
+ metadata_file.write(
+"""Metadata-Version: 1.2
+Name: test
+Version: 0.1
+Summary: test
+Author: me
+ """)
+
+ metadata_file.close()
+
+ test_path = 'test.cfg'
+
+ _, test_resource_path = tempfile.mkstemp()
+
+ test_resource_file = open(test_resource_path, 'w')
+
+ content = 'Config'
+ test_resource_file.write(content)
+ test_resource_file.close()
+
+ resources_file = open(resources_path, 'w')
+
+ resources_file.write("""%s,%s""" % (test_path, test_resource_path))
+ resources_file.close()
+
+ #Add fake site-packages to sys.path to retrieve fake dist
+ old_sys_path = sys.path
+ sys.path.insert(0, temp_site_packages)
+
+ #Force pkgutil to rescan the sys.path
+ disable_cache()
+
+ #Try to retrieve resources paths and files
+ self.assertEqual(resource_path(dist_name, test_path), test_resource_path)
+ self.assertRaises(KeyError, resource_path, dist_name, 'notexis')
+
+ self.assertEqual(resource_open(dist_name, test_path).read(), content)
+ self.assertRaises(KeyError, resource_open, dist_name, 'notexis')
+
+ sys.path = old_sys_path
+
+ enable_cache()
+
+def test_suite():
+ return unittest.makeSuite(DataFilesTestCase)
+
+if __name__ == '__main__':
+ run_unittest(test_suite())
diff --git a/distutils2/tests/test_util.py b/distutils2/tests/test_util.py
index 61d1013..e47bc0f 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,186 @@ 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_invalid_glob_pattern(self):
+ invalids = [
+ 'ppooa**',
+ 'azzaeaz4**/',
+ '/**ddsfs',
+ '**##1e"&e',
+ 'DSFb**c009',
+ '{'
+ '{aaQSDFa'
+ '}'
+ 'aQSDFSaa}'
+ '{**a,'
+ ',**a}'
+ '{a**,'
+ ',b**}'
+ '{a**a,babar}'
+ '{bob,b**z}'
+ ]
+ msg = "%r is not supposed to be a valid pattern"
+ for pattern in invalids:
+ try:
+ iglob(pattern)
+ except ValueError:
+ continue
+ else:
+ self.fail("%r is not a valid iglob pattern" % pattern)
+
+
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")