Skip to content

Commit

Permalink
(edit) remove data type checks for the field values and instad, perfo…
Browse files Browse the repository at this point in the history
…rm equality check in assertFields
  • Loading branch information
nozomione committed Sep 6, 2024
1 parent daccc79 commit 75ed5b3
Showing 1 changed file with 3 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,10 @@ def assertProjectReadmeContains(self, text, zip_file):
self.assertIn(text, zip_file.read(README_FILE).decode("utf-8"))

def assertFields(self, computed_file, expected_fields: Dict):
def assert_bool(value, expected_value, message=""):
if expected_value:
self.assertTrue(value, message)
else:
self.assertFalse(value, message)

def assert_is_none(value, message=""):
self.assertIsNone(value, message)

def assert_equal(value, expected_value, message=""):
self.assertEqual(value, expected_value, message)

for expected_key, expected_value in expected_fields.items():
message = f"Field '{expected_key}' does not match"
output_value = getattr(computed_file, expected_key)
if isinstance(expected_value, bool):
assert_bool(output_value, expected_value, message)
elif expected_value is None:
assert_is_none(output_value, message)
else:
assert_equal(output_value, expected_value, message)
actual_value = getattr(computed_file, expected_key)
message = f"Expected {expected_value}, received {actual_value} on '{expected_key}'"
self.assertEqual(actual_value, expected_value, message)

def assertEqualWithVariance(self, value, expected, variance=50):
# Make sure the given value is within the range of expected bounds
Expand Down

0 comments on commit 75ed5b3

Please sign in to comment.