Skip to content

Commit

Permalink
Merge pull request faif#340 from alanwuha/master
Browse files Browse the repository at this point in the history
Add doctest for abstract_factory.py
  • Loading branch information
faif authored Jul 6, 2020
2 parents 9ee9b44 + 50ed535 commit 30a9eaf
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions patterns/creational/abstract_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,32 @@ def random_animal():


# Show pets with various factories
if __name__ == "__main__":

def main():
"""
# A Shop that sells only cats
cat_shop = PetShop(Cat)
cat_shop.show_pet()
print("")
>>> cat_shop = PetShop(Cat)
>>> cat_shop.show_pet()
We have a lovely Cat
It says meow
# A shop that sells random animals
shop = PetShop(random_animal)
for i in range(3):
shop.show_pet()
print("=" * 20)

### OUTPUT ###
# We have a lovely Cat
# It says meow
#
# We have a lovely Dog
# It says woof
# ====================
# We have a lovely Cat
# It says meow
# ====================
# We have a lovely Cat
# It says meow
# ====================
>>> shop = PetShop(random_animal)
>>> for i in range(3):
... shop.show_pet()
... print("=" * 20)
We have a lovely Cat
It says meow
====================
We have a lovely Dog
It says woof
====================
We have a lovely Dog
It says woof
====================
"""


if __name__ == "__main__":
random.seed(1234) # for deterministic doctest outputs
import doctest
doctest.testmod()

0 comments on commit 30a9eaf

Please sign in to comment.