示例#1
0
def test_cache_load_bad_dir_cache(tmp_dir, dvc):
    from dvc_data import load

    dir_hash = "123.dir"
    fname = os.fspath(dvc.odb.local.oid_to_path(dir_hash))
    tmp_dir.gen({fname: "<clearly>not,json"})
    with pytest.raises(ObjectFormatError):
        load(dvc.odb.local, HashInfo("md5", dir_hash))

    dir_hash = "234.dir"
    fname = os.fspath(dvc.odb.local.oid_to_path(dir_hash))
    tmp_dir.gen({fname: '{"a": "b"}'})
    with pytest.raises(ObjectFormatError):
        load(dvc.odb.local, HashInfo("md5", dir_hash))
示例#2
0
    def test(self):
        from dvc_data import load

        # NOTE: using 'copy' so that cache and link don't have same inode
        ret = main(["config", "cache.type", "copy"])
        self.assertEqual(ret, 0)

        self.dvc.config.load()

        stages = self.dvc.add(self.DATA_DIR)
        self.assertEqual(len(stages), 1)
        self.assertEqual(len(stages[0].outs), 1)
        out = stages[0].outs[0]

        # NOTE: modifying cache file for one of the files inside the directory
        # to check if dvc will detect that the cache is corrupted.
        obj = load(self.dvc.odb.local, out.hash_info)
        _, _, entry_oid = list(obj)[0]
        cache = self.dvc.odb.local.oid_to_path(entry_oid.value)

        os.chmod(cache, 0o644)
        with open(cache, "w+", encoding="utf-8") as fobj:
            fobj.write("1")

        with pytest.raises(CheckoutError):
            self.dvc.checkout(force=True)

        self.assertFalse(os.path.exists(cache))
示例#3
0
def test_add_directory(tmp_dir, dvc):
    from dvc_data import load

    (stage, ) = tmp_dir.dvc_gen({"dir": {"file": "file"}})

    assert stage is not None
    assert len(stage.deps) == 0
    assert len(stage.outs) == 1

    hash_info = stage.outs[0].hash_info

    obj = load(dvc.odb.local, hash_info)
    for key, _, _ in obj:
        for part in key:
            assert "\\" not in part