[ create a new paste ] login | about

Link: http://codepad.org/NbhRLPex    [ raw code | output | fork ]

python@2ch - Python, pasted on Jun 12:
def hello(s):
  """
  >>> hello("world")
  'hello world'
  """
  return "hello " + s

import doctest; print '--(1)--'
doctest.testmod()

def hello(s):
  """
  >>> hello(10)
  100
  """
  return 10*2

print '--(2)--'
doctest.testmod()

def hello(s):
  """
  >>> hello(10)
  100
  >>> nyalo(20)
  400
  """
  return s**2

print '--(3)--'
doctest.testmod()

def hello(s):
  """
  >>> hello(10)
  100
  >>> hello(20)
  400
  """
  s**2

print '--(4)--'
doctest.testmod()

def hello(s):
  """
  >>> hello(10)
  100
  >>> hello(20)
  400
  """
  return s**2

print '--(5)--'
doctest.testmod()


Output:
--(1)--
--(2)--
**********************************************************************
Line 13, in __main__.hello
Failed example:
    hello(10)
Expected:
    100
Got:
    20
**********************************************************************
1 items had failures:
   1 of   1 in __main__.hello
***Test Failed*** 1 failures.
*** DocTestRunner.merge: '__main__.hello' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.
--(3)--
**********************************************************************
Line 25, in __main__.hello
Failed example:
    nyalo(20)
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.5/doctest.py", line 1212, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__.hello[1]>", line 1, in <module>
        nyalo(20)
    NameError: name 'nyalo' is not defined
**********************************************************************
1 items had failures:
   1 of   2 in __main__.hello
***Test Failed*** 1 failures.
*** DocTestRunner.merge: '__main__.hello' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.
--(4)--
**********************************************************************
Line 35, in __main__.hello
Failed example:
    hello(10)
Expected:
    100
Got nothing
**********************************************************************
Line 37, in __main__.hello
Failed example:
    hello(20)
Expected:
    400
Got nothing
**********************************************************************
1 items had failures:
   2 of   2 in __main__.hello
***Test Failed*** 2 failures.
*** DocTestRunner.merge: '__main__.hello' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.
--(5)--
*** DocTestRunner.merge: '__main__.hello' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.


Create a new paste based on this one


Comments: