~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Lib/test/test_fnmatch.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
 
9
9
class FnmatchTestCase(unittest.TestCase):
10
 
    def check_match(self, filename, pattern, should_match=1):
 
10
    def check_match(self, filename, pattern, should_match=1, fn=fnmatch):
11
11
        if should_match:
12
 
            self.assert_(fnmatch(filename, pattern),
13
 
                         "expected %r to match pattern %r"
14
 
                         % (filename, pattern))
 
12
            self.assertTrue(fn(filename, pattern),
 
13
                            "expected %r to match pattern %r"
 
14
                            % (filename, pattern))
15
15
        else:
16
 
            self.assert_(not fnmatch(filename, pattern),
17
 
                         "expected %r not to match pattern %r"
18
 
                         % (filename, pattern))
 
16
            self.assertTrue(not fn(filename, pattern),
 
17
                            "expected %r not to match pattern %r"
 
18
                            % (filename, pattern))
19
19
 
20
20
    def test_fnmatch(self):
21
21
        check = self.check_match
32
32
        check('a', 'b', 0)
33
33
 
34
34
        # these test that '\' is handled correctly in character sets;
35
 
        # see SF bug #???
 
35
        # see SF bug #409651
36
36
        check('\\', r'[\]')
37
37
        check('a', r'[!\]')
38
38
        check('\\', r'[!\]', 0)
39
39
 
 
40
        # test that filenames with newlines in them are handled correctly.
 
41
        # http://bugs.python.org/issue6665
 
42
        check('foo\nbar', 'foo*')
 
43
        check('foo\nbar\n', 'foo*')
 
44
        check('\nfoo', 'foo*', False)
 
45
        check('\n', '*')
 
46
 
 
47
    def test_fnmatchcase(self):
 
48
        check = self.check_match
 
49
        check('AbC', 'abc', 0, fnmatchcase)
 
50
        check('abc', 'AbC', 0, fnmatchcase)
 
51
 
40
52
 
41
53
def test_main():
42
54
    test_support.run_unittest(FnmatchTestCase)