def test_get_experiment_int_experiment_id_backcompat(self): fs = FileStore(self.test_root) exp_id = FileStore.DEFAULT_EXPERIMENT_ID root_dir = os.path.join(self.test_root, exp_id) with safe_edit_yaml(root_dir, "meta.yaml", self._experiment_id_edit_func): self._verify_experiment(fs, exp_id)
def test_yaml_read_and_write(tmpdir): temp_dir = str(tmpdir) yaml_file = random_file("yaml") long_value = long(1) if six.PY2 else 1 # pylint: disable=undefined-variable data = { "a": random_int(), "B": random_int(), "text_value": u"中文", "long_value": long_value, "int_value": 32, "text_value_2": u"hi" } file_utils.write_yaml(temp_dir, yaml_file, data) read_data = file_utils.read_yaml(temp_dir, yaml_file) assert data == read_data yaml_path = os.path.join(temp_dir, yaml_file) with codecs.open(yaml_path, encoding="utf-8") as handle: contents = handle.read() assert "!!python" not in contents # Check that UTF-8 strings are written properly to the file (rather than as ASCII # representations of their byte sequences). assert u"中文" in contents def edit_func(old_dict): old_dict["more_text"] = u"西班牙语" return old_dict assert "more_text" not in file_utils.read_yaml(temp_dir, yaml_file) with safe_edit_yaml(temp_dir, yaml_file, edit_func): editted_dict = file_utils.read_yaml(temp_dir, yaml_file) assert "more_text" in editted_dict assert editted_dict["more_text"] == u"西班牙语" assert "more_text" not in file_utils.read_yaml(temp_dir, yaml_file)
def test_get_run_int_experiment_id_backcompat(self): fs = FileStore(self.test_root) exp_id = FileStore.DEFAULT_EXPERIMENT_ID run_uuid = self.exp_data[exp_id]["runs"][0] root_dir = os.path.join(self.test_root, exp_id, run_uuid) with safe_edit_yaml(root_dir, "meta.yaml", self._experiment_id_edit_func): self._verify_run(fs, run_uuid)