示例#1
0
def test_DataPackageFileAttributesAreValid_unknown_checksum_hash(
        tempdir: pathlib.Path):
    """If no checksum hash is declared, attributes are not valid."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    (tempdir / 'a').touch()
    assert not dpack.DataPackageFileAttributesAreValid(tempdir, df)
示例#2
0
def test_DataPackageFileAttributesAreValid_match(tempdir: pathlib.Path):
    """Test that file attributes can be correct."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    df.checksum_hash = dpack_pb2.SHA256
    df.checksum = SHA256_EMPTY_FILE
    (tempdir / 'a').touch()
    assert dpack.DataPackageFileAttributesAreValid(tempdir, df)
示例#3
0
def test_DataPackageFileAttributesAreValid_different_checksum(
        tempdir: pathlib.Path):
    """If checksum of file differs, attributes are not valid."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    df.checksum_hash = dpack_pb2.SHA256
    (tempdir / 'a').touch()
    assert not dpack.DataPackageFileAttributesAreValid(tempdir, df)
示例#4
0
def test_DataPackageFileAttributesAreValid_different_size(
        tempdir: pathlib.Path):
    """If the size of a file is incorect, attributes are not valid."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    df.checksum_hash = dpack_pb2.SHA256
    df.checksum = SHA256_EMPTY_FILE
    df.size_in_bytes = 10  # An empty file has size 0
    (tempdir / 'a').touch()
    assert not dpack.DataPackageFileAttributesAreValid(tempdir, df)
示例#5
0
def test_DataPackageFileAttributesAreValid_missing_file(tempdir: pathlib.Path):
    """If a file does not exist, attributes are not valid."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    assert not dpack.DataPackageFileAttributesAreValid(tempdir, df)