Skip to content

Commit b29c589

Browse files
committed
various small fixes
1 parent 7294d23 commit b29c589

9 files changed

Lines changed: 196 additions & 136 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/pyCatSim/__pycache__
33
/pyCatSim/api/__pycache__
44
**/__pycache__
5-
./docs/_build/**
5+
/docs/build/**

docs/source/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Cat (pyCatSim.Cat)
1717
:members:
1818

1919
Clowder (pyCatSim.Clowder)
20-
""""""""""""""""""
20+
""""""""""""""""""""""""""
2121

22-
.. autoclass:: pyCatSim.api.cat.Clowder
22+
.. autoclass:: pyCatSim.api.clowder.Clowder
2323
:members:
2424

2525
Owner (pyCatSim.Owner)

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
templates_path = ['_templates']
5151
exclude_patterns = []
5252

53-
autosummary_generate = True
53+
#autosummary_generate = True
5454
numpydoc_show_class_members = True
5555

5656
# -- Options for HTML output -------------------------------------------------

docs/source/utils.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ Contains various functionalities for cat noises.
1313

1414
.. automodule:: pyCatSim.utils.noises
1515
:members:
16+
17+
Facts (pyCatSim.utils.facts)
18+
""""""""""""""""""""""""""""
19+
20+
Contains functionalities for getting facts about cats
21+
22+
.. automodule:: pyCatSim.utils.facts
23+
:members:
24+
25+
Facts (pyCatSim.utils.display)
26+
""""""""""""""""""""""""""""""
27+
28+
Contains functionalities for display images
29+
30+
.. automodule:: pyCatSim.utils.display
31+
:members:

pyCatSim/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Definition of the various Classes and in which Modules they may be found.
33
"""
44

5-
from .cat import Cat, Clowder
5+
from .cat import Cat
6+
from .clowder import Clowder
67
from .human import Owner
78

89
__all__ = ["Cat", "Owner", "Clowder"]

pyCatSim/api/cat.py

Lines changed: 46 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ def __init__(self, name, age=None, color=None, mood=0, hunger_level=0,
9393

9494
def give_fact(self):
9595
"""
96-
calls ..utils.random_facts() and return a random fact about cats
96+
Gives a random fact about cats
9797
9898
Returns
9999
-------
100100
str
101101
A fact randomly chosen from a pre-defined fact pool
102+
103+
Examples
102104
--------
103105
104106
.. jupyter-execute::
@@ -111,7 +113,7 @@ def give_fact(self):
111113

112114
def make_noise(self, noise='meow', play=False):
113115
"""
114-
116+
Have the cat make a noise
115117
116118
Parameters
117119
----------
@@ -177,52 +179,52 @@ def make_noise(self, noise='meow', play=False):
177179

178180
def play(self, mood_boost=1, hunger_boost=1, energy_boost=-1):
179181

180-
"""
181-
Simulates playtime with the cat.
182-
183-
Parameters
184-
----------
185-
mood_boost : int, optional
186-
How much mood improves from play. Must be an integer. Default is 1.
187-
hunger_boost : int, optional
188-
How much hunger increases from play. Must be a positive integer. Default is 1.
189-
energy_boost : int, optional
190-
How much energy decreases from play. Must be a negative integer. Default is -1.
182+
"""
183+
Simulates playtime with the cat.
184+
185+
Parameters
186+
----------
187+
mood_boost : int, optional
188+
How much mood improves from play. Must be an integer. Default is 1.
189+
hunger_boost : int, optional
190+
How much hunger increases from play. Must be a positive integer. Default is 1.
191+
energy_boost : int, optional
192+
How much energy decreases from play. Must be a negative integer. Default is -1.
193+
194+
Raises
195+
------
196+
TypeError
197+
If any of the arguments are not integers.
198+
ValueError
199+
If hunger_boost is not positive or energy_boost is not negative.
200+
201+
Examples
202+
--------
191203
192-
Raises
193-
------
194-
TypeError
195-
If any of the arguments are not integers.
196-
ValueError
197-
If hunger_boost is not positive or energy_boost is not negative.
198-
199-
Examples
200-
--------
204+
.. jupyter-execute::
201205
202-
.. jupyter-execute::
203-
204-
import pyCatSim as cats
205-
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
206-
nutmeg.play()
207-
206+
import pyCatSim as cats
207+
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
208+
nutmeg.play()
208209
209-
"""
210-
for arg_name, arg_value in {
211-
"mood_boost": mood_boost,
212-
"hunger_boost": hunger_boost,
213-
"energy_boost": energy_boost
214-
}.items():
215-
if not isinstance(arg_value, int):
216-
raise TypeError(f"{arg_name} must be an integer.")
217210
218-
if hunger_boost <= 0:
219-
raise ValueError("Cats always get hungry when playing! hunger_boost must be positive.")
220-
if energy_boost >= 0:
221-
raise ValueError("Cats always get tired when playing! energy_boost must be negative.")
222-
223-
self.mood += mood_boost
224-
self.hunger_level += hunger_boost
225-
self.energy += energy_boost
211+
"""
212+
for arg_name, arg_value in {
213+
"mood_boost": mood_boost,
214+
"hunger_boost": hunger_boost,
215+
"energy_boost": energy_boost
216+
}.items():
217+
if not isinstance(arg_value, int):
218+
raise TypeError(f"{arg_name} must be an integer.")
219+
220+
if hunger_boost <= 0:
221+
raise ValueError("Cats always get hungry when playing! hunger_boost must be positive.")
222+
if energy_boost >= 0:
223+
raise ValueError("Cats always get tired when playing! energy_boost must be negative.")
224+
225+
self.mood += mood_boost
226+
self.hunger_level += hunger_boost
227+
self.energy += energy_boost
226228

227229
def bathe(self):
228230
"""
@@ -376,75 +378,3 @@ def sleep(self, duration=0):
376378
energy_boost = math.floor(duration/3)
377379

378380
self.energy += energy_boost
379-
380-
class Clowder:
381-
"""
382-
Represents a group of cats.
383-
384-
Parameters
385-
----------
386-
catlist: list
387-
A list of cats from the Cat class
388-
389-
Attributes
390-
----------
391-
catlist: list
392-
A list of cats from the Cat class
393-
394-
Examples
395-
--------
396-
397-
.. jupyter-execute::
398-
399-
import pyCatSim as cats
400-
group = cats.Clowder(catlist = [list_of_Cats])
401-
"""
402-
403-
def __init__(self, catlist=None):
404-
if catlist is None:
405-
catlist = []
406-
elif not all(isinstance(cat,Cat) for cat in catlist):
407-
raise TypeError("All elements of the list must be a Cat object")
408-
self.catlist = catlist
409-
410-
411-
def add_cat(self, cat):
412-
413-
"""
414-
Adds a Cat to the Clowder
415-
416-
Parameters:
417-
-----------
418-
cat: Cat
419-
the new Cat to add
420-
421-
Raises
422-
------
423-
TypeError
424-
If any of the arguments are not Cat instances.
425-
"""
426-
427-
if not isinstance(cat, Cat):
428-
raise TypeError("Only Cat objects can be added.")
429-
self.catlist.append(cat)
430-
431-
432-
def remove_cat(self,cat):
433-
"""
434-
Removes a Cat from the Clowder
435-
436-
Parameters:
437-
-----------
438-
cat: Cat
439-
the Cat to remove
440-
441-
Raises
442-
------
443-
ValueError
444-
If the Cat is not found in the clowder.
445-
"""
446-
447-
try:
448-
self.catlist.remove(cat)
449-
except ValueError:
450-
raise ValueError("Cat not found in Clowder")

pyCatSim/api/clowder.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
The cat module allows to create a Cat or a group of Cats (i.e. a Clowder)
5+
"""
6+
7+
from .cat import Cat
8+
9+
class Clowder:
10+
"""
11+
Represents a group of cats.
12+
13+
Parameters
14+
----------
15+
catlist: list
16+
A list of cats from the Cat class
17+
18+
Attributes
19+
----------
20+
catlist: list
21+
A list of cats from the Cat class
22+
23+
Examples
24+
--------
25+
26+
.. jupyter-execute::
27+
28+
import pyCatSim as cats
29+
nutmeg = cats.Cat('Nutmeg')
30+
charming = cats.Cat('Charming')
31+
maze = cats.Cat('Mazikeen')
32+
una = cats.Cat('Una')
33+
group = cats.Clowder(catlist = [nutmeg, charming, maze, una])
34+
35+
"""
36+
37+
def __init__(self, catlist=None):
38+
if catlist is None:
39+
catlist = []
40+
elif isinstance(catlist, Cat):
41+
catlist = [catlist]
42+
elif not all(isinstance(cat,Cat) for cat in catlist):
43+
raise TypeError("All elements of the list must be a Cat object")
44+
self.catlist = catlist
45+
46+
47+
def add_cat(self, cat):
48+
49+
"""
50+
Adds a Cat to the Clowder
51+
52+
Parameters
53+
----------
54+
cat: pycCatSim.Cat
55+
the new Cat to add
56+
57+
Raises
58+
------
59+
TypeError
60+
If any of the arguments are not Cat instances.
61+
62+
Examples
63+
--------
64+
65+
.. jupyter-execute::
66+
67+
import pyCatSim as cats
68+
nutmeg = cats.Cat('Nutmeg')
69+
charming = cats.Cat('Charming')
70+
maze = cats.Cat('Mazikeen')
71+
una = cats.Cat('Una')
72+
group = cats.Clowder(catlist = [nutmeg, charming, maze, una])
73+
bailey = cats.Cat('Bailey')
74+
group.add_cat(bailey)
75+
76+
"""
77+
78+
if not isinstance(cat, Cat):
79+
raise TypeError("Only Cat objects can be added.")
80+
self.catlist.append(cat)
81+
82+
83+
def remove_cat(self,cat):
84+
"""
85+
Removes a Cat from the Clowder
86+
87+
Parameters
88+
----------
89+
cat: pyCatSim.Cat
90+
the Cat to remove
91+
92+
Raises
93+
------
94+
ValueError
95+
If the Cat is not found in the clowder.
96+
97+
Examples
98+
--------
99+
100+
.. jupyter-execute::
101+
102+
import pyCatSim as cats
103+
nutmeg = cats.Cat('Nutmeg')
104+
charming = cats.Cat('Charming')
105+
maze = cats.Cat('Mazikeen')
106+
una = cats.Cat('Una')
107+
group = cats.Clowder(catlist = [nutmeg, charming, maze, una])
108+
group.remove_cat(nutmeg)
109+
"""
110+
111+
try:
112+
self.catlist.remove(cat)
113+
except ValueError:
114+
raise ValueError("Cat not found in Clowder")

0 commit comments

Comments
 (0)