Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial wip #201

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
venv/
.vscode/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python
python:
- "2.7"
- "3.4"
- "3.7"
install:
- "pip install -r requirements.txt"
- "pip install -r test_requirements.txt"
Expand Down
2 changes: 1 addition & 1 deletion catinabox/catmath.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NUM_HOOMAN_YEARS_IN_CAT_YEAR = 5


def cat_years_to_hooman_years(age_in_cat_years):
def cat_years_to_hooman_years(age_in_cat_years: float) -> float:
"""Converts the cat's age to the equivalent in hooman years.

:param age_in_cat_years: A float: cat's age in years
Expand Down
17 changes: 10 additions & 7 deletions tests/test_catactivities.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# import pytest
# import time
import pytest
import time

# from catinabox import catactivities
from catinabox import catactivities


def test__cat_nap__satisfying_nap(mocker):
# mock_sleep = mocker.patch.object(time, "sleep", autospec=True)
assert True
mocker.patch.object(time, "sleep", autospec=True)
catactivities.cat_nap(400)
time.sleep.assert_called_with(400)


def test__cat_nap__not_satisfying(mocker):
# mock_sleep = mocker.patch.object(time, "sleep", autospec=True)
assert True
mocker.patch.object(time, "sleep", autospec=True)
with pytest.raises(catactivities.NapWillNotBeSatisfying):
catactivities.cat_nap(1)
time.sleep.assert_not_called()
21 changes: 11 additions & 10 deletions tests/test_catmath.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import pytest
from catinabox import catmath


def test__cat_years_to_hooman_years__middle_age__succeeds():
assert True


def test__cat_years_to_hooman_years__less_than_one_year__succeeds():
assert True


def test__cat_years_to_hooman_years__0__returns_0():
assert True
@pytest.mark.parametrize("age, expected", [
(10, 50),
(0.5, 2.5),
(0, 0)
])
def test__cat_years_to_hooman_years(age, expected):
assert catmath.cat_years_to_hooman_years(age) == expected


# BONUS MATERIAL FOR STEP 2

def test__is_cat_leap_year__succeeds():
assert catmath.is_cat_leap_year(2016) is True
assert catmath.is_cat_leap_year(2000) is True
assert catmath.is_cat_leap_year(2100) is False
assert catmath.is_cat_leap_year(1997) is False
44 changes: 25 additions & 19 deletions tests/test_cattery.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
import pytest

from catinabox import cattery

from catinabox import mccattery

###########################################################################
# 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(params=[
cattery.Cattery,
mccattery.McCattery
])
def cattery_client(request):
c = request.param()
return c


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")
52 changes: 21 additions & 31 deletions tests/test_safecatmath.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
# import pytest
import pytest

from catinabox import safecatmath


def test__cat_years_to_hooman_years__middle_age__succeeds():
hooman_age = safecatmath.cat_years_to_hooman_years(7)
assert hooman_age == 35


def test__cat_years_to_hooman_years__less_than_one_year__succeeds():
hooman_age = safecatmath.cat_years_to_hooman_years(0.1)
assert hooman_age == 0.5


def test__cat_years_to_hooman_years__0__returns_0():
hooman_age = safecatmath.cat_years_to_hooman_years(0)
assert hooman_age == 0


def test__cat_years_to_hooman_years__less_0__raises():
assert True


def test__cat_years_to_hooman_years__older_than_1000__raises():
assert True


def test__cat_years_to_hooman_years__string__raises():
assert True


def test__cat_years_to_hooman_years__nan__raises():
# hooman_age = float('nan')
assert True
@pytest.mark.parametrize('cat_age, hooman_age', [
(7, 35),
(0.1, 0.5),
(0, 0)
])
def test__cat_years_to_hooman_years(cat_age, hooman_age):
assert safecatmath.cat_years_to_hooman_years(cat_age) == hooman_age


@pytest.mark.parametrize('cat_age', [
-1,
10001,
'test',
[-3, 4],
{3: 4},
float('nan')
])
def test__cat_years_to_hooman_years_invalid_raises(cat_age):
with pytest.raises(safecatmath.InvalidAge):
safecatmath.cat_years_to_hooman_years(cat_age)