From 795161e3b7e80f53417cc2d77522851824158b15 Mon Sep 17 00:00:00 2001 From: minalsalke Date: Wed, 27 Jun 2012 16:22:31 +0530 Subject: [PATCH 1/5] Update master --- FizzBuzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FizzBuzz.py b/FizzBuzz.py index 00b6ebd..f2bb6aa 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -1,7 +1,7 @@ """ Q1. Why is the report method untestable ? [2 pts] - +External collaborator Q2. How will you change the api of the report method to make it more testable ? [2 pts] From 36d75444229483a83fd04b588aa87ebbd67a490d Mon Sep 17 00:00:00 2001 From: minalsalke Date: Wed, 27 Jun 2012 16:26:25 +0530 Subject: [PATCH 2/5] Update master --- FizzBuzz.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/FizzBuzz.py b/FizzBuzz.py index f2bb6aa..2a2bf18 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -1,18 +1,19 @@ """ Q1. Why is the report method untestable ? [2 pts] -External collaborator +External collaborator directly file pointer is given.instead wrapper func should be used - FileHandleWrapper Q2. How will you change the api of the report method to make it more testable ? [2 pts] - +as mentioned above.changes done in below code : """ class FizzBuzz(object): - def report(self, numbers): + def report(self, numbers, FileOpener): + FileOpener.Open() - report_file = open('c:/temp/fizzbuzz_report.txt', 'w') + report_file = FileOpener('c:/temp/fizzbuzz_report.txt', 'w') for number in numbers: msg = str(number) + " " From a29045f0060538b4bc0386acd3103fa4a904009b Mon Sep 17 00:00:00 2001 From: minalsalke Date: Wed, 27 Jun 2012 16:28:43 +0530 Subject: [PATCH 3/5] Update master --- FizzBuzz.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FizzBuzz.py b/FizzBuzz.py index 2a2bf18..dc4b397 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -1,10 +1,12 @@ """ Q1. Why is the report method untestable ? [2 pts] -External collaborator directly file pointer is given.instead wrapper func should be used - FileHandleWrapper +External collaborator directly file pointer is given.instead wrapper func should be used - FileHandleWrapper or pass an arg as fileopener. Q2. How will you change the api of the report method to make it more testable ? [2 pts] + + as mentioned above.changes done in below code : From ac2ff64e9c68826d384a1f15079ac19f27d43f25 Mon Sep 17 00:00:00 2001 From: minalsalke Date: Wed, 27 Jun 2012 16:34:52 +0530 Subject: [PATCH 4/5] Update master --- TestFizzBuzzMocked.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/TestFizzBuzzMocked.py b/TestFizzBuzzMocked.py index 6f1d0d5..18c3cb2 100644 --- a/TestFizzBuzzMocked.py +++ b/TestFizzBuzzMocked.py @@ -17,24 +17,22 @@ def tearDown(self): self.fb = None def test_report(self): - pass + #mock the file handle + MockInter = self.mock() + MockFile = self.mock() + self.expectAndReturn(MockInter.open('c:/temp/fizzbuzz_report.txt', 'w'), MockFile) + MockFile.write("3 fizz \n") + MockFile.close() + #replay + self.replay() + #call API + self.fb.report(numbers, FileOpener=MockInter.open) - - - - - - - - - - - - - + # verify + self.verify() if __name__ == "__main__": unittest.main() From 2db5a3ca31a89d19a6655ba667a6949636d71462 Mon Sep 17 00:00:00 2001 From: minalsalke Date: Wed, 27 Jun 2012 16:40:31 +0530 Subject: [PATCH 5/5] Update master --- TestFizzBuzzStubbed.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/TestFizzBuzzStubbed.py b/TestFizzBuzzStubbed.py index 78ee454..1fb4f28 100644 --- a/TestFizzBuzzStubbed.py +++ b/TestFizzBuzzStubbed.py @@ -4,7 +4,14 @@ """ Q3. What will be printed when we execute 'python FizzBuzzStubbed.py' ? [3 pts] - +#class setup - at start setUp +Class FizzBuzzStubbed +#test setup before each testsetup +test_reportteardown +#test setup before each test.setup +test_reportteardown +#class teardown - at end +.tearDownClass @@ -17,16 +24,16 @@ """ class MyStub(object): - pass - - - - - + def __init__(self): + self.values = [] + def write(self, value): + self.values.append(value) + def close(self): + self.closed = True - + class TestFizzBuzzStubbed(unittest.TestCase): @classmethod