def test_infer_versioning_metadata(): """Verify infer_versioning_metadata does nothing so far Test should be broken once the function is implemented """ metadata = {'hello': {'world': 0}} assert resolve_config.infer_versioning_metadata(metadata) == metadata
def test_infer_version_on_invalid_head(invalid_repo, caplog): """Test that repo is ignored if repo has an invalid HEAD state.""" with caplog.at_level(logging.WARNING): assert resolve_config.infer_versioning_metadata(".git") == {} assert "dummy_orion has an invalid HEAD." in caplog.text
def test_infer_versioning_metadata_on_clean_repo(repo): """ Test how `infer_versioning_metadata` fills its different fields when the user's repo is clean: `is_dirty`, `active_branch` and `diff_sha`. """ vcs = resolve_config.infer_versioning_metadata('.git') assert not vcs['is_dirty'] assert vcs['active_branch'] == 'master' # the diff should be empty so the diff_sha should be equal to the diff sha of an empty string assert vcs['diff_sha'] == hashlib.sha256(''.encode('utf-8')).hexdigest()
def test_infer_versioning_metadata_on_clean_repo(repo): """ Test how `infer_versioning_metadata` fills its different fields when the user's repo is clean: `is_dirty`, `active_branch` and `diff_sha`. """ vcs = resolve_config.infer_versioning_metadata(".git") assert not vcs["is_dirty"] assert vcs["active_branch"] == "master" # the diff should be empty so the diff_sha should be equal to the diff sha of an empty string assert vcs["diff_sha"] == hashlib.sha256("".encode("utf-8")).hexdigest()
def config(exp_config): """Return a configuration.""" config = exp_config[0][0] config["metadata"]["user_args"] = ["--x~uniform(-50, 50)"] config["metadata"]["VCS"] = resolve_config.infer_versioning_metadata( config["metadata"]["user_script"]) config["name"] = "exp" config["working_dir"] = "/tmp/orion" backward.populate_space(config) config["space"] = config["metadata"]["priors"] return config
def test_infer_versioning_metadata_on_detached_head(repo): """Test in the case of a detached head.""" with open('README.md', 'w+') as f: f.write('dummy contentt') repo.git.add('README.md') repo.index.commit('2nd commit') existing_metadata = {} existing_metadata['user_script'] = '.git' repo.head.reference = repo.commit('HEAD~1') assert repo.head.is_detached vcs = resolve_config.infer_versioning_metadata('.git') assert vcs['active_branch'] is None
def test_infer_versioning_metadata_on_detached_head(repo): """Test in the case of a detached head.""" with open("README.md", "w+") as f: f.write("dummy contentt") repo.git.add("README.md") repo.index.commit("2nd commit") existing_metadata = {} existing_metadata["user_script"] = ".git" repo.head.reference = repo.commit("HEAD~1") assert repo.head.is_detached vcs = resolve_config.infer_versioning_metadata(".git") assert vcs["active_branch"] is None
def test_infer_versioning_metadata_on_dirty_repo(repo): """ Test how `infer_versioning_metadata` fills its different fields when the uers's repo is dirty: `is_dirty`, `HEAD_sha`, `active_branch` and `diff_sha`. """ existing_metadata = {} existing_metadata['user_script'] = '.git' vcs = resolve_config.infer_versioning_metadata('.git') repo.create_head('feature') repo.git.checkout('feature') with open('README.md', 'w+') as f: f.write('dummy dummy content') vcs = resolve_config.infer_versioning_metadata('.git') assert vcs['is_dirty'] assert vcs['active_branch'] == 'feature' assert vcs['diff_sha'] != hashlib.sha256(''.encode('utf-8')).hexdigest() repo.git.add('README.md') commit = repo.index.commit('Added dummy_file') vcs = resolve_config.infer_versioning_metadata('.git') assert not vcs['is_dirty'] assert vcs['HEAD_sha'] == commit.hexsha assert vcs['diff_sha'] == hashlib.sha256(''.encode('utf-8')).hexdigest()
def test_infer_versioning_metadata_on_dirty_repo(repo): """ Test how `infer_versioning_metadata` fills its different fields when the uers's repo is dirty: `is_dirty`, `HEAD_sha`, `active_branch` and `diff_sha`. """ existing_metadata = {} existing_metadata["user_script"] = ".git" vcs = resolve_config.infer_versioning_metadata(".git") repo.create_head("feature") repo.git.checkout("feature") with open("README.md", "w+") as f: f.write("dummy dummy content") vcs = resolve_config.infer_versioning_metadata(".git") assert vcs["is_dirty"] assert vcs["active_branch"] == "feature" assert vcs["diff_sha"] != hashlib.sha256("".encode("utf-8")).hexdigest() repo.git.add("README.md") commit = repo.index.commit("Added dummy_file") vcs = resolve_config.infer_versioning_metadata(".git") assert not vcs["is_dirty"] assert vcs["HEAD_sha"] == commit.hexsha assert vcs["diff_sha"] == hashlib.sha256("".encode("utf-8")).hexdigest()
def _validate_code_version(self): if self.ignore_code_changes: return old_config = self.experiment.configuration new_config = copy.deepcopy(old_config) new_config["metadata"]["VCS"] = infer_versioning_metadata( old_config["metadata"]["user_script"]) # Circular import from orion.core.evc.conflicts import CodeConflict conflicts = list(CodeConflict.detect(old_config, new_config)) if conflicts: raise BranchingEvent( f"Code changed between execution of 2 trials:\n{conflicts[0]}")
def _validate_code_version(self): old_config = self.experiment.configuration new_config = copy.deepcopy(old_config) new_config["metadata"]["VCS"] = infer_versioning_metadata( old_config["metadata"]["user_script"] ) # Circular import from orion.core.evc.conflicts import CodeConflict conflicts = list(CodeConflict.detect(old_config, new_config)) if conflicts and not self.ignore_code_changes: raise BranchingEvent( f"Code changed between execution of 2 trials:\n{conflicts[0]}" ) elif conflicts: log.warning( "Code changed between execution of 2 trials. Enable EVC with option " "`ignore_code_changes` set to False to raise an error when trials are executed " "with different versions. For more information, see documentation at " "https://orion.readthedocs.io/en/stable/user/config.html#experiment-version-control" )