+++ /dev/null
-import unittest\r
-\r
-from .support import LoggingResult\r
-\r
-\r
-class Test_FunctionTestCase(unittest.TestCase):\r
-\r
- # "Return the number of tests represented by the this test object. For\r
- # TestCase instances, this will always be 1"\r
- def test_countTestCases(self):\r
- test = unittest.FunctionTestCase(lambda: None)\r
-\r
- self.assertEqual(test.countTestCases(), 1)\r
-\r
- # "When a setUp() method is defined, the test runner will run that method\r
- # prior to each test. Likewise, if a tearDown() method is defined, the\r
- # test runner will invoke that method after each test. In the example,\r
- # setUp() was used to create a fresh sequence for each test."\r
- #\r
- # Make sure the proper call order is maintained, even if setUp() raises\r
- # an exception.\r
- def test_run_call_order__error_in_setUp(self):\r
- events = []\r
- result = LoggingResult(events)\r
-\r
- def setUp():\r
- events.append('setUp')\r
- raise RuntimeError('raised by setUp')\r
-\r
- def test():\r
- events.append('test')\r
-\r
- def tearDown():\r
- events.append('tearDown')\r
-\r
- expected = ['startTest', 'setUp', 'addError', 'stopTest']\r
- unittest.FunctionTestCase(test, setUp, tearDown).run(result)\r
- self.assertEqual(events, expected)\r
-\r
- # "When a setUp() method is defined, the test runner will run that method\r
- # prior to each test. Likewise, if a tearDown() method is defined, the\r
- # test runner will invoke that method after each test. In the example,\r
- # setUp() was used to create a fresh sequence for each test."\r
- #\r
- # Make sure the proper call order is maintained, even if the test raises\r
- # an error (as opposed to a failure).\r
- def test_run_call_order__error_in_test(self):\r
- events = []\r
- result = LoggingResult(events)\r
-\r
- def setUp():\r
- events.append('setUp')\r
-\r
- def test():\r
- events.append('test')\r
- raise RuntimeError('raised by test')\r
-\r
- def tearDown():\r
- events.append('tearDown')\r
-\r
- expected = ['startTest', 'setUp', 'test', 'addError', 'tearDown',\r
- 'stopTest']\r
- unittest.FunctionTestCase(test, setUp, tearDown).run(result)\r
- self.assertEqual(events, expected)\r
-\r
- # "When a setUp() method is defined, the test runner will run that method\r
- # prior to each test. Likewise, if a tearDown() method is defined, the\r
- # test runner will invoke that method after each test. In the example,\r
- # setUp() was used to create a fresh sequence for each test."\r
- #\r
- # Make sure the proper call order is maintained, even if the test signals\r
- # a failure (as opposed to an error).\r
- def test_run_call_order__failure_in_test(self):\r
- events = []\r
- result = LoggingResult(events)\r
-\r
- def setUp():\r
- events.append('setUp')\r
-\r
- def test():\r
- events.append('test')\r
- self.fail('raised by test')\r
-\r
- def tearDown():\r
- events.append('tearDown')\r
-\r
- expected = ['startTest', 'setUp', 'test', 'addFailure', 'tearDown',\r
- 'stopTest']\r
- unittest.FunctionTestCase(test, setUp, tearDown).run(result)\r
- self.assertEqual(events, expected)\r
-\r
- # "When a setUp() method is defined, the test runner will run that method\r
- # prior to each test. Likewise, if a tearDown() method is defined, the\r
- # test runner will invoke that method after each test. In the example,\r
- # setUp() was used to create a fresh sequence for each test."\r
- #\r
- # Make sure the proper call order is maintained, even if tearDown() raises\r
- # an exception.\r
- def test_run_call_order__error_in_tearDown(self):\r
- events = []\r
- result = LoggingResult(events)\r
-\r
- def setUp():\r
- events.append('setUp')\r
-\r
- def test():\r
- events.append('test')\r
-\r
- def tearDown():\r
- events.append('tearDown')\r
- raise RuntimeError('raised by tearDown')\r
-\r
- expected = ['startTest', 'setUp', 'test', 'tearDown', 'addError',\r
- 'stopTest']\r
- unittest.FunctionTestCase(test, setUp, tearDown).run(result)\r
- self.assertEqual(events, expected)\r
-\r
- # "Return a string identifying the specific test case."\r
- #\r
- # Because of the vague nature of the docs, I'm not going to lock this\r
- # test down too much. Really all that can be asserted is that the id()\r
- # will be a string (either 8-byte or unicode -- again, because the docs\r
- # just say "string")\r
- def test_id(self):\r
- test = unittest.FunctionTestCase(lambda: None)\r
-\r
- self.assertIsInstance(test.id(), basestring)\r
-\r
- # "Returns a one-line description of the test, or None if no description\r
- # has been provided. The default implementation of this method returns\r
- # the first line of the test method's docstring, if available, or None."\r
- def test_shortDescription__no_docstring(self):\r
- test = unittest.FunctionTestCase(lambda: None)\r
-\r
- self.assertEqual(test.shortDescription(), None)\r
-\r
- # "Returns a one-line description of the test, or None if no description\r
- # has been provided. The default implementation of this method returns\r
- # the first line of the test method's docstring, if available, or None."\r
- def test_shortDescription__singleline_docstring(self):\r
- desc = "this tests foo"\r
- test = unittest.FunctionTestCase(lambda: None, description=desc)\r
-\r
- self.assertEqual(test.shortDescription(), "this tests foo")\r
-\r
-\r
-if __name__ == '__main__':\r
- unittest.main()\r