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)
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)
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)
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)
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)