[Python-checkins] distutils2: added some test coverage and fixed the regexps
tarek.ziade
python-checkins at python.org
Sat May 15 10:58:23 CEST 2010
tarek.ziade pushed a960210179a9 to distutils2:
http://hg.python.org/distutils2/rev/a960210179a9
changeset: 152:a960210179a9
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Sat May 15 10:58:13 2010 +0200
summary: added some test coverage and fixed the regexps
files: src/distutils2/manifest.py, src/distutils2/tests/test_manifest.py
diff --git a/src/distutils2/manifest.py b/src/distutils2/manifest.py
--- a/src/distutils2/manifest.py
+++ b/src/distutils2/manifest.py
@@ -21,9 +21,8 @@
__all__ = ['Manifest']
# a \ followed by some spaces + EOL
-_COLLAPSE_PATTERN = re.compile('\\\w\n', re.M)
-_COMMENTED_LINE = re.compile('^#.*\n$|^\w*\n$', re.M)
-
+_COLLAPSE_PATTERN = re.compile('\\\w*\n', re.M)
+_COMMENTED_LINE = re.compile('#.*?(?=\n)|^\w*\n|\n(?=$)', re.M|re.S)
class Manifest(object):
"""A list of files built by on exploring the filesystem and filtered by
@@ -70,9 +69,10 @@
try:
content = f.read()
# first, let's unwrap collapsed lines
- content = _COLLAPSE_PATTERN.replace(content, '')
+ content = _COLLAPSE_PATTERN.sub('', content)
+
# next, let's remove commented lines and empty lines
- content = _COMMENTED_LINE.replace(content, '')
+ content = _COMMENTED_LINE.sub('', content)
# now we have our cleaned up lines
lines = [line.strip() for line in content.split('\n')]
@@ -83,7 +83,7 @@
try:
self._process_template_line(line)
except DistutilsTemplateError, msg:
- self.warn("%s, %s" % (path, msg))
+ logging.warning("%s, %s" % (path, msg))
def write(self, path):
"""Write the file list in 'self.filelist' (presumably as filled in
@@ -176,51 +176,50 @@
if action == 'include':
for pattern in patterns:
if not self._include_pattern(pattern, anchor=1):
- logging.warning("warning: no files found matching '%s'",
+ logging.warning("warning: no files found matching '%s'" %
pattern)
elif action == 'exclude':
for pattern in patterns:
if not self.exclude_pattern(pattern, anchor=1):
logging.warning(("warning: no previously-included files "
- "found matching '%s'"), pattern)
+ "found matching '%s'") % pattern)
elif action == 'global-include':
for pattern in patterns:
if not self._include_pattern(pattern, anchor=0):
logging.warning(("warning: no files found matching '%s' " +
- "anywhere in distribution"), pattern)
+ "anywhere in distribution") % pattern)
elif action == 'global-exclude':
for pattern in patterns:
if not self.exclude_pattern(pattern, anchor=0):
logging.warning(("warning: no previously-included files "
- "matching '%s' found anywhere in distribution"),
+ "matching '%s' found anywhere in distribution") %
pattern)
elif action == 'recursive-include':
for pattern in patterns:
if not self._include_pattern(pattern, prefix=dir):
logging.warning(("warning: no files found matching '%s' "
- "under directory '%s'"),
- pattern, dir)
+ "under directory '%s'" % (pattern, dir)))
elif action == 'recursive-exclude':
for pattern in patterns:
if not self.exclude_pattern(pattern, prefix=dir):
logging.warning(("warning: no previously-included files "
- "matching '%s' found under directory '%s'"),
- pattern, dir)
+ "matching '%s' found under directory '%s'") %
+ (pattern, dir))
elif action == 'graft':
if not self._include_pattern(None, prefix=dir_pattern):
- logging.warning("warning: no directories found matching '%s'",
+ logging.warning("warning: no directories found matching '%s'" %
dir_pattern)
elif action == 'prune':
if not self.exclude_pattern(None, prefix=dir_pattern):
logging.warning(("no previously-included directories found " +
- "matching '%s'"), dir_pattern)
+ "matching '%s'") % dir_pattern)
else:
raise DistutilsInternalError(
"this cannot happen: invalid action '%s'" % action)
diff --git a/src/distutils2/tests/test_manifest.py b/src/distutils2/tests/test_manifest.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/tests/test_manifest.py
@@ -0,0 +1,57 @@
+"""Tests for distutils.manifest."""
+import unittest2
+import os
+import sys
+import logging
+
+from distutils2.tests import support
+from distutils2.manifest import Manifest
+
+_MANIFEST = """\
+recursive-include foo *.py # ok
+# nothing here
+
+#
+
+recursive-include bar \\
+ *.dat *.txt
+"""
+
+class ManifestTestCase(support.TempdirManager,
+ unittest2.TestCase):
+
+ def test_manifest_reader(self):
+
+ tmpdir = self.mkdtemp()
+ MANIFEST = os.path.join(tmpdir, 'MANIFEST.in')
+ f = open(MANIFEST, 'w')
+ try:
+ f.write(_MANIFEST)
+ finally:
+ f.close()
+ manifest = Manifest()
+
+ warns = []
+ def _warn(msg):
+ warns.append(msg)
+
+ old_warn = logging.warning
+ logging.warning = _warn
+ try:
+ manifest.read_template(MANIFEST)
+ finally:
+ logging.warning = old_warn
+
+ # the manifest should have been read
+ # and 3 warnings issued (we ddidn't provided the files)
+ self.assertEquals(len(warns), 3)
+ for warn in warns:
+ self.assertIn('warning: no files found matching', warn)
+
+
+
+def test_suite():
+ return unittest2.makeSuite(ManifestTestCase)
+
+if __name__ == '__main__':
+ run_unittest(test_suite())
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list