diff --git a/src/animals.py b/src/animals.py deleted file mode 100644 index 33a6967..0000000 --- a/src/animals.py +++ /dev/null @@ -1,33 +0,0 @@ -class Animal(object): - """Base class""" - noise = None - - def make_noise(self): - if self.noise is None: - raise NotImplementedError() - else: - print(self.noise) - - -class Goat(Animal): - noise = "baaa" - - -class Cow(Animal): - noise = "moo" - - -class Pig(Animal): - noise = "oink" - - -class Dog(Animal): - noise = "arf" - - -class Cat(Animal): - noise = "mrkgnao" - - -class Human(Animal): - noise = "buuurp" diff --git a/src/movies.py b/src/movies.py new file mode 100644 index 0000000..4070a9d --- /dev/null +++ b/src/movies.py @@ -0,0 +1,37 @@ +class Movie(object): + """Base class: a movie starring Al Pacino""" + title = None + + def get_title(self): + if self.title is None: + raise NotImplementedError() + else: + print(self.title) + + +class Gf(Movie): + title = "The Godfather" + + +class Gf2(Movie): + title = "The Godfather Part II" + + +class Gf3(Movie): + title = "The Godfather Part III" + + +class Serpico(Movie): + title = "Serpico" + + +class Scarface(Movie): + title = "Scarface" + + +class Ggr(Movie): + title = "Glengarry Glen Ross" + + +class Heat(Movie): + title = "Heat" diff --git a/tests/test_animals.py b/tests/test_animals.py deleted file mode 100644 index 658a7bd..0000000 --- a/tests/test_animals.py +++ /dev/null @@ -1,35 +0,0 @@ -import os -import sys -import unittest - -from al_pacino.animals import Animal, Goat, Cow, Pig, Dog, Cat, Human - -pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) # noqa -sys.path.insert(0, pkg_root) # noqa - -from tests import utils - - -class TestAnimals(unittest.TestCase): - def test_make_noise(self): - # base class - with self.assertRaises(NotImplementedError): - Animal().make_noise() - - # child classes - correct = [ - (Goat, "baaa"), - (Cow, "moo"), - (Pig, "oink"), - (Dog, "arf"), - (Cat, "mrkgnao"), - (Human, "buuurp"), - ] - for cls, correct_noise in correct: - with utils.CaptureStdout() as output: - cls().make_noise() - self.assertIn(correct_noise, "".join(output)) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_movies.py b/tests/test_movies.py new file mode 100644 index 0000000..051b8c8 --- /dev/null +++ b/tests/test_movies.py @@ -0,0 +1,36 @@ +import os +import sys +import unittest + +from al_pacino.movies import Movie, Gf, Gf2, Gf3, Serpico, Scarface, Ggr, Heat + +pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) # noqa +sys.path.insert(0, pkg_root) # noqa + +from tests import utils + + +class TestMovies(unittest.TestCase): + def test_movies(self): + # base class + with self.assertRaises(NotImplementedError): + Movie().get_title() + + # child classes + correct = [ + (Gf, "The Godfather"), + (Gf2, "The Godfather Part II"), + (Gf3, "The Godfather Part III"), + (Serpico, "Serpico"), + (Scarface, "Scarface"), + (Ggr, "Glengarry Glen Ross"), + (Heat, "Heat"), + ] + for cls, correct_title in correct: + with utils.CaptureStdout() as output: + cls().get_title() + self.assertIn(correct_title, output[0]) + + +if __name__ == "__main__": + unittest.main()