Skip to content

Commit 986c058

Browse files
committed
added somepython files and presentation
1 parent 1643953 commit 986c058

6 files changed

Lines changed: 86 additions & 2 deletions

File tree

README

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This project contains a series of Python examples to help someone new to Python
44

55
I am listing the order in which you may want to read these examples. The order below starts with simple concepts, moving on to more advanced ones.
66

7+
**Introduction To Python**
8+
79
- python_strings.py
810
- python_numbers.py
911
- python_booleans.py
@@ -20,4 +22,18 @@ I am listing the order in which you may want to read these examples. The order b
2022
- python_modules.py
2123
- python_os_module.py
2224
- python_star_args_and_kwargs.py
23-
- python_objects.py
25+
- python_objects.py
26+
27+
**TDD With Python**
28+
29+
Slides for introduction to TDD With Python
30+
31+
Code Samples
32+
33+
- write_user_details.py
34+
- test_write_user_details.py
35+
- test_write_user_details_istub.py
36+
- test_write_user_details_iostub.py
37+
- write_user_details_di.py
38+
- test_write_user_details_mock.py
39+

tdd/TDDWithPython.odp

70.7 KB
Binary file not shown.

tdd/all_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import unittest
2+
import test_write_user_details
3+
import test_write_user_details_istub
4+
5+
suite1 = unittest.TestLoader().loadTestsFromTestCase(test_write_user_details.TestUserDetails)
6+
suite1.addTests(unittest.TestLoader().loadTestsFromTestCase(test_write_user_details_istub.TestUserDetails))
7+
8+
unittest.TextTestRunner(verbosity=2).run(suite1)

tdd/tdd_python_plan.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
There are two ways to us the PyMock framework. As standalone or as a unittest testcase. If used in standalone mode, we need to create a controller, and when used as a unittest testcase, the controller is created automatically for us.
2+
3+
Stana
4+
5+
6+
=============================================
7+
1. Explain and run write_user_details.py
8+
2. Explaina and Test the output file with test_write_user_details.py
9+
3. Explain the drawbacks of the plumbing we have to do with this type of test. Explain why we need to automate the accepting of UserInput
10+
4. Explain and run test_write_user_details_istub.py and show it's benefits. This is a one step process. However, we are still writing to a file. This too is not good.
11+
5. Explain and run test_write_user_details_iostub.py
12+
6. This is good but we cannot wrote stubs for everything in a large project. It will take too long to do it
13+
7. Here is where mocking comes in. Explain and run test_write_user_details_mock.py
14+
8. We cannot manually run so many test cases. Here is where test suites come in the picture
15+
9. unittest also supports test discovery
16+
python -m unittest discover
17+
18+
19+
class MyTestCase(unittest.TestCase):
20+
21+
@unittest.skip("demonstrating skipping")
22+
def test_nothing(self):
23+
self.fail("shouldn't happen")
24+
25+
@unittest.skipIf(mylib.__version__ < (1, 3),
26+
"not supported in this library version")
27+
def test_format(self):
28+
# Tests that work for only a certain version of the library.
29+
pass
30+
31+
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
32+
def test_windows_support(self):
33+
# windows specific testing code
34+
pass
35+
36+
@unittest.skip("showing class skipping")
37+
class MySkippedTestCase(unittest.TestCase):
38+
def test_not_run(self):
39+
pass
40+
41+
class ExpectedFailureTestCase(unittest.TestCase):
42+
@unittest.expectedFailure
43+
def test_fail(self):
44+
self.assertEqual(1, 0, "broken")
45+
46+
Resources:
47+
==========
48+
Python unittest http://docs.python.org/library/unittest.html

tdd/test_write_user_details.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
class TestUserDetails(unittest.TestCase):
44

5+
def setUp(self):
6+
super(TestUserDetails, self).setUp()
7+
8+
9+
def tearDown(self):
10+
super(TestUserDetails, self).tearDown()
11+
12+
513
def test_output_file_contents(self):
614
fp = open('Priyanka.txt')
715
name = fp.readline()

tdd/write_user_details.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ def accept_and_write():
1212
fp.write("Name : %s\n" % name)
1313
fp.write("Age : %s\n" % age)
1414
fp.write("City : %s\n" % city)
15-
fp.close()
15+
fp.close()
16+
17+
if __name__ == "__main__":
18+
accept_and_write()
19+

0 commit comments

Comments
 (0)