MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_specials

Method test_specials

Lib/test/test_descr.py:2198–2294  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2196 self.assertRaises(MyException, runner, X())
2197
2198 def test_specials(self):
2199 # Testing special operators...
2200 # Test operators like __hash__ for which a built-in default exists
2201
2202 # Test the default behavior for static classes
2203 class C(object):
2204 def __getitem__(self, i):
2205 if 0 <= i < 10: return i
2206 raise IndexError
2207 c1 = C()
2208 c2 = C()
2209 self.assertFalse(not c1)
2210 self.assertNotEqual(id(c1), id(c2))
2211 hash(c1)
2212 hash(c2)
2213 self.assertEqual(c1, c1)
2214 self.assertTrue(c1 != c2)
2215 self.assertFalse(c1 != c1)
2216 self.assertFalse(c1 == c2)
2217 # Note that the module name appears in str/repr, and that varies
2218 # depending on whether this test is run standalone or from a framework.
2219 self.assertGreaterEqual(str(c1).find('C object at '), 0)
2220 self.assertEqual(str(c1), repr(c1))
2221 self.assertNotIn(-1, c1)
2222 for i in range(10):
2223 self.assertIn(i, c1)
2224 self.assertNotIn(10, c1)
2225 # Test the default behavior for dynamic classes
2226 class D(object):
2227 def __getitem__(self, i):
2228 if 0 <= i < 10: return i
2229 raise IndexError
2230 d1 = D()
2231 d2 = D()
2232 self.assertFalse(not d1)
2233 self.assertNotEqual(id(d1), id(d2))
2234 hash(d1)
2235 hash(d2)
2236 self.assertEqual(d1, d1)
2237 self.assertNotEqual(d1, d2)
2238 self.assertFalse(d1 != d1)
2239 self.assertFalse(d1 == d2)
2240 # Note that the module name appears in str/repr, and that varies
2241 # depending on whether this test is run standalone or from a framework.
2242 self.assertGreaterEqual(str(d1).find('D object at '), 0)
2243 self.assertEqual(str(d1), repr(d1))
2244 self.assertNotIn(-1, d1)
2245 for i in range(10):
2246 self.assertIn(i, d1)
2247 self.assertNotIn(10, d1)
2248 # Test overridden behavior
2249 class Proxy(object):
2250 def __init__(self, x):
2251 self.x = x
2252 def __bool__(self):
2253 return not not self.x
2254 def __hash__(self):
2255 return hash(self.x)

Callers

nothing calls this directly

Calls 15

idFunction · 0.85
hashFunction · 0.85
strFunction · 0.85
reprFunction · 0.85
assertFalseMethod · 0.80
assertNotEqualMethod · 0.80
assertTrueMethod · 0.80
assertGreaterEqualMethod · 0.80
assertNotInMethod · 0.80
assertInMethod · 0.80
CClass · 0.70
DClass · 0.70

Tested by

no test coverage detected