Skip to content

Commit 7294d23

Browse files
committed
cleanup
1 parent 61e684b commit 7294d23

File tree

8 files changed

+100
-104
lines changed

8 files changed

+100
-104
lines changed

pyCatSim/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pyCatSim.utils as utils
44
from .api import *
55

6+
67
# get the version
78
from importlib.metadata import version
89
__version__ = version('pyCatSim')

pyCatSim/api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
from .cat import Cat, Clowder
66
from .human import Owner
77

8+
__all__ = ["Cat", "Owner", "Clowder"]
9+

pyCatSim/api/cat.py

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,6 @@ class Cat:
6565
6666
"""
6767

68-
def give_fact(self):
69-
"""
70-
calls ..utils.random_facts() and return a random fact about cats
71-
72-
Returns
73-
-------
74-
str
75-
A fact randomly chosen from a pre-defined fact pool
76-
--------
77-
78-
.. jupyter-execute::
79-
80-
import pyCatSim as cats
81-
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
82-
nutmeg.give_fact()
83-
"""
84-
return facts.random_facts()
8568

8669
def __init__(self, name, age=None, color=None, mood=0, hunger_level=0,
8770
energy=0, health=0):
@@ -108,6 +91,24 @@ def __init__(self, name, age=None, color=None, mood=0, hunger_level=0,
10891
self.energy = energy
10992
self.health = health
11093

94+
def give_fact(self):
95+
"""
96+
calls ..utils.random_facts() and return a random fact about cats
97+
98+
Returns
99+
-------
100+
str
101+
A fact randomly chosen from a pre-defined fact pool
102+
--------
103+
104+
.. jupyter-execute::
105+
106+
import pyCatSim as cats
107+
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
108+
nutmeg.give_fact()
109+
"""
110+
return facts.random_facts()
111+
111112
def make_noise(self, noise='meow', play=False):
112113
"""
113114
@@ -152,6 +153,12 @@ def make_noise(self, noise='meow', play=False):
152153
import pyCatSim as cats
153154
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
154155
nutmeg.make_noise()
156+
157+
.. jupyter-execute::
158+
159+
import pyCatSim as cats
160+
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
161+
nutmeg.make_noise(noise='hiss')
155162
156163
"""
157164

@@ -221,13 +228,9 @@ def bathe(self):
221228
"""
222229
Bathes the cat, decreasing mood and improving health.
223230
224-
Cats typically dislike baths, which lowers their mood,
225-
but it improves their cleanliness and boosts health.
231+
Cats typically dislike baths, which lowers their mood by 1,
232+
but it improves their cleanliness and boosts health by 1.
226233
227-
Effects
228-
-------
229-
- mood: decreases by 1
230-
- health: increases by 1
231234
232235
Examples
233236
--------
@@ -238,6 +241,7 @@ def bathe(self):
238241
mochi.bathe()
239242
print(mochi.mood) # Output: 2
240243
print(mochi.health) # Output: 6
244+
241245
"""
242246
self.mood -= 1
243247
self.health += 1
@@ -250,6 +254,14 @@ def show(self):
250254
Returns
251255
-------
252256
None.
257+
258+
Examples
259+
--------
260+
.. jupyter-execute::
261+
262+
import pyCatSim as cats
263+
mochi = cats.Cat(name='Mochi', color = 'black')
264+
mochi.show()
253265
254266
"""
255267

@@ -264,24 +276,24 @@ def show(self):
264276

265277
def groom(self):
266278

267-
"""
268-
Grooms a cat, increasing its health and mood levels by one unit.
279+
"""
280+
Grooms a cat, increasing its health and mood levels by one unit.
281+
269282
283+
Examples
284+
--------
285+
286+
.. jupyter-execute::
270287
271-
Examples
272-
--------
273-
274-
.. jupyter-execute::
275-
276-
import pyCatSim as cats
277-
nutmeg = cats.Cat(name = 'Nutmeg', age = 3, color = 'tortoiseshell')
278-
nutmeg.groom()
279-
288+
import pyCatSim as cats
289+
nutmeg = cats.Cat(name = 'Nutmeg', age = 3, color = 'tortoiseshell')
290+
nutmeg.groom()
280291
281-
"""
282-
self.mood += 1
283-
self.health += 1
284-
print(f"{self.name} has been groomed. Health: {self.health}, Mood: {self.mood}")
292+
293+
"""
294+
self.mood += 1
295+
self.health += 1
296+
#print(f"{self.name} has been groomed. Health: {self.health}, Mood: {self.mood}")
285297

286298
def eat(self):
287299
"""
@@ -298,6 +310,7 @@ def eat(self):
298310
299311
Examples
300312
--------
313+
301314
.. jupyter-execute::
302315
303316
import pyCatSim as cats

pyCatSim/api/human.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,24 @@ class Owner:
5151
5252
"""
5353

54+
55+
def __init__(self, name, cats_owned):
56+
57+
58+
if isinstance(cats_owned, Cat):
59+
cats_owned = [cats_owned]
60+
elif isinstance(cats_owned, list):
61+
if not all(isinstance(cat, Cat) for cat in cats_owned):
62+
raise TypeError("All elements in cats_owned must be instances of Cat.")
63+
else:
64+
raise TypeError("cats_owned must be a Cat instance or a list of Cat instances.")
65+
66+
self.name = name
67+
self.cats_owned = cats_owned
68+
5469
def give_fact(self):
5570
"""
56-
calls ..utils.random_facts() and return a random fact about cats
71+
Gives a random fact about cats
5772
5873
Returns
5974
-------
@@ -71,21 +86,9 @@ def give_fact(self):
7186
"""
7287
return facts.random_facts()
7388

74-
def __init__(self, name, cats_owned):
75-
if isinstance(cats_owned, Cat):
76-
cats_owned = [cats_owned]
77-
elif isinstance(cats_owned, list):
78-
if not all(isinstance(cat, Cat) for cat in cats_owned):
79-
raise TypeError("All elements in cats_owned must be instances of Cat.")
80-
else:
81-
raise TypeError("cats_owned must be a Cat instance or a list of Cat instances.")
82-
83-
self.name = name
84-
self.cats_owned = cats_owned
85-
8689
def feed(self, cat):
8790
"""
88-
Feed the specified cat owned by this Owner.
91+
Feed the specified cat owned by this Owner. Decreases `hunger_level` by 1 and Increases `mood` by 1.
8992
9093
Parameters
9194
----------
@@ -98,6 +101,16 @@ def feed(self, cat):
98101
If the specified cat is not owned by this owner.
99102
AttributeError
100103
If the cat does not have 'hunger_level' or 'mood' attributes.
104+
105+
106+
..jupyter-execute::
107+
108+
import pyCatSim as cats
109+
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
110+
john = cats.Owner(name='John', cats_owned = nutmeg)
111+
john.feed(nutmeg)
112+
113+
101114
"""
102115
if cat not in self.cats_owned:
103116
raise ValueError("This owner does not own the specified cat.")
@@ -175,11 +188,8 @@ def groom(self,Cat):
175188
.. jupyter-execute::
176189
177190
from pyCatSim import Cat, Owner
178-
179191
cat1 = Cat(name="Whiskers")
180-
181192
Deborah = Owner(name="Deborah", cats_owned=cat1)
182-
183193
Deborah.groom(cat1)
184194
185195
"""

pyCatSim/tests/test_api_Cat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import pytest
2222
import sys
2323
from pyCatSim import Cat
24-
from PIL import Image
2524

2625
class TestcatCatInit:
2726
''' Test for Cat instantiation '''

pyCatSim/tests/test_api_Owner.py

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
'''
2020

2121
import pytest
22-
import pyCatSim as cat
22+
import pyCatSim as cats
2323

2424
class TesthumanOwnerInit:
2525
''' Test for Owner instantiation '''
2626

2727
def test_init_t0(self):
28-
cat1 = cat.Cat(name="Whiskers")
29-
owner1 = cat.Owner(name="Sasha", cats_owned=cat1)
28+
cat1 = cats.Cat(name="Whiskers")
29+
owner1 = cats.Owner(name="Sasha", cats_owned=cat1)
3030

3131
assert owner1.name == 'Sasha'
3232
assert type(owner1.cats_owned) is list
3333
assert len(owner1.cats_owned) == 1
3434

3535
def test_init_t1(self):
36-
cat1 = cat.Cat(name="Whiskers")
37-
cat2 = cat.Cat(name="Boots", color="tabby")
36+
cat1 = cats.Cat(name="Whiskers")
37+
cat2 = cats.Cat(name="Boots", color="tabby")
3838
# Multiple cats
39-
owner1 = cat.Owner(name="Liam", cats_owned=[cat1, cat2])
39+
owner1 = cats.Owner(name="Liam", cats_owned=[cat1, cat2])
4040

4141
assert owner1.name == 'Liam'
4242
assert type(owner1.cats_owned) is list
@@ -47,21 +47,21 @@ class TesthumanOwnerFact:
4747
''' Test for the give_fact function'''
4848

4949
def test_give_fact_t0(self):
50-
cat1 = cat.Cat(name="Whiskers")
51-
owner1 = cat.Owner(name="Sasha", cats_owned=cat1)
50+
cat1 = cats.Cat(name="Whiskers")
51+
owner1 = cats.Owner(name="Sasha", cats_owned=cat1)
5252
# Test that the fact is given correctly
5353
owner1.give_fact()
5454

5555

5656

5757
class TesthumanOwnerAdopt:
5858
def test_adopt_t0(self):
59-
cat1 = cat.Cat(name="Whiskers")
60-
cat2 = cat.Cat(name="Boots", color="tabby")
61-
owner1 = cat.Owner(name="Sasha", cats_owned=cat1)
62-
owner2 = cat.Owner(name="Liam", cats_owned=[cat1, cat2])
63-
chestnut = cat.Cat(name='Chestnut', age=4, color='tabby')
64-
nutmeg = cat.Cat(name='Nutmeg', age=3, color='tortoiseshell')
59+
cat1 = cats.Cat(name="Whiskers")
60+
cat2 = cats.Cat(name="Boots", color="tabby")
61+
owner1 = cats.Owner(name="Sasha", cats_owned=cat1)
62+
owner2 = cats.Owner(name="Liam", cats_owned=[cat1, cat2])
63+
chestnut = cats.Cat(name='Chestnut', age=4, color='tabby')
64+
nutmeg = cats.Cat(name='Nutmeg', age=3, color='tortoiseshell')
6565

6666
new_cat = chestnut
6767
owner1.adopt(new_cat)
@@ -72,30 +72,12 @@ def test_adopt_t0(self):
7272
assert owner2.cats_owned[-len(new_cat):] == new_cat
7373

7474

75-
class TesthumanOwnerAdopt:
76-
def test_adopt_t0(self):
77-
78-
cat1 = Cat(name="Whiskers")
79-
cat2 = Cat(name="Boots", color="tabby")
80-
owner1 = Owner(name="Sasha", cats_owned=cat1)
81-
owner2 = Owner(name="Liam", cats_owned=[cat1, cat2])
82-
chestnut = Cat(name='Chestnut', age = 4, color = 'tabby')
83-
nutmeg = Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
84-
85-
new_cat=chestnut
86-
owner1.adopt(new_cat)
87-
assert owner1.cats_owned[-1] == new_cat
88-
89-
new_cat=[chestnut,nutmeg]
90-
owner2.adopt(new_cat)
91-
assert owner2.cats_owned[-len(new_cat):]==new_cat
92-
9375
class TesthumanGroom:
9476
''' Test for Owner action success '''
9577

9678
def test_groom_t0(self):
97-
cat1 = cat.Cat(name="Whiskers", mood=7)
98-
owner1 = cat.Owner(name="Sasha", cats_owned=cat1)
79+
cat1 = cats.Cat(name="Whiskers", mood=7)
80+
owner1 = cats.Owner(name="Sasha", cats_owned=cat1)
9981

10082
owner1.groom(cat1)
10183
assert cat1.mood == 8
@@ -105,8 +87,8 @@ def test_feed_t0(self):
10587
"""
10688
Test that feeding a cat decreases hunger_level by 1 and increases mood by 1.
10789
"""
108-
test_cat = cat.Cat(name="Fluffy", hunger_level=5, mood=4)
109-
test_owner = cat.Owner(name="Jordan", cats_owned=test_cat)
90+
test_cat = cats.Cat(name="Fluffy", hunger_level=5, mood=4)
91+
test_owner = cats.Owner(name="Jordan", cats_owned=test_cat)
11092
test_owner.feed(test_cat)
11193
assert test_cat.hunger_level == 4
11294
assert test_cat.mood == 5

pyCatSim/utils/facts.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ def random_facts():
1212
str
1313
A fact randomly chosen from a pre-defined fact pool
1414
15-
Examples
16-
--------
17-
18-
.. jupyter-execute::
19-
20-
import pyCatSim as cats
21-
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
22-
nutmeg.give_fact()
23-
2415
"""
2516

2617
cat_facts = [

pyCatSim/utils/noises.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
from playsound import playsound
1515
import os
1616
from pathlib import Path
17-
import random
18-
import matplotlib.pyplot as plt
19-
import matplotlib.image as mpimg
17+
2018

2119
# Path to the sound files
2220
SOUND_DIR = Path(__file__).parents[1].joinpath("sounds").resolve()

0 commit comments

Comments
 (0)