Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions catinabox/catactivities.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ def cat_nap(nap_seconds):
if nap_seconds < LENGTH_OF_SATISFYING_NAP:
raise NapWillNotBeSatisfying(nap_seconds)
time.sleep(nap_seconds)

#nothing
25 changes: 18 additions & 7 deletions tests/test_catactivities.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# import pytest
# import time
import pytest
import time

# from catinabox import catactivities
# why not necessary: ?
# from pytest_mock import mocker

from catinabox import catactivities


def test__cat_nap__satisfying_nap(mocker):
# mock_sleep = mocker.patch.object(time, "sleep", autospec=True)
assert True
mock_sleep = mocker.patch.object(time, "sleep", autospec=True)
# how to test: test for called_with value:
# mock_sleep.return_value = 20
# assert mock_sleep.called_with(20*60)
# assert mock_sleep.call_args(20*60)
catactivities.cat_nap(20*60)
mock_sleep.assert_called_with(20*60)


def test__cat_nap__not_satisfying(mocker):
# mock_sleep = mocker.patch.object(time, "sleep", autospec=True)
assert True
mock_sleep = mocker.patch.object(time, "sleep", autospec=True)
# mock_sleep.called_with(4*60)
with pytest.raises(catactivities.NapWillNotBeSatisfying):
catactivities.cat_nap(4*60) # too short!
assert mock_sleep.call_count == 0
6 changes: 3 additions & 3 deletions tests/test_catmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


def test__cat_years_to_hooman_years__middle_age__succeeds():
assert True
assert catmath.cat_years_to_hooman_years(8) == 40


def test__cat_years_to_hooman_years__less_than_one_year__succeeds():
assert True
assert catmath.cat_years_to_hooman_years(0.75) == 3.75


def test__cat_years_to_hooman_years__0__returns_0():
assert True
assert catmath.cat_years_to_hooman_years(0) == 0


# BONUS MATERIAL FOR STEP 2
Expand Down
37 changes: 19 additions & 18 deletions tests/test_cattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@
# add_cats
###########################################################################

def test__add_cats__succeeds():
c = cattery.Cattery()
c.add_cats(["Fluffy", "Snookums"])
assert c.cats == ["Fluffy", "Snookums"]
assert c.num_cats == 2
@pytest.fixture()
def cattery_client():
return cattery.Cattery()


def test__add_cats__succeeds(cattery_client):
cattery_client.add_cats(["Fluffy", "Snookums"])
assert cattery_client.cats == ["Fluffy", "Snookums"]
assert cattery_client.num_cats == 2


###########################################################################
# remove_cat
###########################################################################

def test__remove_cat__succeeds():
c = cattery.Cattery()
c.add_cats(["Fluffy", "Junior"])
c.remove_cat("Fluffy")
assert c.cats == ["Junior"]
assert c.num_cats == 1
def test__remove_cat__succeeds(cattery_client):
cattery_client.add_cats(["Fluffy", "Junior"])
cattery_client.remove_cat("Fluffy")
assert cattery_client.cats == ["Junior"]
assert cattery_client.num_cats == 1


def test__remove_cat__no_cats__fails():
c = cattery.Cattery()
def test__remove_cat__no_cats__fails(cattery_client):
with pytest.raises(cattery.CatNotFound):
c.remove_cat("Fluffles")
cattery_client.remove_cat("Fluffles")


def test__remove_cat__cat_not_in_cattery__fails():
c = cattery.Cattery()
c.add_cats(["Fluffy"])
def test__remove_cat__cat_not_in_cattery__fails(cattery_client):
cattery_client.add_cats(["Fluffy"])
with pytest.raises(cattery.CatNotFound):
c.remove_cat("Snookums")
cattery_client.remove_cat("Snookums")
15 changes: 9 additions & 6 deletions tests/test_safecatmath.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# import pytest
import pytest

from catinabox import safecatmath

Expand All @@ -19,17 +19,20 @@ def test__cat_years_to_hooman_years__0__returns_0():


def test__cat_years_to_hooman_years__less_0__raises():
assert True
with pytest.raises(safecatmath.InvalidAge):
safecatmath.cat_years_to_hooman_years(-3)


def test__cat_years_to_hooman_years__older_than_1000__raises():
assert True
with pytest.raises(safecatmath.InvalidAge):
safecatmath.cat_years_to_hooman_years(1100)


def test__cat_years_to_hooman_years__string__raises():
assert True
with pytest.raises(safecatmath.InvalidAge):
safecatmath.cat_years_to_hooman_years('11')


def test__cat_years_to_hooman_years__nan__raises():
# hooman_age = float('nan')
assert True
with pytest.raises(safecatmath.InvalidAge):
safecatmath.cat_years_to_hooman_years(float('nan'))