コード例 #1
0
    def test_fork_identical_new_trial(self):
        lineage = LineageNode(TrialStub(id="my-id", working_dir="same_folder"))
        with pytest.raises(
            RuntimeError, match="The new trial new-id has the same working directory"
        ):
            lineage.fork(TrialStub(id="new-id", working_dir="same_folder"))

        assert lineage.children == []
コード例 #2
0
    def test_register(self):
        item = [0]
        lineage = LineageNode(item)
        assert lineage.item == item
        assert lineage.item is not item

        item = [1]
        lineage.register(item)
        assert lineage.item == item
        assert lineage.item is not item
コード例 #3
0
    def test_set_jump(self):
        parent_lineage = LineageNode(1)
        child_lineage = LineageNode(2)
        parent_lineage.set_jump(child_lineage)

        assert child_lineage.parent is None
        assert child_lineage.jumps == []
        assert child_lineage.base is parent_lineage

        assert parent_lineage.children == []
        assert parent_lineage.jumps == [child_lineage]
        assert parent_lineage.base is None
コード例 #4
0
    def test_fork_to_existing_path(self, tmp_path):
        trial = TrialStub(id="stub", working_dir=os.path.join(tmp_path, "stub"))
        os.makedirs(trial.working_dir)
        lineage = LineageNode(trial)
        new_trial = TrialStub(id="fork", working_dir=os.path.join(tmp_path, "fork"))
        os.makedirs(new_trial.working_dir)

        with pytest.raises(
            FileExistsError, match="Folder already exists for trial fork."
        ):
            lineage.fork(new_trial)

        assert lineage.children == []
コード例 #5
0
    def test_fork(self, mocker):
        path = "/some_path"
        trial = TrialStub(path)
        lineage = LineageNode(trial)

        new_path = "/another_path"
        new_trial = TrialStub(new_path)

        mocker.patch("shutil.copytree")
        new_lineage = lineage.fork(new_trial)
        shutil.copytree.assert_called_once_with(path, new_path)

        assert new_lineage.item.working_dir == new_trial.working_dir
        assert new_lineage.parent is lineage
        assert lineage.children[0] is new_lineage
コード例 #6
0
 def test_get_true_ancestor_with_jump(self):
     lineage = LineageNode(1)
     child_lineage = LineageNode(2, parent=lineage)
     true_lineage = LineageNode(3)
     true_lineage.set_jump(child_lineage)
     assert child_lineage.parent is lineage
     assert child_lineage.base is true_lineage
     assert child_lineage.get_true_ancestor() is true_lineage
コード例 #7
0
    def test_set_jump_to_old_node(self):
        parent_lineage = LineageNode(1)
        child_lineage = LineageNode(2)
        parent_lineage.set_jump(child_lineage)

        another_child_lineage = LineageNode(3)

        with pytest.raises(RuntimeError, match="Trying to jump to an existing node"):
            another_child_lineage.set_jump(child_lineage)

        assert child_lineage.parent is None
        assert child_lineage.jumps == []
        assert child_lineage.base is parent_lineage

        assert another_child_lineage.parent is None
        assert another_child_lineage.jumps == []
        assert another_child_lineage.base is None

        assert parent_lineage.children == []
        assert parent_lineage.jumps == [child_lineage]
        assert parent_lineage.base is None
コード例 #8
0
    def test_set_jump_twice(self):
        parent_lineage = LineageNode(1)
        child_lineage = LineageNode(2)
        parent_lineage.set_jump(child_lineage)

        another_child_lineage = LineageNode(3)
        parent_lineage.set_jump(another_child_lineage)

        assert child_lineage.parent is None
        assert child_lineage.jumps == []
        assert child_lineage.base is parent_lineage

        assert another_child_lineage.parent is None
        assert another_child_lineage.jumps == []
        assert another_child_lineage.base is parent_lineage

        assert parent_lineage.children == []
        assert parent_lineage.jumps == [child_lineage, another_child_lineage]
        assert parent_lineage.base is None
コード例 #9
0
 def test_get_best_trial_non_completed_root(self):
     lineage = LineageNode(TrialStub(id="my-id"))
     assert lineage.get_best_trial() is None
コード例 #10
0
 def test_get_best_trial_empty(self):
     trial = TrialStub(id="id-1", objective=1)
     lineage = LineageNode(trial)
     assert lineage.get_best_trial().id == "id-1"
コード例 #11
0
 def test_get_true_ancestor_parent_no_jump(self):
     lineage = LineageNode(1)
     child_lineage = LineageNode(2, parent=lineage)
     assert child_lineage.get_true_ancestor() is lineage
コード例 #12
0
 def test_get_true_ancestor_no_parent(self):
     lineage = LineageNode(1)
     assert lineage.get_true_ancestor() is None