示例#1
0
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'),
    }
示例#2
0
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')}
示例#3
0
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')}
示例#4
0
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')}
示例#5
0
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"),
    }
示例#6
0
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
示例#7
0
def test_GetFilesInDirectory_empty_dir(tempdir: pathlib.Path):
    """Test that an empty directory has no contents."""
    assert not dpack.GetFilesInDirectory(tempdir, [])