Skip to content

Commit

Permalink
Merge branch 'main' into config-update-1
Browse files Browse the repository at this point in the history
  • Loading branch information
prakaa authored Aug 22, 2024
2 parents a390b4a + b316127 commit 1ef6f9f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
10 changes: 7 additions & 3 deletions src/isp_workbook_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _check_for_missed_column_on_right_hand_side_of_table(
data = pd.read_excel(
self.file,
sheet_name=sheet_name,
header=start_row,
header=start_row - 1,
usecols=column_next_to_last_column,
nrows=(end_row - start_row),
)
Expand Down Expand Up @@ -233,11 +233,15 @@ def _check_for_missed_column_on_left_hand_side_of_table(
data = pd.read_excel(
self.file,
sheet_name=sheet_name,
header=start_row,
header=start_row - 1,
usecols=column_next_to_first_column,
nrows=(end_row - start_row),
)
if not data[data.columns[0]].isna().all():
if data[data.columns[0]].isna().all():
range_error = False
elif "DO NOT DELETE THIS COLUMN" in data.columns[0]:
range_error = False
else:
range_error = True
except pd.errors.ParserError:
range_error = False
Expand Down
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest

from isp_workbook_parser import Parser


@pytest.fixture(scope="session")
def workbook_v6() -> Parser:
workbook = Parser("workbooks/6.0/2024-isp-inputs-and-assumptions-workbook.xlsx")
return workbook
27 changes: 12 additions & 15 deletions tests/test_config_validation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import pytest

from isp_workbook_parser import Parser
from isp_workbook_parser.parser import TableConfigError
from isp_workbook_parser.config_model import TableConfig

workbook = Parser("workbooks/6.0/2024-isp-inputs-and-assumptions-workbook.xlsx")


def test_end_row_runs_into_another_table_throws_error():
def test_end_row_runs_into_another_table_throws_error(workbook_v6):
table_config = TableConfig(
name="DUMMY",
sheet_name="Aggregated energy storages",
Expand All @@ -20,10 +17,10 @@ def test_end_row_runs_into_another_table_throws_error():
"incorrectly specified."
)
with pytest.raises(TableConfigError, match=error_message):
workbook.get_table_from_config(table_config)
workbook_v6.get_table_from_config(table_config)


def test_end_row_runs_into_notes_throws_error():
def test_end_row_runs_into_notes_throws_error(workbook_v6):
table_config = TableConfig(
name="DUMMY",
sheet_name="Network Capability",
Expand All @@ -35,10 +32,10 @@ def test_end_row_runs_into_notes_throws_error():
"The first column of the table DUMMY contains the sub string 'Notes:'."
)
with pytest.raises(TableConfigError, match=error_message):
workbook.get_table_from_config(table_config)
workbook_v6.get_table_from_config(table_config)


def test_end_row_too_soon_throws_error():
def test_end_row_too_soon_throws_error(workbook_v6):
table_config = TableConfig(
name="DUMMY",
sheet_name="Network Capability",
Expand All @@ -50,10 +47,10 @@ def test_end_row_too_soon_throws_error():
"There is data in the row after the defined table end for table DUMMY."
)
with pytest.raises(TableConfigError, match=error_message):
workbook.get_table_from_config(table_config)
workbook_v6.get_table_from_config(table_config)


def test_end_column_too_soon_throws_error():
def test_end_column_too_soon_throws_error(workbook_v6):
table_config = TableConfig(
name="DUMMY",
sheet_name="Network Capability",
Expand All @@ -65,10 +62,10 @@ def test_end_column_too_soon_throws_error():
"There is data in the column adjacent to the last column in the table DUMMY."
)
with pytest.raises(TableConfigError, match=error_message):
workbook.get_table_from_config(table_config)
workbook_v6.get_table_from_config(table_config)


def test_start_column_too_far_throws_error():
def test_start_column_too_far_throws_error(workbook_v6):
table_config = TableConfig(
name="DUMMY",
sheet_name="Network Capability",
Expand All @@ -80,15 +77,15 @@ def test_start_column_too_far_throws_error():
"There is data in the column adjacent to the first column in the table DUMMY."
)
with pytest.raises(TableConfigError, match=error_message):
workbook.get_table_from_config(table_config)
workbook_v6.get_table_from_config(table_config)


def test_good_config_throws_no_error():
def test_good_config_throws_no_error(workbook_v6):
table_config = TableConfig(
name="DUMMY",
sheet_name="Network Capability",
header_rows=[6, 7],
end_row=21,
column_range="B:J",
)
workbook.get_table_from_config(table_config)
workbook_v6.get_table_from_config(table_config)
2 changes: 1 addition & 1 deletion tests/test_packaged_table_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@pytest.mark.parametrize("workbook_version_folder", workbook_path.iterdir())
def test_packaged_table_configs_for_each_version(workbook_version_folder: Path):
xl_file = [file for file in workbook_version_folder.glob("*.xls*")]
xl_file = [file for file in workbook_version_folder.glob("[!.]*.xls*")]
assert (
len(xl_file) == 1
), f"There should only be one Excel workbook in each version sub-directory, got {xl_file}"
Expand Down

0 comments on commit 1ef6f9f

Please sign in to comment.