annotate Lib/test/test_errno.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 17891566a478
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4735
4a3f45b3471a Added test_errno to the test suite
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
1 #! /usr/bin/env python
4a3f45b3471a Added test_errno to the test suite
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
2 """Test the errno module
4a3f45b3471a Added test_errno to the test suite
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
3 Roger E. Masse
4a3f45b3471a Added test_errno to the test suite
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
4 """
4740
062e88608b55 Revised test for errno ala bwarsaw's testing paradigm.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4735
diff changeset
5
062e88608b55 Revised test for errno ala bwarsaw's testing paradigm.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4735
diff changeset
6 import errno
45821
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
7 from test import test_support
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
8 import unittest
4735
4a3f45b3471a Added test_errno to the test suite
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff changeset
9
45855
78ca8c2561db Fix test_errno to only check for error numbers that are defined by Standard C.
Brett Cannon <bcannon@gmail.com>
parents: 45848
diff changeset
10 std_c_errors = frozenset(['EDOM', 'ERANGE'])
45821
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
11
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
12 class ErrnoAttributeTests(unittest.TestCase):
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
13
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
14 def test_for_improper_attributes(self):
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
15 # No unexpected attributes should be on the module.
45855
78ca8c2561db Fix test_errno to only check for error numbers that are defined by Standard C.
Brett Cannon <bcannon@gmail.com>
parents: 45848
diff changeset
16 for error_code in std_c_errors:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45855
diff changeset
17 self.assertTrue(hasattr(errno, error_code),
45855
78ca8c2561db Fix test_errno to only check for error numbers that are defined by Standard C.
Brett Cannon <bcannon@gmail.com>
parents: 45848
diff changeset
18 "errno is missing %s" % error_code)
45821
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
19
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
20 def test_using_errorcode(self):
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
21 # Every key value in errno.errorcode should be on the module.
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
22 for value in errno.errorcode.itervalues():
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 45855
diff changeset
23 self.assertTrue(hasattr(errno, value), 'no %s attr in errno' % value)
45821
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
24
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
25
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
26 class ErrorcodeTests(unittest.TestCase):
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
27
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
28 def test_attributes_in_errorcode(self):
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
29 for attribute in errno.__dict__.iterkeys():
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
30 if attribute.isupper():
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 55002
diff changeset
31 self.assertIn(getattr(errno, attribute), errno.errorcode,
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 55002
diff changeset
32 'no %s attr in errno.errorcode' % attribute)
45821
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
33
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
34
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
35 def test_main():
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
36 test_support.run_unittest(ErrnoAttributeTests, ErrorcodeTests)
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
37
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
38
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
39 if __name__ == '__main__':
4dabd907187e test_errno was a no-op test; now it actually tests things and uses unittest.
Brett Cannon <bcannon@gmail.com>
parents: 30723
diff changeset
40 test_main()