Esempio n. 1
0
def test_subdirs(tempdirs):
    # Try to fool the algorithm by adding normal files
    prefix_name = str(tempdirs)
    open(os.path.join(prefix_name, 'foo', 'bar', 'file.txt'), 'w').close()
    open(os.path.join(prefix_name, 'loo', 'file.txt'), 'w').close()

    expected_subdirs = {
        prefix_name,
        os.path.join(prefix_name, 'foo'),
        os.path.join(prefix_name, 'foo', 'bar'),
        os.path.join(prefix_name, 'foo', 'bar', 'boo'),
        os.path.join(prefix_name, 'foo', 'goo'),
        os.path.join(prefix_name, 'loo'),
        os.path.join(prefix_name, 'loo', 'bar')
    }

    returned_subdirs = os_ext.subdirs(prefix_name)
    assert [prefix_name] == returned_subdirs

    returned_subdirs = os_ext.subdirs(prefix_name, recurse=True)
    assert expected_subdirs == set(returned_subdirs)
Esempio n. 2
0
    def test_subdirs(self):
        prefix = tempfile.mkdtemp()
        self._make_testdirs(prefix)

        # Try to fool the algorithm by adding normal files
        open(os.path.join(prefix, 'foo', 'bar', 'file.txt'), 'w').close()
        open(os.path.join(prefix, 'loo', 'file.txt'), 'w').close()

        expected_subdirs = {prefix,
                            os.path.join(prefix, 'foo'),
                            os.path.join(prefix, 'foo', 'bar'),
                            os.path.join(prefix, 'foo', 'bar', 'boo'),
                            os.path.join(prefix, 'foo', 'goo'),
                            os.path.join(prefix, 'loo'),
                            os.path.join(prefix, 'loo', 'bar')}

        returned_subdirs = os_ext.subdirs(prefix)
        self.assertEqual([prefix], returned_subdirs)

        returned_subdirs = os_ext.subdirs(prefix, recurse=True)
        self.assertEqual(expected_subdirs, set(returned_subdirs))
        shutil.rmtree(prefix)