Skip to content

Commit 7fd2db5

Browse files
committed
Make types in test_int_convert more ~boring~ descriptive
1 parent 2092295 commit 7fd2db5

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

tests/test_builtin_casters.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -252,36 +252,36 @@ def test_integer_casting():
252252

253253

254254
def test_int_convert():
255-
class DeepThought(object):
255+
class Int(object):
256256
def __int__(self):
257257
return 42
258258

259-
class DoubleThought(object):
260-
def __int__(self):
261-
return 42
262-
263-
def __index__(self):
264-
return 0
265-
266-
class ShallowThought(object):
259+
class NotInt(object):
267260
pass
268261

269-
class FuzzyThought(object):
262+
class Float(object):
270263
def __float__(self):
271264
return 41.99999
272265

273-
class IndexedThought(object):
266+
class Index(object):
274267
def __index__(self):
275268
return 42
276269

277-
class TypeErrorThought(object):
270+
class IntAndIndex(object):
271+
def __int__(self):
272+
return 42
273+
274+
def __index__(self):
275+
return 0
276+
277+
class RaisingTypeErrorOnIndex(object):
278278
def __index__(self):
279279
raise TypeError
280280

281281
def __int__(self):
282282
return 42
283283

284-
class RaisingThought(object):
284+
class RaisingValueErrorOnIndex(object):
285285
def __index__(self):
286286
raise ValueError
287287

@@ -299,21 +299,21 @@ def cant_convert(v):
299299
assert convert(7) == 7
300300
assert noconvert(7) == 7
301301
cant_convert(3.14159)
302-
assert convert(DeepThought()) == 42
303-
requires_conversion(DeepThought())
304-
assert convert(DoubleThought()) == 0 # Fishy; `int(DoubleThought)` == 42
305-
assert noconvert(DoubleThought()) == 0
306-
cant_convert(ShallowThought())
307-
cant_convert(FuzzyThought())
302+
assert convert(Int()) == 42
303+
requires_conversion(Int())
304+
cant_convert(NotInt())
305+
cant_convert(Float())
308306

309307
# Before Python 3.8, `PyLong_AsLong` does not pick up on `obj.__index__`,
310308
# but pybind11 "backports" this behavior.
311-
assert convert(IndexedThought()) == 42
312-
assert noconvert(IndexedThought()) == 42
313-
assert convert(TypeErrorThought()) == 42
314-
requires_conversion(TypeErrorThought())
315-
assert convert(RaisingThought()) == 42
316-
requires_conversion(RaisingThought())
309+
assert convert(Index()) == 42
310+
assert noconvert(Index()) == 42
311+
assert convert(IntAndIndex()) == 0 # Fishy; `int(DoubleThought)` == 42
312+
assert noconvert(IntAndIndex()) == 0
313+
assert convert(RaisingTypeErrorOnIndex()) == 42
314+
requires_conversion(RaisingTypeErrorOnIndex())
315+
assert convert(RaisingValueErrorOnIndex()) == 42
316+
requires_conversion(RaisingValueErrorOnIndex())
317317

318318

319319
def test_numpy_int_convert():

0 commit comments

Comments
 (0)