Skip to content

Commit

Permalink
Merge pull request #44 from TranslatorSRI/fix-nodenorm-row-id
Browse files Browse the repository at this point in the history
By default, test IDs are 0-based. This corrects them so that the row index in the file could be used to directly look up the test row in the Google Sheet.
  • Loading branch information
gaurav authored Nov 4, 2024
2 parents 5dc2d19 + 64c0a65 commit d608fe9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions tests/common/google_sheet_test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ def __init__(self, google_sheet_id="11zebx8Qs1Tc3ShQR9nh4HRW8QSoo8k65w_xIaftN0no
for row in reader:
self.rows.append(row)

def test_rows(self, test_nodenorm: bool = False, test_nameres: bool = False) -> list[ParameterSet]:
def test_rows(self, test_id_prefix: str, test_nodenorm: bool = False, test_nameres: bool = False) -> list[ParameterSet]:
"""
self.rows is the raw list of rows we got back from the Google Sheets. This method transforms that into
a list of TestRows.
:param test_id_prefix: The prefix for the row ID.
:return: A list of TestRows for the rows in this file.
"""
def has_nonempty_value(d: dict):
Expand All @@ -104,32 +106,35 @@ def has_nonempty_value(d: dict):
for count, row in enumerate(self.rows):
# Note that count is off by two: presumably one for the header row and one because we count from zero
# but Google Sheets counts from one.
row_id = f"{test_id_prefix}:row={count + 2}"

if has_nonempty_value(row):
tr = TestRow.from_data_row(row)

if test_nodenorm:
if tr.ExpectPassInNodeNorm:
trows.append(pytest.param(tr))
trows.append(pytest.param(tr, id=row_id))
else:
trows.append(pytest.param(
tr,
marks=pytest.mark.xfail(
reason=f"Test row {count + 2} is marked as not expected to pass NodeNorm in the "
f"Google Sheet: {tr}",
strict=True)
strict=True),
id=row_id
))

if test_nameres:
if tr.ExpectPassInNameRes:
trows.append(pytest.param(tr))
trows.append(pytest.param(tr, id=row_id))
else:
trows.append(pytest.param(
tr,
marks=pytest.mark.xfail(
reason=f"Test row {count + 2} is marked as not expected to pass NameRes in the "
f"Google Sheet: {tr}",
strict=True)
strict=True),
id=row_id
))

return trows
Expand Down
2 changes: 1 addition & 1 deletion tests/nameres/test_nameres_from_gsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
gsheet = GoogleSheetTestCases()


@pytest.mark.parametrize("test_row", gsheet.test_rows(test_nodenorm=False, test_nameres=True))
@pytest.mark.parametrize("test_row", gsheet.test_rows('test_nameres_from_gsheet.test_label', test_nodenorm=False, test_nameres=True))
def test_label(target_info, test_row, test_category):
nameres_url = target_info['NameResURL']
limit = target_info['NameResLimit']
Expand Down
2 changes: 1 addition & 1 deletion tests/nodenorm/test_nodenorm_from_gsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
gsheet = GoogleSheetTestCases()


@pytest.mark.parametrize("test_row", gsheet.test_rows(test_nodenorm=True, test_nameres=False))
@pytest.mark.parametrize("test_row", gsheet.test_rows('test_nodenorm_from_gsheet.test_row', test_nodenorm=True, test_nameres=False))
def test_normalization(target_info, test_row, test_category):
nodenorm_url = target_info['NodeNormURL']

Expand Down

0 comments on commit d608fe9

Please sign in to comment.