def test_GetFilesInDirectory_leaf_files(tempdir: pathlib.Path): """Test that files in the directory are returned.""" # Start with one file. (tempdir / 'a').touch() assert set(dpack.GetFilesInDirectory(tempdir, [])) == {pathlib.Path('a')} # Add a second file. (tempdir / 'b').touch() assert set(dpack.GetFilesInDirectory(tempdir, [])) == { pathlib.Path('a'), pathlib.Path('b'), } # Add a third file. (tempdir / 'c').touch() assert set(dpack.GetFilesInDirectory(tempdir, [])) == { pathlib.Path('a'), pathlib.Path('b'), pathlib.Path('c'), }
def test_GetFilesInDirectory_subdir_relpath(tempdir: pathlib.Path): """Test that relative paths to files in a subdirectory are returned.""" # Create files: [ sub/a, sub/sub/b ] (tempdir / 'sub').mkdir() (tempdir / 'sub' / 'a').touch() (tempdir / 'sub' / 'sub').mkdir() (tempdir / 'sub' / 'sub' / 'b').touch() assert set(dpack.GetFilesInDirectory( tempdir, [])) == {pathlib.Path('sub/a'), pathlib.Path('sub/sub/b')}
def test_GetFilesInDirectory_exclude_subdir(tempdir: pathlib.Path): """Test that files in subdirs can be excluded.""" # Create files: [ a, foo, sub/foo ] (tempdir / 'a').touch() (tempdir / 'foo').touch() (tempdir / 'sub').mkdir() (tempdir / 'sub' / 'foo').touch() (tempdir / 'sub' / 'sub').mkdir() (tempdir / 'sub' / 'sub' / 'foo').touch() assert set(dpack.GetFilesInDirectory(tempdir, ['sub/foo'])) == { pathlib.Path('a'), pathlib.Path('foo'), pathlib.Path('sub/sub/foo') } assert set(dpack.GetFilesInDirectory( tempdir, ['*/foo'])) == {pathlib.Path('a'), pathlib.Path('foo')} assert set(dpack.GetFilesInDirectory( tempdir, ['*/foo*'])) == {pathlib.Path('a'), pathlib.Path('foo')}
def test_GetFilesInDirectory_exclude_by_name(tempdir: pathlib.Path): """Test that filenames which exactly match an exclude pattern are excluded.""" # Create files: [ a, foo, sub/foo ] (tempdir / 'a').touch() (tempdir / 'foo').touch() (tempdir / 'sub').mkdir() (tempdir / 'sub' / 'foo').touch() # Exclude pattern 'foo' does not exclude subdir 'foo'. assert set(dpack.GetFilesInDirectory( tempdir, ['foo'])) == {pathlib.Path('a'), pathlib.Path('sub/foo')}
def test_GetFilesInDirectory_exclude_subdir(tempdir: pathlib.Path): """Test that files in subdirs can be excluded.""" # Create files: [ a, foo, sub/foo ] (tempdir / "a").touch() (tempdir / "foo").touch() (tempdir / "sub").mkdir() (tempdir / "sub" / "foo").touch() (tempdir / "sub" / "sub").mkdir() (tempdir / "sub" / "sub" / "foo").touch() assert set(dpack.GetFilesInDirectory(tempdir, ["sub/foo"])) == { pathlib.Path("a"), pathlib.Path("foo"), pathlib.Path("sub/sub/foo"), } assert set(dpack.GetFilesInDirectory(tempdir, ["*/foo"])) == { pathlib.Path("a"), pathlib.Path("foo"), } assert set(dpack.GetFilesInDirectory(tempdir, ["*/foo*"])) == { pathlib.Path("a"), pathlib.Path("foo"), }
def GetAlbumDirectories(directory: pathlib.Path): """TODO.""" okay = True for subdir in fs.lsdirs(directory, recursive=True): subdir = pathlib.Path(subdir) depth = len(pathlib.Path(subdir).parts) if depth == 2: if FLAGS.update_musiclib_manifests: contents = dpack.GetFilesInDirectory(directory / subdir, [".*"]) dpack.InitManifest(directory / subdir, contents, update=True) else: if not dpack.VerifyManifest(directory / subdir): okay = False return okay
def test_GetFilesInDirectory_empty_dir(tempdir: pathlib.Path): """Test that an empty directory has no contents.""" assert not dpack.GetFilesInDirectory(tempdir, [])