diff --git a/catinabox/catactivities.py b/catinabox/catactivities.py index 012367b..34a53b1 100644 --- a/catinabox/catactivities.py +++ b/catinabox/catactivities.py @@ -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 diff --git a/tests/test_catactivities.py b/tests/test_catactivities.py index e2051b1..ef82ac1 100644 --- a/tests/test_catactivities.py +++ b/tests/test_catactivities.py @@ -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 diff --git a/tests/test_catmath.py b/tests/test_catmath.py index ced6358..233388c 100644 --- a/tests/test_catmath.py +++ b/tests/test_catmath.py @@ -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 diff --git a/tests/test_cattery.py b/tests/test_cattery.py index b36692c..527c38c 100644 --- a/tests/test_cattery.py +++ b/tests/test_cattery.py @@ -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") diff --git a/tests/test_safecatmath.py b/tests/test_safecatmath.py index 3f85a35..fd26197 100644 --- a/tests/test_safecatmath.py +++ b/tests/test_safecatmath.py @@ -1,4 +1,4 @@ -# import pytest +import pytest from catinabox import safecatmath @@ -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'))