/home/lnzliplg/www/test.tar
test_functiontestcase.py 0000644 00000012653 15173131026 0011544 0 ustar 00 import unittest
from unittest.test.support import LoggingResult
class Test_FunctionTestCase(unittest.TestCase):
# "Return the number of tests represented by the this test object. For
# TestCase instances, this will always be 1"
def test_countTestCases(self):
test = unittest.FunctionTestCase(lambda: None)
self.assertEqual(test.countTestCases(), 1)
# "When a setUp() method is defined, the test runner will run that method
# prior to each test. Likewise, if a tearDown() method is defined, the
# test runner will invoke that method after each test. In the example,
# setUp() was used to create a fresh sequence for each test."
#
# Make sure the proper call order is maintained, even if setUp() raises
# an exception.
def test_run_call_order__error_in_setUp(self):
events = []
result = LoggingResult(events)
def setUp():
events.append('setUp')
raise RuntimeError('raised by setUp')
def test():
events.append('test')
def tearDown():
events.append('tearDown')
expected = ['startTest', 'setUp', 'addError', 'stopTest']
unittest.FunctionTestCase(test, setUp, tearDown).run(result)
self.assertEqual(events, expected)
# "When a setUp() method is defined, the test runner will run that method
# prior to each test. Likewise, if a tearDown() method is defined, the
# test runner will invoke that method after each test. In the example,
# setUp() was used to create a fresh sequence for each test."
#
# Make sure the proper call order is maintained, even if the test raises
# an error (as opposed to a failure).
def test_run_call_order__error_in_test(self):
events = []
result = LoggingResult(events)
def setUp():
events.append('setUp')
def test():
events.append('test')
raise RuntimeError('raised by test')
def tearDown():
events.append('tearDown')
expected = ['startTest', 'setUp', 'test', 'addError', 'tearDown',
'stopTest']
unittest.FunctionTestCase(test, setUp, tearDown).run(result)
self.assertEqual(events, expected)
# "When a setUp() method is defined, the test runner will run that method
# prior to each test. Likewise, if a tearDown() method is defined, the
# test runner will invoke that method after each test. In the example,
# setUp() was used to create a fresh sequence for each test."
#
# Make sure the proper call order is maintained, even if the test signals
# a failure (as opposed to an error).
def test_run_call_order__failure_in_test(self):
events = []
result = LoggingResult(events)
def setUp():
events.append('setUp')
def test():
events.append('test')
self.fail('raised by test')
def tearDown():
events.append('tearDown')
expected = ['startTest', 'setUp', 'test', 'addFailure', 'tearDown',
'stopTest']
unittest.FunctionTestCase(test, setUp, tearDown).run(result)
self.assertEqual(events, expected)
# "When a setUp() method is defined, the test runner will run that method
# prior to each test. Likewise, if a tearDown() method is defined, the
# test runner will invoke that method after each test. In the example,
# setUp() was used to create a fresh sequence for each test."
#
# Make sure the proper call order is maintained, even if tearDown() raises
# an exception.
def test_run_call_order__error_in_tearDown(self):
events = []
result = LoggingResult(events)
def setUp():
events.append('setUp')
def test():
events.append('test')
def tearDown():
events.append('tearDown')
raise RuntimeError('raised by tearDown')
expected = ['startTest', 'setUp', 'test', 'tearDown', 'addError',
'stopTest']
unittest.FunctionTestCase(test, setUp, tearDown).run(result)
self.assertEqual(events, expected)
# "Return a string identifying the specific test case."
#
# Because of the vague nature of the docs, I'm not going to lock this
# test down too much. Really all that can be asserted is that the id()
# will be a string (either 8-byte or unicode -- again, because the docs
# just say "string")
def test_id(self):
test = unittest.FunctionTestCase(lambda: None)
self.assertIsInstance(test.id(), basestring)
# "Returns a one-line description of the test, or None if no description
# has been provided. The default implementation of this method returns
# the first line of the test method's docstring, if available, or None."
def test_shortDescription__no_docstring(self):
test = unittest.FunctionTestCase(lambda: None)
self.assertEqual(test.shortDescription(), None)
# "Returns a one-line description of the test, or None if no description
# has been provided. The default implementation of this method returns
# the first line of the test method's docstring, if available, or None."
def test_shortDescription__singleline_docstring(self):
desc = "this tests foo"
test = unittest.FunctionTestCase(lambda: None, description=desc)
self.assertEqual(test.shortDescription(), "this tests foo")
if __name__ == '__main__':
unittest.main()
test_assertions.pyo 0000644 00000032172 15173131027 0010533 0 ustar 00 �
{fc @ sg d d l Z d d l Z d e j f d � � YZ d e j f d � � YZ e d k rc e j � n d S( i����Nt Test_Assertionsc B s, e Z d � Z d � Z d � Z d � Z RS( c C sH | j d d � | j d d � | j | j | j d d � | j | j | j d d � | j d d d d �| j | j | j d d d d �| j d d d d �| j d d d d �| j | j | j d d
d d �| j | j | j d d d d �| j t d
� t d
� � | j | j | j t d
� t d
� � d S( Ng�1� �?g �?g��� �?g�������?t placesi i g�������?y �������?t infy�������?�������?y�������?�������?y�������?�������?y�������?�������?( t assertAlmostEqualt assertNotAlmostEqualt assertRaisest failureExceptiont float( t self( ( s5 /usr/lib64/python2.7/unittest/test/test_assertions.pyt test_AlmostEqual s$ c C s� | j d d d d �| j d d d d �| j d d d d �| j d d d d �| j d d d d �| j | j | j d d d d �| j | j | j d d d d �| j | j | j d d d d �| j t | j d d d d d d �| j t | j d d d d d d �t j j � } | t j d d � } | j | | d t j d d
� �| j | | d t j d d � �d S( Ng�������?g �?t deltag �?g�������?R i t secondsi
i i ( R R R R t TypeErrort datetimet nowt timedelta( R t firstt second( ( s5 /usr/lib64/python2.7/unittest/test/test_assertions.pyt test_AmostEqualWithDelta s* c C s� d � } | j t | t � | j t | t d � � y | j t d � � Wn) | j k
rw } | j d | j � n X| j d � y | j t | t � Wn t k
r� n X| j d � | j t � �* } y
t � Wn t k
r� } � n XWd QX| j | j | � | j t � � t d � � Wd QXy | j t � � Wd QXWn) | j k
rr} | j d | j � n X| j d � y | j t � � t � Wd QXWn t k
r�n X| j d � d S( Nc S s
| � d S( N( ( t e( ( s5 /usr/lib64/python2.7/unittest/test/test_assertions.pyt _raise: s t keyc S s d S( N( t None( ( ( s5 /usr/lib64/python2.7/unittest/test/test_assertions.pyt <lambda>? t s KeyError not raiseds assertRaises() didn't fails0 assertRaises() didn't let exception pass through(
R t KeyErrorR t assertInt argst failt
ValueErrort Exceptiont assertIst exception( R R R t cm( ( s5 /usr/lib64/python2.7/unittest/test/test_assertions.pyt test_assertRaises9 sB
c C s | j d d � y | j d d d � WnD | j k
rm } | j d | j d � | j d | j d � n X| j d � d S( Ns Ala ma kotas r+s k.tt Messages 'kot'i s* assertNotRegexpMatches should have failed.( t assertNotRegexpMatchesR R R R ( R R ( ( s5 /usr/lib64/python2.7/unittest/test/test_assertions.pyt testAssertNotRegexpMatchesb s ( t __name__t
__module__R R R"