|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | import pytest
|
3 | 3 |
|
| 4 | +import env |
4 | 5 | from pybind11_tests import enums as m
|
5 | 6 |
|
6 | 7 |
|
@@ -238,20 +239,26 @@ def test_duplicate_enum_name():
|
238 | 239 |
|
239 | 240 | def test_char_underlying_enum(): # Issue #1331/PR #1334:
|
240 | 241 | assert type(m.ScopedCharEnum.Positive.__int__()) is int
|
241 |
| - assert int(m.ScopedChar16Enum.Zero) == 0 # int() call should successfully return |
| 242 | + assert int(m.ScopedChar16Enum.Zero) == 0 |
242 | 243 | assert hash(m.ScopedChar32Enum.Positive) == 1
|
243 |
| - assert m.ScopedCharEnum.Positive.__getstate__() == 1 # return type is long in py2.x |
| 244 | + if env.PY2: |
| 245 | + assert m.ScopedCharEnum.Positive.__getstate__() == 1 # long |
| 246 | + else: |
| 247 | + assert type(m.ScopedCharEnum.Positive.__getstate__()) is int |
244 | 248 | assert m.ScopedWCharEnum(1) == m.ScopedWCharEnum.Positive
|
245 | 249 | with pytest.raises(TypeError):
|
246 |
| - # Enum should construct with a int, even with char underlying type |
247 |
| - m.ScopedWCharEnum("0") |
| 250 | + # Even if the underlying type is char, only an int can be used to construct the enum: |
| 251 | + m.ScopedCharEnum("0") |
248 | 252 |
|
249 | 253 |
|
250 | 254 | def test_bool_underlying_enum():
|
251 | 255 | assert type(m.ScopedBoolEnum.TRUE.__int__()) is int
|
252 | 256 | assert int(m.ScopedBoolEnum.FALSE) == 0
|
253 | 257 | assert hash(m.ScopedBoolEnum.TRUE) == 1
|
254 |
| - assert m.ScopedBoolEnum.TRUE.__getstate__() == 1 |
| 258 | + if env.PY2: |
| 259 | + assert m.ScopedBoolEnum.TRUE.__getstate__() == 1 # long |
| 260 | + else: |
| 261 | + assert type(m.ScopedBoolEnum.TRUE.__getstate__()) is int |
255 | 262 | assert m.ScopedBoolEnum(1) == m.ScopedBoolEnum.TRUE
|
256 | 263 | # Enum could construct with a bool
|
257 | 264 | # (bool is a strict subclass of int, and False will be converted to 0)
|
|
0 commit comments