Skip to content

Commit

Permalink
fixing broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Jan 18, 2022
1 parent 001963e commit 97a6294
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions grid2op/Space/SerializableSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,28 @@ def from_dict(dict_):
if actionClass_li[-1] in globals():
subtype = globals()[actionClass_li[-1]]
else:
try:
exec("from {} import {}".format(".".join(actionClass_li[:-1]), actionClass_li[-1]))
except ModuleNotFoundError as exc_:
# prior to grid2op 1.6.5 the Observation module was grid2op.Observation.completeObservation.CompleteObservation
# after its grid2op.Observation.completeObservation.CompleteObservation
# so I try here to make the python file lower case in order to import
# the class correctly
if len(actionClass_li) > 2:
test_str = actionClass_li[2]
actionClass_li[2] = test_str[0].lower() + test_str[1:]
exec("from {} import {}".format(".".join(actionClass_li[:-1]), actionClass_li[-1]))
else:
raise exc_

# TODO make something better and recursive here
exec("from {} import {}".format(".".join(actionClass_li[:-1]), actionClass_li[-1]))
try:
subtype = eval(actionClass_li[-1])
except NameError:
if len(actionClass_li) > 1:
try:
subtype = eval(".".join(actionClass_li[1:]))
except:
except Exception as exc_:
msg_err_ = "Impossible to find the module \"{}\" to load back the space (ERROR 1). " \
"Try \"from {} import {}\""
raise Grid2OpException(msg_err_.format(actionClass_str, ".".join(actionClass_li[:-1]),
Expand All @@ -192,7 +205,7 @@ def from_dict(dict_):
except AttributeError:
try:
subtype = eval(actionClass_li[-1])
except:
except Exception as exc_:
if len(actionClass_li) > 1:
msg_err_ = "Impossible to find the class named \"{}\" to load back the space (ERROR 3)" \
"(module is found but not the class in it) Please import it via " \
Expand Down
2 changes: 1 addition & 1 deletion grid2op/tests/test_Observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def setUp(self):
"storage_loss": [],
'storage_charging_efficiency': [],
'storage_discharging_efficiency': [],
'_init_subtype': 'grid2op.Observation.CompleteObservation.CompleteObservation',
'_init_subtype': 'grid2op.Observation.completeObservation.CompleteObservation',
"dim_alarms": 0,
"alarms_area_names": [],
"alarms_lines_area": {},
Expand Down

0 comments on commit 97a6294

Please sign in to comment.