Пример #1
0
def test_transfer_files(tmpdir):
    test_string = "test"
    tmp_from = tmpdir
    os.chdir(tmp_from)
    for i in ["file1", "file2", "file3", "file4"]:
        with open(i, "w") as f1:
            print(test_string, end="", file=f1)
    file_transfers = FileTransfers(
        {
            "file1": "m",
            "file2": "c",
            "file3": "l",
            "file4": "m"
        },
        path=Path(tmp_from))

    tmp_to = tmp_from.mkdir("tmp_to")
    file_transfers.transfer(Path(tmp_to))
    # Test copied and linked files
    for i in ["file2", "file3"]:
        with open(Path(tmp_to) / i, 'r') as f_to:
            with open(Path(tmp_from) / i, 'r') as f_from:
                assert f_to.read() == f_from.read()

    # Test moved files
    for i in ["file1", "file4"]:
        with open(Path(tmp_to) / i, 'r') as f2:
            assert f2.read() == test_string
Пример #2
0
def test_transfer_delete(tmpdir):
    tmp_from = tmpdir
    for i in ["a", "bbb", "cbb", "bd", "bda"]:
        tmp_from.join(i).write("test")
    file_transfers = FileTransfers(
        {
            "a": "m",
            "bbb": "c",
            "cbb": "l",
            "bd": "m",
            "bda": "m"
        },
        path=Path(tmp_from))
    file_transfers.delete_file_transfers(["bb", "a"])
    assert len(file_transfers.file_transfers) == 1
Пример #3
0
def test_transfer_files_logger_empty(tmpdir, mocker):
    mock = mocker.patch("vise.util.file_transfer.logger.warning")
    empty_filename = "empty_file"
    tmp_from = tmpdir
    tmp_from.join(empty_filename).write("")
    FileTransfers({empty_filename: "m"}, path=Path(tmp_from))
    mock.assert_called_once_with(
        f"{Path(tmp_from) / empty_filename} is empty.")
Пример #4
0
def test_transfer_files_logger_non_exist(tmpdir, mocker):
    mock = mocker.patch("vise.util.file_transfer.logger.warning")
    non_exist_filename = "non_exist_file"
    tmp_from = tmpdir
    os.chdir(tmp_from)
    FileTransfers({non_exist_filename: "m"}, path=Path(tmp_from))
    mock.assert_called_once_with(
        f"{Path(tmp_from) / non_exist_filename} does not exist.")
Пример #5
0
    def _option_kwargs(self):
        result = deepcopy(defaults.options)
        if self._prior_info:
            result.update(self._prior_info.input_options_kwargs)

        if self.args.prev_dir:
            pi = prior_info_from_calc_dir(prev_dir_path=self.args.prev_dir,
                                          vasprun=self.args.vasprun,
                                          outcar=self.args.outcar)
            result.update(pi.input_options_kwargs)

            self._file_transfers = FileTransfers(self._file_transfer(),
                                                 path=self.args.prev_dir)

        if self.args.options:
            args = list2dict(self.args.options, assignable_option_set)
            result.update(args)
        if self.args.uniform_kpt_mode:
            result["kpt_mode"] = KpointsMode.uniform

        return result
Пример #6
0
def test_raise_error_for_incorrect_transfer_type(tmpdir):
    tmp_from = tmpdir
    os.chdir(tmp_from)
    tmp_from.join("filename").write("test")
    with pytest.raises(ViseFileTransferError):
        FileTransfers({"filename": "x"}, path=Path(tmp_from))