Open hhummel opened 4 years ago
Thanks for the report! Yes there are two separate bugs here that I need to fix:
First is in the test assertions, I'm using the wrong mocks, so this is what needs to change:
result = do_rounds(database, 'Meerkat', utcnow=now_func)
assert result == 2
- food_func.assert_called_once_with(database, 'Meerkat')
- animals_func.assert_called_once_with(database, 'Meerkat')
- feed_func.assert_has_calls(
+ get_food_period.assert_called_once_with(database, 'Meerkat')
+ get_animals.assert_called_once_with(database, 'Meerkat')
+ feed_animal.assert_has_calls(
[
call(database, 'Spot', now_func.return_value),
call(database, 'Fluffy', now_func.return_value),
And once that's fixed, the example still fails because there's a typo in the later version of do_rounds
that doesn't have as many keyword arguments. That needs to change like this:
for name, last_mealtime in animals:
if (now - last_mealtime) > feeding_timedelta:
- feed_func(database, name, now)
+ feed_animal(database, name, now)
fed += 1
Thanks for following up! Big fan
On Sun, May 24, 2020 at 5:28 PM Brett Slatkin notifications@github.com wrote:
Thanks for the report! Yes there are two separate bugs here that I need to fix:
First is in the test assertions, I'm using the wrong mocks, so this is what needs to change:
result = do_rounds(database, 'Meerkat', utcnow=now_func) assert result == 2
- food_func.assert_called_once_with(database, 'Meerkat')
- animals_func.assert_called_once_with(database, 'Meerkat')
- feed_func.assert_has_calls(
- get_food_period.assert_called_once_with(database, 'Meerkat')
- get_animals.assert_called_once_with(database, 'Meerkat')
- feed_animal.assert_has_calls( [ call(database, 'Spot', now_func.return_value), call(database, 'Fluffy', now_func.return_value),
And once that's fixed, the example still fails because there's a typo in the later version of do_rounds that doesn't have as many keyword arguments. That needs to change like this:
for name, last_mealtime in animals: if (now - last_mealtime) > feeding_timedelta:
- feed_func(database, name, now)
- feed_animal(database, name, now) fed += 1
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bslatkin/effectivepython/issues/73#issuecomment-633303578, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADL374OFJPKQ4TH2SPD7SMTRTGGO3ANCNFSM4MYM53SA .
Test refers to food_func, animals_func and feed_func, but these don't appear in the patch on p 374. Did you mean get_food_period, get_animals and feed_animal?
Even changing those, the assert result == 2 fails, (returning 3), and should be self.assertEqual according to what you say on p 360.
Next I get an assert error: AssertionError: (('', <BoundArguments (database=<object object at 0x7f652955ffb0>, name='Spot', when=datetime.datetime(2019, 6, 5, 15, 45))>), ('', <BoundArguments (database=<object object at 0x7f652955ffb0>, name='Fluffy', when=datetime.datetime(2019, 6, 5, 15, 45))>)) not all found in call list This is where I gave up.