def test_set_reward_signal_nan_inf(self, float_case: float) -> None: """Test (not) keeping the reward signal for nan/inf.""" predictor = TemporalDifference() state = State() state.add_resolved_dependency( ("tensorflow", "2.3.0", "https://pypi.org/simple")) state.add_resolved_dependency( ("flask", "0.12", "https://pypi.org/simple")) state.add_unresolved_dependency( ("termial-random", "0.0.2", "https://pypi.org/simple")) predictor._policy = { ("flask", "0.12", "https://pypi.org/simple"): [0.2, 1], } predictor._steps_taken = 2 predictor._steps_reward = 1.2 predictor._next_state = state assert (predictor.set_reward_signal( state, ("tensorflow", "2.0.0", "https://pypi.org/simple"), float_case) is None) assert predictor._policy == { ("flask", "0.12", "https://pypi.org/simple"): [1.4, 2], ("tensorflow", "2.3.0", "https://pypi.org/simple"): [1.2, 1], } assert predictor._steps_taken == 0 assert predictor._steps_reward == 0.0 assert predictor._next_state is None
def test_pre_run(self) -> None: """Test initialization done before running.""" predictor = TemporalDifference() predictor._policy = {("tensorflow", "2.0.0", "https://pypi.org/simple"): [1.0, 2]} predictor._temperature_history = [(0.212, True, 0.23, 100)] predictor._temperature = 12.3 context = flexmock(limit=42) with predictor.assigned_context(context): predictor.pre_run() assert predictor._policy == {} assert predictor._temperature_history == [] assert isinstance(predictor._temperature, float) assert predictor._temperature == float(context.limit)
def test_set_reward_signal_unseen(self) -> None: """Test keeping the reward signal for an unseen step.""" reward = 42.24 package_tuple = ("tensorflow", "2.0.0", "https://thoth-station.ninja") state = flexmock() state.should_receive("iter_resolved_dependencies").and_return([package_tuple]).once() predictor = TemporalDifference() predictor._policy = { ("numpy", "1.0.0", "https://pypi.org/simple"): [30.30, 92], } predictor._steps_taken = 1 predictor.set_reward_signal(state, None, reward) assert predictor._policy == { package_tuple: [42.24, 1], ("numpy", "1.0.0", "https://pypi.org/simple"): [30.30, 92], }
def test_do_exploitation(self) -> None: """Tests on exploitation computation.""" predictor = TemporalDifference() predictor._policy = { ("tensorflow", "2.1.0", "https://thoth-station.ninja"): [2020.21, 666], ("tensorflow", "2.0.0", "https://thoth-station.ninja"): [16.61, 1992], ("numpy", "1.0.0", "https://pypi.org/simple"): [30.30, 92], } state = flexmock() state.should_receive("iter_unresolved_dependencies").and_return([ ("spacy", "2.2.4", "https://pypi.org/simple"), ("numpy", "1.0.0", "https://pypi.org/simple"), ("tensorflow", "2.1.0", "https://thoth-station.ninja"), ]).once() state.should_receive("get_random_unresolved_dependency").times(0) assert predictor._do_exploitation(state) == ( "tensorflow", "2.1.0", "https://thoth-station.ninja", )