Skip to content

Commit

Permalink
Merge pull request #544 from AntaresSimulatorTeam/release/Fix_boolean…
Browse files Browse the repository at this point in the history
…_case

Fix issue with mishandling boolean represented as string
  • Loading branch information
JasonMarechal25 authored Oct 4, 2022
2 parents 3c009a4 + 7fd7861 commit 4144b34
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/python/antares_xpansion/general_data_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def change_general_data_file_to_configure_antares_execution(self):

def backport_playlist(self, ini_file_backup, writer, playlist_options: dict):
ini_reader = GeneralDataIniReader(ini_file_backup)
ini_reader.get_active_years()
active_years = ini_reader.get_raw_active_years()
inactive_years = ini_reader.get_raw_inactive_years()
active_years, inactive_years = ini_reader.get_raw_playlist()
writer.write("[playlist]\n")
for option in playlist_options:
if option != "playlist_year +" and option != "playlist_year -":
Expand Down
26 changes: 16 additions & 10 deletions src/python/antares_xpansion/general_data_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, file_path: Path = None):
self.file_lines = open(file_path, 'r').readlines()

self._mc_years: int = int(self.config["general"]["nbyears"])
self._user_playlist = str(self.config["general"]["user-playlist"])
self._user_playlist = self.config.getboolean("general", "user-playlist")
self._playlist_reset_option: bool = True
self._active_year_list: List[int] = []
self._inactive_year_list: List[int] = []
Expand All @@ -44,19 +44,27 @@ def get_nb_years(self) -> int:
return self._mc_years

def get_active_years(self):

if self._user_playlist == "true":
self._active_year_list = []
self._inactive_year_list = []
if self._user_playlist:
self._set_playlist_reset_option()
self._set_playlist_year_lists()
return self._get_active_years()
else:
return list(range(1, self._mc_years + 1))

def get_raw_active_years(self):
return self._active_year_list

def get_raw_inactive_years(self):
return self._inactive_year_list
def get_raw_playlist(self):
current_section = ""
self._active_year_list = []
self._inactive_year_list = []
for line in self.file_lines:
if IniReader.line_is_not_a_section_header(line):
if current_section == 'playlist':
key, val = IniReader.get_key_val_from_line(line)
self._read_playlist_val(key, val)
else:
current_section = IniReader.read_section_header(line)
return self._active_year_list, self._inactive_year_list

def _get_active_years(self):
if self._playlist_reset_option is True:
Expand All @@ -83,8 +91,6 @@ def _set_playlist_reset_option(self):
self._playlist_reset_option = self.config.getboolean('playlist', 'playlist_reset', fallback=True)

def _set_playlist_year_lists(self):
self._active_year_list = []
self._inactive_year_list = []
current_section = ""
for line in self.file_lines:
current_section = self._read_playlist(current_section, line.strip())
Expand Down
3 changes: 1 addition & 2 deletions tests/python/test_antares_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def test_preserve_playlist(self, tmp_path):
xpansion_ini_reader.get_active_years()
config_reader = configparser.ConfigParser(strict=False)
config_reader.read(gen_data_path)
active_years = xpansion_ini_reader.get_raw_active_years()
inactive_years = xpansion_ini_reader.get_raw_inactive_years()
active_years, inactive_years = xpansion_ini_reader.get_raw_playlist()
assert config_reader.get("playlist", "dummy_entry") == "value"
assert active_years == [1, 42]
assert inactive_years == [5, 0]
Expand Down

0 comments on commit 4144b34

Please sign in to comment.