Welcome, guest | Sign In | My Account | Store | Cart
def function(a, b):
    # description and test
    """Adds an integer and a float and returns a str.
    >>> function(1, 3.0)
    '4.0'
    """

    # precondition
    assert isinstance(a, int), 'a argument should be int'
    assert isinstance(b, float), 'b argument should be float'

    #implementation
    try:
        c = str(a + b)
        return c

    # postcondition
    finally:
        assert isinstance(c, str), 'c variable should be str'


# run all docstring test on debug mode
if __debug__:
    import doctest
    doctest.testmod()


if __name__ == '__main__':
    # do something
    pass

Diff to Previous Revision

--- revision 1 2013-11-05 19:23:58
+++ revision 2 2013-11-05 20:50:30
@@ -4,6 +4,7 @@
     >>> function(1, 3.0)
     '4.0'
     """
+
     # precondition
     assert isinstance(a, int), 'a argument should be int'
     assert isinstance(b, float), 'b argument should be float'
@@ -15,14 +16,15 @@
 
     # postcondition
     finally:
-        assert isinstance(c, str), 'c var should be str'
+        assert isinstance(c, str), 'c variable should be str'
+
+
+# run all docstring test on debug mode
+if __debug__:
+    import doctest
+    doctest.testmod()
 
 
 if __name__ == '__main__':
-    # run all docstring test on debug mode
-    if __debug__:
-        import doctest
-        doctest.testmod()
-    else:
-        # do something
-        pass
+    # do something
+    pass

History