Skip to content

Commit 6127f9d

Browse files
committed
Fixed tests for abstract factory.
This all removes all the low value tests which were testing things that were trivial, irrelevant to the point or now no longer exist.
1 parent d68190d commit 6127f9d

2 files changed

Lines changed: 9 additions & 56 deletions

File tree

creational/abstract_factory.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,16 @@ def random_animal():
9393
shop.show_pet()
9494
print("=" * 20)
9595

96-
9796
### OUTPUT ###
9897
# We have a lovely Cat
9998
# It says meow
100-
#
101-
# ====================
99+
#
102100
# We have a lovely Dog
103101
# It says woof
104102
# ====================
105103
# We have a lovely Cat
106104
# It says meow
107105
# ====================
106+
# We have a lovely Cat
107+
# It says meow
108+
# ====================

tests/test_abstract_factory.py

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import unittest
4-
from creational.abstract_factory import PetShop,\
5-
Dog, Cat, DogFactory, CatFactory, Pet
4+
from creational.abstract_factory import PetShop, Dog
65
try:
76
from unittest.mock import patch
87
except ImportError:
@@ -12,54 +11,7 @@
1211
class TestPetShop(unittest.TestCase):
1312

1413
def test_dog_pet_shop_shall_show_dog_instance(self):
15-
f = DogFactory()
16-
with patch.object(f, 'get_pet') as mock_f_get_pet,\
17-
patch.object(f, 'get_food') as mock_f_get_food:
18-
ps = PetShop(f)
19-
ps.show_pet()
20-
self.assertEqual(mock_f_get_pet.call_count, 1)
21-
self.assertEqual(mock_f_get_food.call_count, 1)
22-
23-
def test_cat_pet_shop_shall_show_cat_instance(self):
24-
f = CatFactory()
25-
with patch.object(f, 'get_pet') as mock_f_get_pet,\
26-
patch.object(f, 'get_food') as mock_f_get_food:
27-
ps = PetShop(f)
28-
ps.show_pet()
29-
self.assertEqual(mock_f_get_pet.call_count, 1)
30-
self.assertEqual(mock_f_get_food.call_count, 1)
31-
32-
33-
class TestCat(unittest.TestCase):
34-
35-
@classmethod
36-
def setUpClass(cls):
37-
cls.c = Cat()
38-
39-
def test_cat_shall_meow(cls):
40-
cls.assertEqual(cls.c.speak(), 'meow')
41-
42-
def test_cat_shall_be_printable(cls):
43-
cls.assertEqual(str(cls.c), 'Cat')
44-
45-
46-
class TestDog(unittest.TestCase):
47-
48-
@classmethod
49-
def setUpClass(cls):
50-
cls.d = Dog()
51-
52-
def test_dog_shall_woof(cls):
53-
cls.assertEqual(cls.d.speak(), 'woof')
54-
55-
def test_dog_shall_be_printable(cls):
56-
cls.assertEqual(str(cls.d), 'Dog')
57-
58-
59-
class PetTest(unittest.TestCase):
60-
61-
def test_from_name(self):
62-
test_cases = [("kitty", "Miao"), ("duck", "Quak")]
63-
for name, expected_speech in test_cases:
64-
pet = Pet.from_name(name)
65-
self.assertEqual(pet.speak(), expected_speech)
14+
dog_pet_shop = PetShop(Dog)
15+
with patch.object(Dog, 'speak') as mock_Dog_speak:
16+
dog_pet_shop.show_pet()
17+
self.assertEqual(mock_Dog_speak.call_count, 1)

0 commit comments

Comments
 (0)