Skip to content

Commit

Permalink
Use assertRegex() and assertNotRegex() assertions
Browse files Browse the repository at this point in the history
Per the Python docs, the assertRegexpMatches() and
assertNotRegexpMatches() assertions has been deprecated for some time.
See:
<https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRegex>
  • Loading branch information
caleb531 committed Oct 8, 2023
1 parent ccb36c7 commit 37ada76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions tests/test_simulator_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def test_display_addr_refs():
table_output = out.getvalue()
num_cols = 6
col_width = TABLE_WIDTH // num_cols
case.assertRegexpMatches(
case.assertRegex(
table_output, r'{}\s*{}\s*{}\s*{}\s*{}\s*{}\n{}'.format(
'WordAddr'.rjust(col_width), 'BinAddr'.rjust(col_width),
'Tag'.rjust(col_width), 'Index'.rjust(col_width),
'Offset'.rjust(col_width), 'Hit/Miss'.rjust(col_width),
('-' * TABLE_WIDTH)))
case.assertRegexpMatches(
case.assertRegex(
table_output, r'{}\s*{}\s*{}\s*{}\s*{}\s*{}'.format(
'253'.rjust(col_width), '1111 1101'.rjust(col_width),
'11111'.rjust(col_width), '10'.rjust(col_width),
Expand All @@ -55,7 +55,7 @@ def test_display_addr_refs_no_tag():
with contextlib.redirect_stdout(out):
sim.display_addr_refs(refs, table_width=TABLE_WIDTH)
table_output = out.getvalue()
case.assertRegexpMatches(
case.assertRegex(
table_output, r'\s*{}\s*{}\s*{}'.format(
r'\d\d', r'n/a', r'\d'))

Expand All @@ -71,7 +71,7 @@ def test_display_addr_refs_no_index():
with contextlib.redirect_stdout(out):
sim.display_addr_refs(refs, table_width=TABLE_WIDTH)
table_output = out.getvalue()
case.assertRegexpMatches(
case.assertRegex(
table_output, r'\s*{}\s*{}\s*{}'.format(
r'n/a', r'\d', 'miss'))

Expand All @@ -87,7 +87,7 @@ def test_display_addr_refs_no_offset():
with contextlib.redirect_stdout(out):
sim.display_addr_refs(refs, table_width=TABLE_WIDTH)
table_output = out.getvalue()
case.assertRegexpMatches(
case.assertRegex(
table_output, r'\s*{}\s*{}\s*{}'.format(
r'\d\d', r'n/a', 'miss'))

Expand All @@ -109,17 +109,17 @@ def test_display_cache():
table_output = out.getvalue()
num_cols = 2
col_width = TABLE_WIDTH // num_cols
case.assertRegexpMatches(
case.assertRegex(
table_output, '{}\n{}'.format(
'Cache'.center(TABLE_WIDTH),
('-' * TABLE_WIDTH)))
case.assertEqual(
table_output.count('-'), TABLE_WIDTH * 2)
case.assertRegexpMatches(
case.assertRegex(
table_output, r'{}{}'.format(
'000'.center(col_width),
'001'.center(col_width)))
case.assertRegexpMatches(
case.assertRegex(
table_output, r'{}{}'.format(
'88,89'.center(col_width),
'2,3 42,43'.center(col_width)))
Expand All @@ -137,11 +137,11 @@ def test_display_cache_fully_assoc():
]
}, table_width=TABLE_WIDTH)
table_output = out.getvalue()
case.assertRegexpMatches(
case.assertRegex(
table_output, '{}\n{}'.format(
'Cache'.center(TABLE_WIDTH),
('-' * TABLE_WIDTH)))
case.assertEqual(
table_output.count('-'), TABLE_WIDTH)
case.assertRegexpMatches(
case.assertRegex(
table_output, '2,3 252,253'.center(TABLE_WIDTH))
10 changes: 5 additions & 5 deletions tests/test_simulator_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def test_main():
with contextlib.redirect_stdout(out):
main.main()
main_output = out.getvalue()
case.assertRegexpMatches(main_output, r'\bWordAddr\b')
case.assertRegexpMatches(main_output, r'\b0110\b')
case.assertRegexpMatches(main_output, r'\bCache')
case.assertRegexpMatches(main_output, r'\b01\b')
case.assertRegexpMatches(main_output, r'\b8\s*6\b')
case.assertRegex(main_output, r'\bWordAddr\b')
case.assertRegex(main_output, r'\b0110\b')
case.assertRegex(main_output, r'\bCache')
case.assertRegex(main_output, r'\b01\b')
case.assertRegex(main_output, r'\b8\s*6\b')
2 changes: 1 addition & 1 deletion tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_get_separator():
def test_str_title():
"""should correctly display title"""
table = Table(num_cols=5, width=12, title='Cache')
case.assertRegexpMatches(
case.assertRegex(
''.join(('Cache'.center(12), '\n', ('-' * 12))), str(table))


Expand Down

0 comments on commit 37ada76

Please sign in to comment.