[Python-checkins] distutils2: Increase test coverage for manifest (#11751).
eric.araujo
python-checkins at python.org
Mon Nov 14 15:24:07 CET 2011
http://hg.python.org/distutils2/rev/3dda26cfc1d7
changeset: 1233:3dda26cfc1d7
user: Éric Araujo <merwok at netwok.org>
date: Fri Nov 11 23:36:39 2011 +0100
summary:
Increase test coverage for manifest (#11751).
One test fails on versions older than 2.6 because of a change in
fnmatch; we’re discussing how best to fix that on the bug tracker and
another commit will follow up.
files:
CHANGES.txt | 1 +
CONTRIBUTORS.txt | 1 +
distutils2/manifest.py | 4 +-
distutils2/tests/test_manifest.py | 201 +++++++++++++++++-
4 files changed, 199 insertions(+), 8 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -148,6 +148,7 @@
- #13170: Revert one of Jeremy's changes to config to fix a bug, kludge around
shlex not supporting unicode in 2.x, fix wrong shutil import [david, éric]
- #13205: Fix and improve generated setup scripts [david, éric]
+- #11751: Improve test coverage for manifest [justin]
1.0a3 - 2010-10-08
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -46,6 +46,7 @@
- Alain Leufroy
- Martin von Löwis
- Hugo Lopes Tavares
+- Justin Love
- Simon Mathieu
- Carl Meyer
- Alexis Métaireau
diff --git a/distutils2/manifest.py b/distutils2/manifest.py
--- a/distutils2/manifest.py
+++ b/distutils2/manifest.py
@@ -153,7 +153,9 @@
def _parse_template_line(self, line):
words = line.split()
- if len(words) == 1:
+ if len(words) == 1 and words[0] not in (
+ 'include', 'exclude', 'global-include', 'global-exclude',
+ 'recursive-include', 'recursive-exclude', 'graft', 'prune'):
# no action given, let's use the default 'include'
words.insert(0, 'include')
diff --git a/distutils2/tests/test_manifest.py b/distutils2/tests/test_manifest.py
--- a/distutils2/tests/test_manifest.py
+++ b/distutils2/tests/test_manifest.py
@@ -1,8 +1,10 @@
"""Tests for distutils2.manifest."""
import os
+import re
import logging
from StringIO import StringIO
-from distutils2.manifest import Manifest
+from distutils2.errors import PackagingTemplateError
+from distutils2.manifest import Manifest, _translate_pattern, _glob_to_re
from distutils2.tests import unittest, support
@@ -26,13 +28,11 @@
support.LoggingCatcher,
unittest.TestCase):
- def setUp(self):
- super(ManifestTestCase, self).setUp()
- self.cwd = os.getcwd()
+ def assertNoWarnings(self):
+ self.assertEqual(self.get_logs(logging.WARNING), [])
- def tearDown(self):
- os.chdir(self.cwd)
- super(ManifestTestCase, self).tearDown()
+ def assertWarnings(self):
+ self.assertGreater(len(self.get_logs(logging.WARNING)), 0)
def test_manifest_reader(self):
tmpdir = self.mkdtemp()
@@ -75,6 +75,193 @@
manifest.read_template(content)
self.assertEqual(['README', 'file1'], manifest.files)
+ def test_glob_to_re(self):
+ # simple cases
+ self.assertEqual(_glob_to_re('foo*'), 'foo[^/]*\\Z(?ms)')
+ self.assertEqual(_glob_to_re('foo?'), 'foo[^/]\\Z(?ms)')
+ self.assertEqual(_glob_to_re('foo??'), 'foo[^/][^/]\\Z(?ms)')
+
+ # special cases
+ self.assertEqual(_glob_to_re(r'foo\\*'), r'foo\\\\[^/]*\Z(?ms)')
+ self.assertEqual(_glob_to_re(r'foo\\\*'), r'foo\\\\\\[^/]*\Z(?ms)')
+ self.assertEqual(_glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)')
+ self.assertEqual(_glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)')
+
+ def test_remove_duplicates(self):
+ manifest = Manifest()
+ manifest.files = ['a', 'b', 'a', 'g', 'c', 'g']
+ # files must be sorted beforehand
+ manifest.sort()
+ manifest.remove_duplicates()
+ self.assertEqual(manifest.files, ['a', 'b', 'c', 'g'])
+
+ def test_translate_pattern(self):
+ # blackbox test of a private function
+
+ # not regex
+ pattern = _translate_pattern('a', anchor=True, is_regex=False)
+ self.assertTrue(hasattr(pattern, 'search'))
+
+ # is a regex
+ regex = re.compile('a')
+ pattern = _translate_pattern(regex, anchor=True, is_regex=True)
+ self.assertEqual(pattern, regex)
+
+ # plain string flagged as regex
+ pattern = _translate_pattern('a', anchor=True, is_regex=True)
+ self.assertTrue(hasattr(pattern, 'search'))
+
+ # glob support
+ pattern = _translate_pattern('*.py', anchor=True, is_regex=False)
+ self.assertTrue(pattern.search('filelist.py'))
+
+ def test_exclude_pattern(self):
+ # return False if no match
+ manifest = Manifest()
+ self.assertFalse(manifest.exclude_pattern('*.py'))
+
+ # return True if files match
+ manifest = Manifest()
+ manifest.files = ['a.py', 'b.py']
+ self.assertTrue(manifest.exclude_pattern('*.py'))
+
+ # test excludes
+ manifest = Manifest()
+ manifest.files = ['a.py', 'a.txt']
+ manifest.exclude_pattern('*.py')
+ self.assertEqual(manifest.files, ['a.txt'])
+
+ def test_include_pattern(self):
+ # return False if no match
+ manifest = Manifest()
+ manifest.allfiles = []
+ self.assertFalse(manifest._include_pattern('*.py'))
+
+ # return True if files match
+ manifest = Manifest()
+ manifest.allfiles = ['a.py', 'b.txt']
+ self.assertTrue(manifest._include_pattern('*.py'))
+
+ # test * matches all files
+ manifest = Manifest()
+ self.assertIsNone(manifest.allfiles)
+ manifest.allfiles = ['a.py', 'b.txt']
+ manifest._include_pattern('*')
+ self.assertEqual(manifest.allfiles, ['a.py', 'b.txt'])
+
+ def test_process_template(self):
+ # invalid lines
+ manifest = Manifest()
+ for action in ('include', 'exclude', 'global-include',
+ 'global-exclude', 'recursive-include',
+ 'recursive-exclude', 'graft', 'prune'):
+ self.assertRaises(PackagingTemplateError,
+ manifest._process_template_line, action)
+
+ # implicit include
+ manifest = Manifest()
+ manifest.allfiles = ['a.py', 'b.txt', 'd/c.py']
+
+ manifest._process_template_line('*.py')
+ self.assertEqual(manifest.files, ['a.py'])
+ self.assertNoWarnings()
+
+ # include
+ manifest = Manifest()
+ manifest.allfiles = ['a.py', 'b.txt', 'd/c.py']
+
+ manifest._process_template_line('include *.py')
+ self.assertEqual(manifest.files, ['a.py'])
+ self.assertNoWarnings()
+
+ manifest._process_template_line('include *.rb')
+ self.assertEqual(manifest.files, ['a.py'])
+ self.assertWarnings()
+
+ # exclude
+ manifest = Manifest()
+ manifest.files = ['a.py', 'b.txt', 'd/c.py']
+
+ manifest._process_template_line('exclude *.py')
+ self.assertEqual(manifest.files, ['b.txt', 'd/c.py'])
+ self.assertNoWarnings()
+
+ manifest._process_template_line('exclude *.rb')
+ self.assertEqual(manifest.files, ['b.txt', 'd/c.py'])
+ self.assertWarnings()
+
+ # global-include
+ manifest = Manifest()
+ manifest.allfiles = ['a.py', 'b.txt', 'd/c.py']
+
+ manifest._process_template_line('global-include *.py')
+ self.assertEqual(manifest.files, ['a.py', 'd/c.py'])
+ self.assertNoWarnings()
+
+ manifest._process_template_line('global-include *.rb')
+ self.assertEqual(manifest.files, ['a.py', 'd/c.py'])
+ self.assertWarnings()
+
+ # global-exclude
+ manifest = Manifest()
+ manifest.files = ['a.py', 'b.txt', 'd/c.py']
+
+ manifest._process_template_line('global-exclude *.py')
+ self.assertEqual(manifest.files, ['b.txt'])
+ self.assertNoWarnings()
+
+ manifest._process_template_line('global-exclude *.rb')
+ self.assertEqual(manifest.files, ['b.txt'])
+ self.assertWarnings()
+
+ # recursive-include
+ manifest = Manifest()
+ manifest.allfiles = ['a.py', 'd/b.py', 'd/c.txt', 'd/d/e.py']
+
+ manifest._process_template_line('recursive-include d *.py')
+ self.assertEqual(manifest.files, ['d/b.py', 'd/d/e.py'])
+ self.assertNoWarnings()
+
+ manifest._process_template_line('recursive-include e *.py')
+ self.assertEqual(manifest.files, ['d/b.py', 'd/d/e.py'])
+ self.assertWarnings()
+
+ # recursive-exclude
+ manifest = Manifest()
+ manifest.files = ['a.py', 'd/b.py', 'd/c.txt', 'd/d/e.py']
+
+ manifest._process_template_line('recursive-exclude d *.py')
+ self.assertEqual(manifest.files, ['a.py', 'd/c.txt'])
+ self.assertNoWarnings()
+
+ manifest._process_template_line('recursive-exclude e *.py')
+ self.assertEqual(manifest.files, ['a.py', 'd/c.txt'])
+ self.assertWarnings()
+
+ # graft
+ manifest = Manifest()
+ manifest.allfiles = ['a.py', 'd/b.py', 'd/d/e.py', 'f/f.py']
+
+ manifest._process_template_line('graft d')
+ self.assertEqual(manifest.files, ['d/b.py', 'd/d/e.py'])
+ self.assertNoWarnings()
+
+ manifest._process_template_line('graft e')
+ self.assertEqual(manifest.files, ['d/b.py', 'd/d/e.py'])
+ self.assertWarnings()
+
+ # prune
+ manifest = Manifest()
+ manifest.files = ['a.py', 'd/b.py', 'd/d/e.py', 'f/f.py']
+
+ manifest._process_template_line('prune d')
+ self.assertEqual(manifest.files, ['a.py', 'f/f.py'])
+ self.assertNoWarnings()
+
+ manifest._process_template_line('prune e')
+ self.assertEqual(manifest.files, ['a.py', 'f/f.py'])
+ self.assertWarnings()
+
def test_suite():
return unittest.makeSuite(ManifestTestCase)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list