Skip to content

Commit 71e0d55

Browse files
author
Alan Tan
committed
Add doctest for abstract_factory.py
1 parent 6a29d64 commit 71e0d55

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

patterns/creational/abstract_factory.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,32 @@ def random_animal():
7575

7676

7777
# Show pets with various factories
78-
if __name__ == "__main__":
79-
78+
def main():
79+
"""
8080
# A Shop that sells only cats
81-
cat_shop = PetShop(Cat)
82-
cat_shop.show_pet()
83-
print("")
81+
>>> cat_shop = PetShop(Cat)
82+
>>> cat_shop.show_pet()
83+
We have a lovely Cat
84+
It says meow
8485
8586
# A shop that sells random animals
86-
shop = PetShop(random_animal)
87-
for i in range(3):
88-
shop.show_pet()
89-
print("=" * 20)
90-
91-
### OUTPUT ###
92-
# We have a lovely Cat
93-
# It says meow
94-
#
95-
# We have a lovely Dog
96-
# It says woof
97-
# ====================
98-
# We have a lovely Cat
99-
# It says meow
100-
# ====================
101-
# We have a lovely Cat
102-
# It says meow
103-
# ====================
87+
>>> shop = PetShop(random_animal)
88+
>>> for i in range(3):
89+
... shop.show_pet()
90+
... print("=" * 20)
91+
We have a lovely Cat
92+
It says meow
93+
====================
94+
We have a lovely Dog
95+
It says woof
96+
====================
97+
We have a lovely Dog
98+
It says woof
99+
====================
100+
"""
101+
102+
103+
if __name__ == "__main__":
104+
random.seed(1234) # for deterministic doctest outputs
105+
import doctest
106+
doctest.testmod()

0 commit comments

Comments
 (0)