facade.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import time
  4. SLEEP = 0.5
  5. # Complex Parts
  6. class TC1:
  7. def run(self):
  8. print("###### In Test 1 ######")
  9. time.sleep(SLEEP)
  10. print("Setting up")
  11. time.sleep(SLEEP)
  12. print("Running test")
  13. time.sleep(SLEEP)
  14. print("Tearing down")
  15. time.sleep(SLEEP)
  16. print("Test Finished\n")
  17. class TC2:
  18. def run(self):
  19. print("###### In Test 2 ######")
  20. time.sleep(SLEEP)
  21. print("Setting up")
  22. time.sleep(SLEEP)
  23. print("Running test")
  24. time.sleep(SLEEP)
  25. print("Tearing down")
  26. time.sleep(SLEEP)
  27. print("Test Finished\n")
  28. class TC3:
  29. def run(self):
  30. print("###### In Test 3 ######")
  31. time.sleep(SLEEP)
  32. print("Setting up")
  33. time.sleep(SLEEP)
  34. print("Running test")
  35. time.sleep(SLEEP)
  36. print("Tearing down")
  37. time.sleep(SLEEP)
  38. print("Test Finished\n")
  39. # Facade
  40. class TestRunner:
  41. def __init__(self):
  42. self.tc1 = TC1()
  43. self.tc2 = TC2()
  44. self.tc3 = TC3()
  45. self.tests = [i for i in (self.tc1, self.tc2, self.tc3)]
  46. def runAll(self):
  47. [i.run() for i in self.tests]
  48. # Client
  49. if __name__ == '__main__':
  50. testrunner = TestRunner()
  51. testrunner.runAll()
  52. ### OUTPUT ###
  53. # ###### In Test 1 ######
  54. # Setting up
  55. # Running test
  56. # Tearing down
  57. # Test Finished
  58. #
  59. # ###### In Test 2 ######
  60. # Setting up
  61. # Running test
  62. # Tearing down
  63. # Test Finished
  64. #
  65. # ###### In Test 3 ######
  66. # Setting up
  67. # Running test
  68. # Tearing down
  69. # Test Finished
  70. #