def test_get_files_symlinks(self):
        for pattern, expected in [('**/*.txt', [
                os.path.join('sub1', 'file1.txt'),
                os.path.join('sub2', 'file2.txt'),
                os.path.join('sub1', 'sub2', 'file2.txt')
        ]),
                                  ('./**/*.txt', [
                                      os.path.join('.', 'sub1', 'file1.txt'),
                                      os.path.join('.', 'sub2', 'file2.txt'),
                                      os.path.join('.', 'sub1', 'sub2',
                                                   'file2.txt')
                                  ]),
                                  ('*/*.txt', [
                                      os.path.join('sub1', 'file1.txt'),
                                      os.path.join('sub2', 'file2.txt')
                                  ])]:
            with self.subTest(pattern=pattern):
                with tempfile.TemporaryDirectory() as path:
                    filenames = [
                        os.path.join('sub1', 'file1.txt'),
                        os.path.join('sub2', 'file2.txt')
                    ]
                    with chdir(path):
                        os.mkdir('sub1')
                        os.mkdir('sub2')
                        for filename in filenames:
                            with open(filename, mode='w'):
                                pass
                        os.symlink(os.path.join(path, 'sub2'),
                                   os.path.join(path, 'sub1', 'sub2'),
                                   target_is_directory=True)

                        files = get_files(pattern)
                        self.assertEqual(sorted(expected), sorted(files))
    def test_get_files_include_and_exclude(self):
        filenames = ['file1.txt', 'file2.txt', 'file3.bin']
        with tempfile.TemporaryDirectory() as path:
            with chdir(path):
                for filename in filenames:
                    with open(filename, mode='w'):
                        pass

                files = get_files('*.txt\n!file1.txt')
                self.assertEqual(['file2.txt'], sorted(files))
    def test_get_files_character_range(self):
        filenames = ['file1.txt', 'file2.txt', 'file3.bin']
        with tempfile.TemporaryDirectory() as path:
            with chdir(path):
                for filename in filenames:
                    with open(filename, mode='w'):
                        pass

                files = get_files('file[0-2].*')
                self.assertEqual(['file1.txt', 'file2.txt'], sorted(files))
Exemplo n.º 4
0
    def test_get_files_absolute_path_and_wildcard(self):
        filenames = ['file1.txt', 'file2.txt', 'file3.bin']
        with tempfile.TemporaryDirectory() as path:
            with chdir(path):
                for filename in filenames:
                    with open(filename, mode='w'):
                        pass

                files = get_files(os.path.join(path, '*'))
                self.assertEqual([os.path.join(path, file) for file in filenames], sorted(files))
Exemplo n.º 5
0
    def test_get_files_multi_wildcard(self):
        for sep in ['\n', '\r\n', '\n\r', '\n\n', '\r\n\r\n']:
            with self.subTest(sep=sep):
                filenames = ['file1.txt', 'file2.txt', 'file3.bin']
                with tempfile.TemporaryDirectory() as path:
                    with chdir(path):
                        for filename in filenames:
                            with open(filename, mode='w'):
                                pass

                        files = get_files(f'*1.txt{sep}*3.bin')
                        self.assertEqual(['file1.txt', 'file3.bin'], sorted(files))
Exemplo n.º 6
0
    def test_get_files_single_wildcard(self):
        filenames = ['file1.txt', 'file2.txt', 'file3.bin']
        for wildcard in ['*.txt', 'file?.txt']:
            with self.subTest(wildcard=wildcard):
                with tempfile.TemporaryDirectory() as path:
                    with chdir(path):
                        for filename in filenames:
                            with open(filename, mode='w'):
                                pass

                        files = get_files(wildcard)
                        self.assertEqual(['file1.txt', 'file2.txt'], sorted(files))
Exemplo n.º 7
0
    def test_get_files_subdir_and_wildcard(self):
        filenames = [os.path.join('sub', 'file1.txt'),
                     os.path.join('sub', 'file2.txt'),
                     os.path.join('sub', 'file3.bin'),
                     os.path.join('sub2', 'file4.txt'),
                     'file5.txt']
        with tempfile.TemporaryDirectory() as path:
            with chdir(path):
                os.mkdir('sub')
                os.mkdir('sub2')
                for filename in filenames:
                    with open(filename, mode='w'):
                        pass

                files = get_files('sub/*.txt')
                self.assertEqual([os.path.join('sub', 'file1.txt'),
                                  os.path.join('sub', 'file2.txt')], sorted(files))
    def test_get_files_recursive_wildcard(self):
        for pattern, expected in [('**/*.txt', [
                'file6.txt',
                os.path.join('sub', 'file1.txt'),
                os.path.join('sub', 'file2.txt'),
                os.path.join('sub2', 'file4.txt'),
                os.path.join('sub2', 'sub3', 'sub4', 'file5.txt')
        ]),
                                  ('./**/*.txt', [
                                      os.path.join('.', 'file6.txt'),
                                      os.path.join('.', 'sub', 'file1.txt'),
                                      os.path.join('.', 'sub', 'file2.txt'),
                                      os.path.join('.', 'sub2', 'file4.txt'),
                                      os.path.join('.', 'sub2', 'sub3', 'sub4',
                                                   'file5.txt')
                                  ]),
                                  ('*/**/*.txt', [
                                      os.path.join('sub', 'file1.txt'),
                                      os.path.join('sub', 'file2.txt'),
                                      os.path.join('sub2', 'file4.txt'),
                                      os.path.join('sub2', 'sub3', 'sub4',
                                                   'file5.txt')
                                  ])]:
            with self.subTest(pattern=pattern):
                filenames = [
                    os.path.join('sub', 'file1.txt'),
                    os.path.join('sub', 'file2.txt'),
                    os.path.join('sub', 'file3.bin'),
                    os.path.join('sub2', 'file4.txt'),
                    os.path.join('sub2', 'sub3', 'sub4', 'file5.txt'),
                    'file6.txt'
                ]
                with tempfile.TemporaryDirectory() as path:
                    with chdir(path):
                        os.mkdir('sub')
                        os.mkdir('sub2')
                        os.mkdir(os.path.join('sub2', 'sub3'))
                        os.mkdir(os.path.join('sub2', 'sub3', 'sub4'))
                        for filename in filenames:
                            with open(filename, mode='w'):
                                pass

                        files = get_files(pattern)
                        self.assertEqual(sorted(expected), sorted(files))