Unit tests raising Error. (#2)

* fixed assertAlmostEqual calls in tests

As you can see in the docs the signature of assertAlmostEqual is `assertAlmostEqual(first, second, places=7, msg=None, delta=None)`
Since the message is originally provided using a positional argument and only three arguments where given, the message effectively took the place of the `places` argument.

The default of places=7 is fine, we just have to use a keyword argument instead and this will resolve the resulting `TypeError`s when testing

* change assertAlmostEqual to assertEqual for string

assertAlmostEqual only makes sense when asserting ints/floats

* no need for keyword argument

Signature of method is `assertEqual(first, second, msg=None)`
Using a keyword argument is not required here.

Co-authored-by: ngschaider <gschaiderniklas@gmail.com>
This commit is contained in:
ngschaider 2021-02-04 02:07:02 +01:00 committed by GitHub
parent 0a01eb1418
commit c887194ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,47 +8,47 @@ class DemographicAnalyzerTestCase(unittest.TestCase):
def test_race_count(self): def test_race_count(self):
actual = self.data['race_count'].tolist() actual = self.data['race_count'].tolist()
expected = [27816, 3124, 1039, 311, 271] expected = [27816, 3124, 1039, 311, 271]
self.assertAlmostEqual(actual, expected, "Expected race count values to be [27816, 3124, 1039, 311, 271]") self.assertAlmostEqual(actual, expected, msg="Expected race count values to be [27816, 3124, 1039, 311, 271]")
def test_average_age_men(self): def test_average_age_men(self):
actual = self.data['average_age_men'] actual = self.data['average_age_men']
expected = 39.4 expected = 39.4
self.assertAlmostEqual(actual, expected, "Expected different value for average age of men.") self.assertAlmostEqual(actual, expected, msg="Expected different value for average age of men.")
def test_percentage_bachelors(self): def test_percentage_bachelors(self):
actual = self.data['percentage_bachelors'] actual = self.data['percentage_bachelors']
expected = 16.4 expected = 16.4
self.assertAlmostEqual(actual, expected, "Expected different value for percentage with Bachelors degrees.") self.assertAlmostEqual(actual, expected, msg="Expected different value for percentage with Bachelors degrees.")
def test_higher_education_rich(self): def test_higher_education_rich(self):
actual = self.data['higher_education_rich'] actual = self.data['higher_education_rich']
expected = 46.5 expected = 46.5
self.assertAlmostEqual(actual, expected, "Expected different value for percentage with higher education that earn >50K.") self.assertAlmostEqual(actual, expected, msg="Expected different value for percentage with higher education that earn >50K.")
def test_lower_education_rich(self): def test_lower_education_rich(self):
actual = self.data['lower_education_rich'] actual = self.data['lower_education_rich']
expected = 17.4 expected = 17.4
self.assertAlmostEqual(actual, expected, "Expected different value for percentage without higher education that earn >50K.") self.assertAlmostEqual(actual, expected, msg="Expected different value for percentage without higher education that earn >50K.")
def test_min_work_hours(self): def test_min_work_hours(self):
actual = self.data['min_work_hours'] actual = self.data['min_work_hours']
expected = 1 expected = 1
self.assertAlmostEqual(actual, expected, "Expected different value for minimum work hours.") self.assertAlmostEqual(actual, expected, msg="Expected different value for minimum work hours.")
def test_rich_percentage(self): def test_rich_percentage(self):
actual = self.data['rich_percentage'] actual = self.data['rich_percentage']
expected = 10 expected = 10
self.assertAlmostEqual(actual, expected, "Expected different value for percentage of rich among those who work fewest hours.") self.assertAlmostEqual(actual, expected, msg="Expected different value for percentage of rich among those who work fewest hours.")
def test_highest_earning_country(self): def test_highest_earning_country(self):
actual = self.data['highest_earning_country'] actual = self.data['highest_earning_country']
expected = 'Iran' expected = 'Iran'
self.assertAlmostEqual(actual, expected, "Expected different value for highest earning country.") self.assertEqual(actual, expected, "Expected different value for highest earning country.")
def test_highest_earning_country_percentage(self): def test_highest_earning_country_percentage(self):
actual = self.data['highest_earning_country_percentage'] actual = self.data['highest_earning_country_percentage']
expected = 41.9 expected = 41.9
self.assertAlmostEqual(actual, expected, "Expected different value for heighest earning country percentage.") self.assertAlmostEqual(actual, expected, msg="Expected different value for heighest earning country percentage.")
def test_top_IN_occupation(self): def test_top_IN_occupation(self):
actual = self.data['top_IN_occupation'] actual = self.data['top_IN_occupation']