(self)
| 50 | self.assertEqual(True, copy.copy(True)) |
| 51 | |
| 52 | def test_extension_registry(self): |
| 53 | mod, func, code = 'junk1 ', ' junk2', 0xabcd |
| 54 | e = ExtensionSaver(code) |
| 55 | try: |
| 56 | # Shouldn't be in registry now. |
| 57 | self.assertRaises(ValueError, copyreg.remove_extension, |
| 58 | mod, func, code) |
| 59 | copyreg.add_extension(mod, func, code) |
| 60 | # Should be in the registry. |
| 61 | self.assertTrue(copyreg._extension_registry[mod, func] == code) |
| 62 | self.assertTrue(copyreg._inverted_registry[code] == (mod, func)) |
| 63 | # Shouldn't be in the cache. |
| 64 | self.assertNotIn(code, copyreg._extension_cache) |
| 65 | # Redundant registration should be OK. |
| 66 | copyreg.add_extension(mod, func, code) # shouldn't blow up |
| 67 | # Conflicting code. |
| 68 | self.assertRaises(ValueError, copyreg.add_extension, |
| 69 | mod, func, code + 1) |
| 70 | self.assertRaises(ValueError, copyreg.remove_extension, |
| 71 | mod, func, code + 1) |
| 72 | # Conflicting module name. |
| 73 | self.assertRaises(ValueError, copyreg.add_extension, |
| 74 | mod[1:], func, code ) |
| 75 | self.assertRaises(ValueError, copyreg.remove_extension, |
| 76 | mod[1:], func, code ) |
| 77 | # Conflicting function name. |
| 78 | self.assertRaises(ValueError, copyreg.add_extension, |
| 79 | mod, func[1:], code) |
| 80 | self.assertRaises(ValueError, copyreg.remove_extension, |
| 81 | mod, func[1:], code) |
| 82 | # Can't remove one that isn't registered at all. |
| 83 | if code + 1 not in copyreg._inverted_registry: |
| 84 | self.assertRaises(ValueError, copyreg.remove_extension, |
| 85 | mod[1:], func[1:], code + 1) |
| 86 | |
| 87 | finally: |
| 88 | e.restore() |
| 89 | |
| 90 | # Shouldn't be there anymore. |
| 91 | self.assertNotIn((mod, func), copyreg._extension_registry) |
| 92 | # The code *may* be in copyreg._extension_registry, though, if |
| 93 | # we happened to pick on a registered code. So don't check for |
| 94 | # that. |
| 95 | |
| 96 | # Check valid codes at the limits. |
| 97 | for code in 1, 0x7fffffff: |
| 98 | e = ExtensionSaver(code) |
| 99 | try: |
| 100 | copyreg.add_extension(mod, func, code) |
| 101 | copyreg.remove_extension(mod, func, code) |
| 102 | finally: |
| 103 | e.restore() |
| 104 | |
| 105 | # Ensure invalid codes blow up. |
| 106 | for code in -1, 0, 0x80000000: |
| 107 | self.assertRaises(ValueError, copyreg.add_extension, |
| 108 | mod, func, code) |
| 109 |
nothing calls this directly
no test coverage detected