OLD | NEW |
(Empty) | |
| 1 #! /usr/bin/env python |
| 2 # |
| 3 # Copyright 2009 Google Inc. All Rights Reserved. |
| 4 # |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 # you may not use this file except in compliance with the License. |
| 7 # You may obtain a copy of the License at |
| 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # |
| 11 # Unless required by applicable law or agreed to in writing, software |
| 12 # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 # See the License for the specific language governing permissions and |
| 15 # limitations under the License. |
| 16 |
| 17 """Test for fake_filesystem_glob.""" |
| 18 |
| 19 import doctest |
| 20 import sys |
| 21 if sys.version_info < (2, 7): |
| 22 import unittest2 as unittest |
| 23 else: |
| 24 import unittest |
| 25 |
| 26 import fake_filesystem |
| 27 import fake_filesystem_glob |
| 28 |
| 29 |
| 30 class FakeGlobUnitTest(unittest.TestCase): |
| 31 |
| 32 def setUp(self): |
| 33 self.filesystem = fake_filesystem.FakeFilesystem(path_separator='/') |
| 34 self.glob = fake_filesystem_glob.FakeGlobModule(self.filesystem) |
| 35 directory = './xyzzy' |
| 36 self.filesystem.CreateDirectory(directory) |
| 37 self.filesystem.CreateDirectory('%s/subdir' % directory) |
| 38 self.filesystem.CreateDirectory('%s/subdir2' % directory) |
| 39 self.filesystem.CreateFile('%s/subfile' % directory) |
| 40 self.filesystem.CreateFile('[Temp]') |
| 41 |
| 42 def testGlobEmpty(self): |
| 43 self.assertEqual(self.glob.glob(''), []) |
| 44 |
| 45 def testGlobStar(self): |
| 46 self.assertEqual(['/xyzzy/subdir', '/xyzzy/subdir2', '/xyzzy/subfile'], |
| 47 self.glob.glob('/xyzzy/*')) |
| 48 |
| 49 def testGlobExact(self): |
| 50 self.assertEqual(['/xyzzy'], self.glob.glob('/xyzzy')) |
| 51 self.assertEqual(['/xyzzy/subfile'], self.glob.glob('/xyzzy/subfile')) |
| 52 |
| 53 def testGlobQuestion(self): |
| 54 self.assertEqual(['/xyzzy/subdir', '/xyzzy/subdir2', '/xyzzy/subfile'], |
| 55 self.glob.glob('/x?zz?/*')) |
| 56 |
| 57 def testGlobNoMagic(self): |
| 58 self.assertEqual(['/xyzzy'], self.glob.glob('/xyzzy')) |
| 59 self.assertEqual(['/xyzzy/subdir'], self.glob.glob('/xyzzy/subdir')) |
| 60 |
| 61 def testNonExistentPath(self): |
| 62 self.assertEqual([], self.glob.glob('nonexistent')) |
| 63 |
| 64 def testDocTest(self): |
| 65 self.assertFalse(doctest.testmod(fake_filesystem_glob)[0]) |
| 66 |
| 67 def testMagicDir(self): |
| 68 self.assertEqual(['/[Temp]'], self.glob.glob('/*emp*')) |
| 69 |
| 70 def testRootGlob(self): |
| 71 self.assertEqual(['[Temp]', 'xyzzy'], self.glob.glob('*')) |
| 72 |
| 73 def testGlob1(self): |
| 74 self.assertEqual(['[Temp]'], self.glob.glob1('/', '*Tem*')) |
| 75 |
| 76 def testHasMagic(self): |
| 77 self.assertTrue(self.glob.has_magic('[')) |
| 78 self.assertFalse(self.glob.has_magic('a')) |
| 79 |
| 80 |
| 81 if __name__ == '__main__': |
| 82 unittest.main() |
OLD | NEW |