diff --git a/grid2op/tests/aaa_test_backend_interface.py b/grid2op/tests/aaa_test_backend_interface.py index b45bd379..a3290a4c 100644 --- a/grid2op/tests/aaa_test_backend_interface.py +++ b/grid2op/tests/aaa_test_backend_interface.py @@ -814,7 +814,7 @@ def test_16_isolated_load_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=False) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated loads in AC." + # assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated loads in AC." assert res[1] is not None, "When your backend diverges, we expect it throws an exception (second return value)" error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" @@ -829,7 +829,7 @@ def test_16_isolated_load_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=True) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated loads in DC." + # assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated loads in DC." assert res[1] is not None, "When your backend diverges, we expect it throws an exception (second return value)" error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" @@ -862,7 +862,7 @@ def test_17_isolated_gen_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=False) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated gen." + # assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated gen." assert res[1] is not None, "When your backend diverges, we expect it throws an exception (second return value)" error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" @@ -877,7 +877,7 @@ def test_17_isolated_gen_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=True) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated gen." + # assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated gen." assert res[1] is not None, "When your backend diverges, we expect it throws an exception (second return value)" error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" @@ -916,7 +916,7 @@ def test_18_isolated_shunt_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=False) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated shunt." + # assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated shunt." assert res[1] is not None, "When your backend diverges, we expect it throws an exception (second return value)" error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" @@ -931,7 +931,7 @@ def test_18_isolated_shunt_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=True) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated shunt in DC." + # assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated shunt in DC." assert res[1] is not None, "When your backend stops, we expect it throws an exception (second return value)" error = res[1] assert isinstance(error, Grid2OpException), f"When your backend returns `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" @@ -967,7 +967,7 @@ def test_19_isolated_storage_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=False) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated storage units in AC." + # assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated storage units in AC." assert res[1] is not None, "When your backend stops, we expect it throws an exception (second return value)" error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" @@ -981,7 +981,7 @@ def test_19_isolated_storage_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=True) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated storage unit." + # assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of isolated storage unit." assert res[1] is not None, "When your backend stops, we expect it throws an exception (second return value)" error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" @@ -989,7 +989,8 @@ def test_19_isolated_storage_stops_computation(self): warnings.warn("The error returned by your backend when it stopped (due to isolated storage units) should preferably inherit from BackendError") def test_20_disconnected_load_stops_computation(self): - """Tests that a disconnected load unit will be spotted by the `run_pf` method and forwarded to grid2op by returining `False, an_exception` (in AC and DC) + """ + Tests that a disconnected load unit will be caught by the `_runpf_with_diverging_exception` method. This test supposes that : @@ -1003,7 +1004,7 @@ def test_20_disconnected_load_stops_computation(self): .. note:: Currently this stops the computation of the environment and lead to a game over. - This behaviour might change in the future. + Behaviour changed in version 1.11.0 (no longer caught by runpf() itelf) """ self.skip_if_needed() backend = self.aux_make_backend() @@ -1014,13 +1015,9 @@ def test_20_disconnected_load_stops_computation(self): bk_act = type(backend).my_bk_act_class() bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 - res = backend.runpf(is_dc=False) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of disconnected load in AC." - assert res[1] is not None, "When your backend stops, we expect it throws an exception (second return value)" - error = res[1] - assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" - if not isinstance(error, BackendError): - warnings.warn("The error returned by your backend when it stopped (due to disconnected load) should preferably inherit from BackendError") + error = backend._runpf_with_diverging_exception(is_dc=False) + assert error is not None + assert isinstance(error, Grid2OpException) backend.reset(self.get_path(), self.get_casefile()) # a load alone on a bus @@ -1029,16 +1026,13 @@ def test_20_disconnected_load_stops_computation(self): bk_act = type(backend).my_bk_act_class() bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 - res = backend.runpf(is_dc=True) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of disconnected load in DC." - assert res[1] is not None, "When your backend stops, we expect it throws an exception (second return value)" - error = res[1] - assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" - if not isinstance(error, BackendError): - warnings.warn("The error returned by your backend when it stopped (due to disconnected load) should preferably inherit from BackendError") - + error = backend._runpf_with_diverging_exception(is_dc=True) + assert error is not None + assert isinstance(error, Grid2OpException) + def test_21_disconnected_gen_stops_computation(self): - """Tests that a disconnected generator will be spotted by the `run_pf` method and forwarded to grid2op by returining `False, an_exception` (in AC and DC) + """ + Tests that a disconnected generator will be caught by the `_runpf_with_diverging_exception` method This test supposes that : @@ -1052,7 +1046,7 @@ def test_21_disconnected_gen_stops_computation(self): .. note:: Currently this stops the computation of the environment and lead to a game over. - This behaviour might change in the future. + Behaviour changed in version 1.11.0 (no longer caught by runpf() itelf) """ self.skip_if_needed() backend = self.aux_make_backend() @@ -1063,13 +1057,9 @@ def test_21_disconnected_gen_stops_computation(self): bk_act = type(backend).my_bk_act_class() bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 - res = backend.runpf(is_dc=False) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of disconnected gen in AC." - assert res[1] is not None, "When your backend stops, we expect it throws an exception (second return value)" - error = res[1] - assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" - if not isinstance(error, BackendError): - warnings.warn("The error returned by your backend when it stopped (due to disconnected gen) should preferably inherit from BackendError") + error = backend._runpf_with_diverging_exception(is_dc=False) + assert error is not None + assert isinstance(error, Grid2OpException) backend.reset(self.get_path(), self.get_casefile()) # a disconnected generator @@ -1078,14 +1068,10 @@ def test_21_disconnected_gen_stops_computation(self): bk_act = type(backend).my_bk_act_class() bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 - res = backend.runpf(is_dc=True) - assert not res[0], "It is expected (at time of writing) that your backend returns `False` in case of disconnected gen in DC." - assert res[1] is not None, "When your backend stops, we expect it throws an exception (second return value)" - error = res[1] - assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" - if not isinstance(error, BackendError): - warnings.warn("The error returned by your backend when it stopped (due to disconnected gen) should preferably inherit from BackendError") - + res = backend._runpf_with_diverging_exception(is_dc=True) + assert error is not None + assert isinstance(error, Grid2OpException) + def test_22_islanded_grid_stops_computation(self): """Tests that when the grid is split in two different "sub_grid" is spotted by the `run_pf` method and forwarded to grid2op by returining `False, an_exception` (in AC and DC) @@ -1117,7 +1103,7 @@ def test_22_islanded_grid_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=False) - assert not res[0], f"It is expected that your backend return `(False, _)` in case of non connected grid in AC." + # assert not res[0], f"It is expected that your backend return `(False, _)` in case of non connected grid in AC." error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" if not isinstance(error, BackendError): @@ -1133,7 +1119,7 @@ def test_22_islanded_grid_stops_computation(self): bk_act += action backend.apply_action(bk_act) # mix of bus 1 and 2 on substation 1 res = backend.runpf(is_dc=True) - assert not res[0], f"It is expected that your backend return `(False, _)` in case of non connected grid in DC." + # assert not res[0], f"It is expected that your backend return `(False, _)` in case of non connected grid in DC." error = res[1] assert isinstance(error, Grid2OpException), f"When your backend return `False`, we expect it throws an exception inheriting from Grid2OpException (second return value), backend returned {type(error)}" if not isinstance(error, BackendError): diff --git a/grid2op/tests/test_alert_gym_compat.py b/grid2op/tests/test_alert_gym_compat.py index e522deee..04895e37 100644 --- a/grid2op/tests/test_alert_gym_compat.py +++ b/grid2op/tests/test_alert_gym_compat.py @@ -120,6 +120,7 @@ def test_print_alert(self): act.raise_alert = [2] act_gym = env_gym.action_space.to_gym(act) act_str = act_gym.__str__() + assert act_str == ("OrderedDict([('change_bus', array([False, False, False, False, False, False, False, False, False," "\n False, False, False, False, False, False, False, False, False,\n " "False, False, False, False, False, False, False, False, False,\n False, False, False, "