(self)
| 2292 | self.assertRaises(MyException, runner, X()) |
| 2293 | |
| 2294 | def test_specials(self): |
| 2295 | # Testing special operators... |
| 2296 | # Test operators like __hash__ for which a built-in default exists |
| 2297 | |
| 2298 | # Test the default behavior for static classes |
| 2299 | class C(object): |
| 2300 | def __getitem__(self, i): |
| 2301 | if 0 <= i < 10: return i |
| 2302 | raise IndexError |
| 2303 | c1 = C() |
| 2304 | c2 = C() |
| 2305 | self.assertFalse(not c1) |
| 2306 | self.assertNotEqual(id(c1), id(c2)) |
| 2307 | hash(c1) |
| 2308 | hash(c2) |
| 2309 | self.assertEqual(c1, c1) |
| 2310 | self.assertTrue(c1 != c2) |
| 2311 | self.assertFalse(c1 != c1) |
| 2312 | self.assertFalse(c1 == c2) |
| 2313 | # Note that the module name appears in str/repr, and that varies |
| 2314 | # depending on whether this test is run standalone or from a framework. |
| 2315 | self.assertGreaterEqual(str(c1).find('C object at '), 0) |
| 2316 | self.assertEqual(str(c1), repr(c1)) |
| 2317 | self.assertNotIn(-1, c1) |
| 2318 | for i in range(10): |
| 2319 | self.assertIn(i, c1) |
| 2320 | self.assertNotIn(10, c1) |
| 2321 | # Test the default behavior for dynamic classes |
| 2322 | class D(object): |
| 2323 | def __getitem__(self, i): |
| 2324 | if 0 <= i < 10: return i |
| 2325 | raise IndexError |
| 2326 | d1 = D() |
| 2327 | d2 = D() |
| 2328 | self.assertFalse(not d1) |
| 2329 | self.assertNotEqual(id(d1), id(d2)) |
| 2330 | hash(d1) |
| 2331 | hash(d2) |
| 2332 | self.assertEqual(d1, d1) |
| 2333 | self.assertNotEqual(d1, d2) |
| 2334 | self.assertFalse(d1 != d1) |
| 2335 | self.assertFalse(d1 == d2) |
| 2336 | # Note that the module name appears in str/repr, and that varies |
| 2337 | # depending on whether this test is run standalone or from a framework. |
| 2338 | self.assertGreaterEqual(str(d1).find('D object at '), 0) |
| 2339 | self.assertEqual(str(d1), repr(d1)) |
| 2340 | self.assertNotIn(-1, d1) |
| 2341 | for i in range(10): |
| 2342 | self.assertIn(i, d1) |
| 2343 | self.assertNotIn(10, d1) |
| 2344 | # Test overridden behavior |
| 2345 | class Proxy(object): |
| 2346 | def __init__(self, x): |
| 2347 | self.x = x |
| 2348 | def __bool__(self): |
| 2349 | return not not self.x |
| 2350 | def __hash__(self): |
| 2351 | return hash(self.x) |
nothing calls this directly
no test coverage detected