From c0a8a4eef9f61b695659f4a1c8b92b2498278db2 Mon Sep 17 00:00:00 2001 From: maheshmakude Date: Tue, 26 Jun 2012 18:15:12 +0530 Subject: [PATCH 1/6] Update master --- FizzBuzz.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FizzBuzz.py b/FizzBuzz.py index 00b6ebd..fded117 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -6,7 +6,8 @@ Q2. How will you change the api of the report method to make it more testable ? [2 pts] - +Ans :- + 1. For handelling the file pale we wili use file handler """ class FizzBuzz(object): From c2a8377ec41a88170038898bc95e05365ff1ba8a Mon Sep 17 00:00:00 2001 From: maheshmakude Date: Tue, 26 Jun 2012 18:15:44 +0530 Subject: [PATCH 2/6] Update master --- FizzBuzz.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/FizzBuzz.py b/FizzBuzz.py index fded117..52b5469 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -1,6 +1,11 @@ """ Q1. Why is the report method untestable ? [2 pts] +Ans - + 1. As the file path is user/OS/System specific + 2. inputs to report method depends on colabrataive (Range) + 3. While writing msg to a report file its constructed from numbers. + 4. it is easy to use for writer but not to user who is using it. From f052b696c08073bc8308faf13a045bddb81f79c8 Mon Sep 17 00:00:00 2001 From: maheshmakude Date: Tue, 26 Jun 2012 18:16:29 +0530 Subject: [PATCH 3/6] Update master --- TestFizzBuzzStubbed.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/TestFizzBuzzStubbed.py b/TestFizzBuzzStubbed.py index 78ee454..096d2b6 100644 --- a/TestFizzBuzzStubbed.py +++ b/TestFizzBuzzStubbed.py @@ -6,7 +6,15 @@ - +Ans:_ +setUpClass FizzBuzzStubbed +setup +test_report +teardown +.setup +test_report +teardown +.tearDownClass From 122642fa513fb52cd96d4a5fc0e74c844030e555 Mon Sep 17 00:00:00 2001 From: maheshmakude Date: Tue, 26 Jun 2012 18:41:59 +0530 Subject: [PATCH 4/6] Update master --- FizzBuzz.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/FizzBuzz.py b/FizzBuzz.py index 52b5469..6d6dbe6 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -13,6 +13,51 @@ Ans :- 1. For handelling the file pale we wili use file handler + + class FizzBuzz(object): + + def report(self, numbers, file_handle): + + for number in numbers: + + msg = str(number) + " " + + fizzbuzz_found = False + + if number % 3 == 0: + + msg += "fizz " + + fizzbuzz_found = True + + if number % 5 == 0: + + msg += "buzz " + + fizzbuzz_found = True + + if fizzbuzz_found: + + file_handle.write(msg + "\n") + + + + + + + + + +if "__main__" == __name__: + + fb = FizzBuzz() + + file_handle = open('temp.txt', 'w') # can create open wrapper + + fb.report(range(100), file_handle) + + file_handle.close() + """ class FizzBuzz(object): From 78854c1938f17a7214d9e0a9dba28dac8d276b41 Mon Sep 17 00:00:00 2001 From: maheshmakude Date: Wed, 27 Jun 2012 13:22:57 +0530 Subject: [PATCH 5/6] Update master --- TestFizzBuzzMocked.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/TestFizzBuzzMocked.py b/TestFizzBuzzMocked.py index 6f1d0d5..8506754 100644 --- a/TestFizzBuzzMocked.py +++ b/TestFizzBuzzMocked.py @@ -6,8 +6,9 @@ mock objects to test the report method of FizzBuzz. [5 pts] """ class TestFizzBuzzMocked(pymock.PyMockTestCase): - + def setUp(self): + super(TestFizzBuzzMocked, self).setUp() self.fb = FizzBuzz.FizzBuzz() print "setUp TestFizzBuzzMocked" @@ -17,23 +18,22 @@ def tearDown(self): self.fb = None def test_report(self): - pass - - - + #create mock + mockFileProvider = self.mock() + mockFileWrapper = self.mockFileProvider('report.txt', 'w') + #replay + self.replay() + #Call the report method + numbers=range(100) + FizzBuzz.report(self.numbers,self.mockFileWrapper) - - - - - - + if __name__ == "__main__": From c226d36fb72a9ca2879412304aa9290e2d25df4c Mon Sep 17 00:00:00 2001 From: maheshmakude Date: Wed, 27 Jun 2012 13:27:34 +0530 Subject: [PATCH 6/6] Update master --- TestFizzBuzzStubbed.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/TestFizzBuzzStubbed.py b/TestFizzBuzzStubbed.py index 096d2b6..7754a43 100644 --- a/TestFizzBuzzStubbed.py +++ b/TestFizzBuzzStubbed.py @@ -25,7 +25,20 @@ """ class MyStub(object): - pass + def __init__(self): + self.openflag=False + self.values=[] # create empty list + + def open(self): + self.openflag = True #"open fake file" + + def write(self,msg): + self.values.append(msg) # append values to list + + def close(): + self.openflag = False # close fake "file" + +