From f7e6556e13d0a890c66e250ff2f56350a9302d79 Mon Sep 17 00:00:00 2001 From: Vipul Kumar Date: Wed, 8 Sep 2021 22:06:26 +0530 Subject: [PATCH 1/3] [testing] Add missing output of the command Output of 'factorial.py' script is missing in "Factorial code" section. --- docs/testing.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/testing.rst b/docs/testing.rst index 931f5db..d21fc1c 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -73,6 +73,7 @@ Output :: $ python factorial.py 5 + 120 Which function to test ? ======================== From bff7dd8c4b7997b24af5e64621d71af98a71af2c Mon Sep 17 00:00:00 2001 From: Vipul Kumar Date: Thu, 9 Sep 2021 15:47:05 +0530 Subject: [PATCH 2/3] [testing] Close opened files after completion of work File is remained open even after completion of the work. --- docs/testing.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/testing.rst b/docs/testing.rst index d21fc1c..b9847b6 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -228,6 +228,7 @@ Here we have only one function *mount_details()* doing the parsing and printing print('(%s)' % ' '.join(words[3:-2])) else: print('') + fd.close() if __name__ == '__main__': @@ -258,6 +259,7 @@ Now we refactored the code and have one new function *parse_mounts* which we can else: res = (words[0],words[1],words[2]) result.append(res) + fd.close() return result def mount_details(): From ea1412d661a081cd97c8a252789d478deb819811 Mon Sep 17 00:00:00 2001 From: Vipul Kumar Date: Thu, 9 Sep 2021 15:52:01 +0530 Subject: [PATCH 3/3] [testing] Fix punctuations This commit contains following changes: - End a complete sentence with a period punctuation. - End a sentence with colon punctuation, if next sentence contains explanation of it. - Remove space between the word and comma punctuation. --- docs/testing.rst | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/testing.rst b/docs/testing.rst index b9847b6..ae5673a 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -11,7 +11,7 @@ If possible everything in our codebase, each and every function. But it depends as a choice of the developers. You can skip it if it is not practical to write a robust test. As `Nick Coghlan `_ said in a guest session -- *... with a solid test suite, you can make big changes, -confident that the externally visible behavior will remain the same* +confident that the externally visible behavior will remain the same*. To have effective tests, you should remember to write/split your code in smaller functions which can be tested separately. It is very easy to keep @@ -23,7 +23,7 @@ test cases. Unit testing ============= -A method by which individual units of source code. `Wikipedia `_ says +A method by which individual units of source code. `Wikipedia `_ says, *In computer programming, unit testing is a method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine if they are fit for use.* @@ -35,7 +35,7 @@ In Python we have ``unittest`` module to help us. Factorial code =============== -In this example we will write a file `factorial.py`. +In this example, we will write a file `factorial.py`: :: import sys @@ -69,7 +69,8 @@ In this example we will write a file `factorial.py`. main(int(sys.argv[1])) -Output +Output: + :: $ python factorial.py 5 @@ -127,7 +128,7 @@ which we want to test. A testcase is created by subclassing ``unittest.TestCase``. -Now open the test file and change *120* to *121* and see what happens :) +Now open the test file and change *120* to *121* and see what happens. :) Different assert statements @@ -163,7 +164,7 @@ Different assert statements Testing exceptions ================== -If we call ``div(0)`` in factorial.py , we can see if raises an exception. +If we call ``div(0)`` in factorial.py, we can see if raises an exception. We can also test these exceptions, like: @@ -171,7 +172,8 @@ We can also test these exceptions, like: self.assertRaises(ZeroDivisionError, div, 0) -Full code +Full code: + :: import unittest @@ -327,7 +329,7 @@ Test coverage Test coverage is a simple way to find untested parts of a codebase. It does not tell you how good your tests are. -In Python we already have a nice coverage tool to help us. You can install it in Fedora +In Python we already have a nice coverage tool to help us. You can install it in Fedora: ::