def test_age_at_backward(self, user, age, data):
     assume(user.date_of_birth.year + age <= 10000)  # relativedelta doesn't like year 10000 and above
     # one of the techniques to define a property - work backwards from the output to the input that will produce it
     check_age_at = data.draw(st.datetimes(
         min_value=user.date_of_birth + relativedelta(dt1=user.date_of_birth, years=age),
         max_value=user.date_of_birth + relativedelta(dt1=user.date_of_birth, years=age+1) - timedelta(microseconds=1),
     ))
     self.assertEqual(age_at(user, check_age_at), age)  # property
Ejemplo n.º 2
0
 def test_age_before_born(self, user, date):
     with self.assertRaises(AssertionError):
         age_at(user, date)
Ejemplo n.º 3
0
 def test_age_at(self, user, date, expected_age):
     self.assertEqual(age_at(user, date), expected_age)
 def test_age_before_born(self, user, datetime):
     assume(user.date_of_birth > datetime)
     with self.assertRaises(AssertionError):  # property
         age_at(user, datetime)
 def test_age_at_tautological(self, user, date):
     # FIXME: this is an example of tautological test - DO NOT DO THIS
     assume(user.date_of_birth <= date)
     expected_age = relativedelta(date, user.date_of_birth).years
     self.assertEqual(age_at(user, date), expected_age)  # property
Ejemplo n.º 6
0
 def test_age_before_born(self):
     with self.assertRaises(AssertionError):
         age_at(Users.jack, parser.parse("1990-01-01"))
Ejemplo n.º 7
0
 def test_age_at_16th_birthday(self):
     self.assertEqual(age_at(Users.jack, parser.parse("2015-01-01")), 16)
Ejemplo n.º 8
0
 def test_age_at_some_random_date_after_birth(self):
     self.assertEqual(age_at(Users.jill, parser.parse("2019-11-11")), 18)
Ejemplo n.º 9
0
 def test_age_at_birth(self):
     self.assertEqual(age_at(Users.jack, Users.jack.date_of_birth), 0)