From 910b9b8f019aa4fb5b21689fdbaa09a53ee93f67 Mon Sep 17 00:00:00 2001 From: Dhananjay-gholap Date: Tue, 26 Jun 2012 18:07:16 +0530 Subject: [PATCH 1/5] added ans for qu1 --- FizzBuzz.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/FizzBuzz.py b/FizzBuzz.py index 00b6ebd..d2673c6 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -1,11 +1,17 @@ """ 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. 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 """ From 5b9bffeb678e8984d51e2645e5994336c8544e62 Mon Sep 17 00:00:00 2001 From: Dhananjay-gholap Date: Tue, 26 Jun 2012 18:09:15 +0530 Subject: [PATCH 2/5] Added ans for Qu 3 --- TestFizzBuzzStubbed.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/TestFizzBuzzStubbed.py b/TestFizzBuzzStubbed.py index 78ee454..8a63207 100644 --- a/TestFizzBuzzStubbed.py +++ b/TestFizzBuzzStubbed.py @@ -4,10 +4,15 @@ """ Q3. What will be printed when we execute 'python FizzBuzzStubbed.py' ? [3 pts] - - - - +Ans:_ +setUpClass FizzBuzzStubbed +setup +test_report +teardown +.setup +test_report +teardown +.tearDownClass From 6f55c15141bfa15a3e3905806c1403d23eb4e6ac Mon Sep 17 00:00:00 2001 From: Dhananjay-gholap Date: Tue, 26 Jun 2012 18:39:47 +0530 Subject: [PATCH 3/5] updated ans for qu2 --- FizzBuzz.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/FizzBuzz.py b/FizzBuzz.py index d2673c6..b42e713 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 3ce242e0286e1f2e5072b14fd14e838876c169a7 Mon Sep 17 00:00:00 2001 From: Dhananjay-gholap Date: Wed, 27 Jun 2012 15:00:31 +0530 Subject: [PATCH 4/5] Update master --- TestFizzBuzzMocked.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/TestFizzBuzzMocked.py b/TestFizzBuzzMocked.py index 6f1d0d5..b1fe3f8 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,11 +18,20 @@ 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__": + unittest.main() @@ -36,5 +46,4 @@ def test_report(self): -if __name__ == "__main__": - unittest.main() + From fa5352e64924f48b9763c08bb53867c5a4ae84ad Mon Sep 17 00:00:00 2001 From: Dhananjay-gholap Date: Wed, 27 Jun 2012 15:02:10 +0530 Subject: [PATCH 5/5] Update master --- TestFizzBuzzStubbed.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/TestFizzBuzzStubbed.py b/TestFizzBuzzStubbed.py index 8a63207..0abc2dd 100644 --- a/TestFizzBuzzStubbed.py +++ b/TestFizzBuzzStubbed.py @@ -22,16 +22,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" - - - - class TestFizzBuzzStubbed(unittest.TestCase): @classmethod