From dce252352b78b8077ae95211ba7c30578d97245c Mon Sep 17 00:00:00 2001 From: sudhansumishra Date: Tue, 26 Jun 2012 18:40:46 +0530 Subject: [PATCH 1/5] Update master --- FizzBuzz.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/FizzBuzz.py b/FizzBuzz.py index 00b6ebd..dced480 100644 --- a/FizzBuzz.py +++ b/FizzBuzz.py @@ -1,6 +1,7 @@ """ Q1. Why is the report method untestable ? [2 pts] - +......... +report_file open and path is external collaborative (platform and system environment dependent) which is handled in the function so it is untestable @@ -10,27 +11,46 @@ """ class FizzBuzz(object): - def report(self, numbers): - report_file = open('c:/temp/fizzbuzz_report.txt', 'w') + 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 + + msg += "buzz " + + fizzbuzz_found = True if fizzbuzz_found: - report_file.write(msg + "\n") - report_file.close() + file_handle.write(msg + "\n") -if "__main__" == __name__: - fb = FizzBuzz() - fb.report(range(100)) + + + + + + +if "__main__" == __name__: + + fb = FizzBuzz() + + file_handle = open('temp.txt', 'w') # can create open wrapper + + fb.report(range(100), file_handle) + + file_handle.close() + From eab65300ffa1642547235d54d0e8a2d16be81b6b Mon Sep 17 00:00:00 2001 From: sudhansumishra Date: Tue, 26 Jun 2012 18:42:16 +0530 Subject: [PATCH 2/5] Update master --- TestFizzBuzzStubbed.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/TestFizzBuzzStubbed.py b/TestFizzBuzzStubbed.py index 78ee454..7e52383 100644 --- a/TestFizzBuzzStubbed.py +++ b/TestFizzBuzzStubbed.py @@ -3,12 +3,16 @@ import FizzBuzz """ Q3. What will be printed when we execute 'python FizzBuzzStubbed.py' ? [3 pts] - - - - - - +.............. + +setUpClass FizzBuzzStubbed +setup +test_report +teardown +.setup +test_report +teardown +.tearDownClass From 8f9c7d46248377e89360db2102699804bafa9860 Mon Sep 17 00:00:00 2001 From: sudhansumishra Date: Thu, 28 Jun 2012 11:50:27 +0530 Subject: [PATCH 3/5] Update master --- TestFizzBuzzMocked.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/TestFizzBuzzMocked.py b/TestFizzBuzzMocked.py index 6f1d0d5..331af1b 100644 --- a/TestFizzBuzzMocked.py +++ b/TestFizzBuzzMocked.py @@ -17,8 +17,16 @@ 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 with mocked filewrapper + numbers=range(100) + FizzBuzz.report(self.numbers,self.mockFileWrapper) + #verify + self.verify() From 17d915e6d5ae1669d67a85aa52e9a5a0e3dcfb40 Mon Sep 17 00:00:00 2001 From: sudhansumishra Date: Thu, 28 Jun 2012 11:52:13 +0530 Subject: [PATCH 4/5] Update master --- TestFizzBuzzStubbed.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/TestFizzBuzzStubbed.py b/TestFizzBuzzStubbed.py index 7e52383..8c7b19f 100644 --- a/TestFizzBuzzStubbed.py +++ b/TestFizzBuzzStubbed.py @@ -21,7 +21,19 @@ """ class MyStub(object): - pass + def __init__(self, values) + self.flag = False + self.values = [] + + def open(self) + self.flag = True + + def write(self,msg) + self.values.append(msg) + + def close(self) + self.flag = False + From d828a5a2306409c12bc3799b411c5bc4c5ad5de7 Mon Sep 17 00:00:00 2001 From: sudhansumishra Date: Thu, 28 Jun 2012 11:52:50 +0530 Subject: [PATCH 5/5] Update master --- TestFizzBuzzStubbed.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/TestFizzBuzzStubbed.py b/TestFizzBuzzStubbed.py index 8c7b19f..a0a451b 100644 --- a/TestFizzBuzzStubbed.py +++ b/TestFizzBuzzStubbed.py @@ -34,15 +34,7 @@ def write(self,msg) def close(self) self.flag = False - - - - - - - - - + class TestFizzBuzzStubbed(unittest.TestCase): @classmethod