def test_replicateignore(temp_bucket, tmpdir): repository = GCSRepository(bucket=temp_bucket.name, root="") for path in [ "foo.txt", "bar/baz.txt", "bar/quux.xyz", "bar/new-qux.txt", "qux.xyz", ]: abs_path = os.path.join(tmpdir, path) os.makedirs(os.path.dirname(abs_path), exist_ok=True) with open(abs_path, "w") as f: f.write("hello " + path) with open(os.path.join(tmpdir, ".replicateignore"), "w") as f: f.write(""" # this is a comment baz.txt *.xyz """) repository.put_path(tmpdir, "folder") assert temp_bucket.blob( "folder/foo.txt").download_as_bytes() == b"hello foo.txt" assert (temp_bucket.blob("folder/bar/new-qux.txt").download_as_bytes() == b"hello bar/new-qux.txt") with pytest.raises(NotFound): temp_bucket.blob("folder/bar/baz.txt").download_as_bytes() with pytest.raises(NotFound): temp_bucket.blob("folder/qux.xyz").download_as_bytes() with pytest.raises(NotFound): temp_bucket.blob("folder/bar/quux.xyz").download_as_bytes()
def test_put_path_with_root(temp_bucket, tmpdir): repository = GCSRepository(bucket=temp_bucket.name, root="someroot") for path in ["foo.txt", "bar/baz.txt", "qux.txt"]: abs_path = os.path.join(tmpdir, path) os.makedirs(os.path.dirname(abs_path), exist_ok=True) with open(abs_path, "w") as f: f.write("hello " + path) repository.put_path(tmpdir, "folder") assert (temp_bucket.blob("someroot/folder/foo.txt").download_as_bytes() == b"hello foo.txt") assert (temp_bucket.blob("someroot/folder/qux.txt").download_as_bytes() == b"hello qux.txt") assert (temp_bucket.blob("someroot/folder/bar/baz.txt").download_as_bytes( ) == b"hello bar/baz.txt") # single files repository.put_path(os.path.join(tmpdir, "foo.txt"), "singlefile/foo.txt") assert (temp_bucket.blob( "someroot/singlefile/foo.txt").download_as_bytes() == b"hello foo.txt")