Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_errno.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 78ca8c2561db |
| children | 6768b2350c57 |
| 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: |
|
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
|
17 self.assert_(hasattr(errno, error_code), |
|
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(): |
|
45841
6fc6a806784f
Add some info to the failure messages
Neal Norwitz <nnorwitz@gmail.com>
parents:
45839
diff
changeset
|
23 self.assert_(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(): |
|
45841
6fc6a806784f
Add some info to the failure messages
Neal Norwitz <nnorwitz@gmail.com>
parents:
45839
diff
changeset
|
31 self.assert_(getattr(errno, attribute) in errno.errorcode, |
|
6fc6a806784f
Add some info to the failure messages
Neal Norwitz <nnorwitz@gmail.com>
parents:
45839
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() |
