Skip to content

Commit 5838d45

Browse files
committed
tests/basics: Add skip detection for metaclass and enum tests.
Adds feature detection to skip tests when required features are not available (e.g. in minimal/standard build variants). - class_metaclass_init.py: Skip if MICROPY_PY_METACLASS_INIT disabled - class_metaclass_property.py: Skip if MICROPY_PY_METACLASS_PROPERTIES disabled - class_metaclass_prepare.py: Already had skip for __prepare__ - enum_auto.py: Add enum import check before __prepare__ check - enum_flag.py: Skip if enum or __prepare__ not available - enum_strenum.py: Skip if enum module not available - metaclass.py: Skip if MICROPY_PY_METACLASS_INIT disabled This fixes CI failures on build variants where these features are disabled by config. Signed-off-by: Andrew Leech <[email protected]>
1 parent cc4d559 commit 5838d45

File tree

7 files changed

+142
-17
lines changed

7 files changed

+142
-17
lines changed

tests/basics/class_metaclass_init.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Test metaclass __init__ support (requires MICROPY_PY_METACLASS_INIT)
2+
3+
# Skip test if metaclass __init__ is not supported
4+
_init_test = []
5+
6+
class _TestMeta(type):
7+
def __init__(cls, name, bases, attrs):
8+
super().__init__(name, bases, attrs)
9+
_init_test.append(1)
10+
11+
class _Test(metaclass=_TestMeta):
12+
pass
13+
14+
if not _init_test:
15+
print("SKIP")
16+
raise SystemExit
17+
118
# Test 1: Basic metaclass __init__ call
219
init_called = []
320

tests/basics/class_metaclass_prepare.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
# Test metaclass __prepare__ method (PEP 3115)
22

3+
# Skip test if classmethod builtin is not available
4+
try:
5+
classmethod
6+
except NameError:
7+
print("SKIP")
8+
raise SystemExit
9+
310
# Skip test if __prepare__ is not supported
411
_prepare_test = []
5-
class _TestMeta(type):
6-
@classmethod
7-
def __prepare__(mcs, name, bases):
8-
_prepare_test.append(1)
9-
return {}
1012

11-
class _Test(metaclass=_TestMeta):
13+
try:
14+
class _TestMeta(type):
15+
@classmethod
16+
def __prepare__(mcs, name, bases):
17+
_prepare_test.append(1)
18+
return {}
19+
20+
class _Test(metaclass=_TestMeta):
21+
pass
22+
except:
1223
pass
1324

1425
if not _prepare_test:

tests/basics/class_metaclass_property.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
# Test metaclass property/method support (requires MICROPY_PY_METACLASS_PROPERTIES)
2+
3+
# Skip test if property builtin is not available
4+
try:
5+
property
6+
except NameError:
7+
print("SKIP")
8+
raise SystemExit
9+
10+
# Skip test if metaclass property access is not supported
11+
_property_test = None
12+
13+
try:
14+
class _TestMeta(type):
15+
@property
16+
def test_prop(cls):
17+
return "works"
18+
19+
class _Test(metaclass=_TestMeta):
20+
pass
21+
22+
_property_test = _Test.test_prop
23+
except (AttributeError, TypeError):
24+
pass
25+
26+
if _property_test != "works":
27+
print("SKIP")
28+
raise SystemExit
29+
130
# Test 1: Metaclass property access
231
class Meta(type):
332
@property

tests/basics/enum_auto.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
# Test enum.auto() support (requires MICROPY_PY_METACLASS_PREPARE)
22

3+
# Skip test if enum module is not available
4+
try:
5+
from enum import Enum, IntEnum, auto
6+
except ImportError:
7+
print("SKIP")
8+
raise SystemExit
9+
10+
# Skip test if classmethod builtin is not available
11+
try:
12+
classmethod
13+
except NameError:
14+
print("SKIP")
15+
raise SystemExit
16+
317
# Skip test if __prepare__ is not supported
418
_prepare_test = []
5-
class _TestMeta(type):
6-
@classmethod
7-
def __prepare__(mcs, name, bases):
8-
_prepare_test.append(1)
9-
return {}
1019

11-
class _Test(metaclass=_TestMeta):
20+
try:
21+
class _TestMeta(type):
22+
@classmethod
23+
def __prepare__(mcs, name, bases):
24+
_prepare_test.append(1)
25+
return {}
26+
27+
class _Test(metaclass=_TestMeta):
28+
pass
29+
except:
1230
pass
1331

1432
if not _prepare_test:
1533
print("SKIP")
1634
raise SystemExit
1735

18-
# Now run the actual tests
19-
from enum import Enum, IntEnum, auto
20-
2136
# Test 1: Basic auto() usage - sequential values starting from 1
2237
print("Test 1: Basic auto() usage")
2338
class Color(Enum):

tests/basics/enum_flag.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# Test Flag and IntFlag enum classes
2-
from enum import Flag, IntFlag, auto
2+
3+
# Skip test if enum module is not available
4+
try:
5+
from enum import Flag, IntFlag, auto
6+
except ImportError:
7+
print("SKIP")
8+
raise SystemExit
9+
10+
# Skip test if classmethod builtin is not available
11+
try:
12+
classmethod
13+
except NameError:
14+
print("SKIP")
15+
raise SystemExit
16+
17+
# Skip test if __prepare__ is not supported (needed for auto())
18+
_prepare_test = []
19+
20+
try:
21+
class _TestMeta(type):
22+
@classmethod
23+
def __prepare__(mcs, name, bases):
24+
_prepare_test.append(1)
25+
return {}
26+
27+
class _Test(metaclass=_TestMeta):
28+
pass
29+
except:
30+
pass
31+
32+
if not _prepare_test:
33+
print("SKIP")
34+
raise SystemExit
335

436
print("Test 1: Basic Flag operations")
537
class Permission(Flag):

tests/basics/enum_strenum.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Test StrEnum class
2-
from enum import StrEnum
2+
3+
# Skip test if enum module is not available
4+
try:
5+
from enum import StrEnum
6+
except ImportError:
7+
print("SKIP")
8+
raise SystemExit
39

410
print("Test 1: Basic StrEnum")
511
class Color(StrEnum):

tests/basics/metaclass.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Skip test if metaclass __init__ is not supported
2+
_init_test = []
3+
4+
class _TestMeta(type):
5+
def __init__(cls, name, bases, attrs):
6+
super().__init__(name, bases, attrs)
7+
_init_test.append(1)
8+
9+
class _Test(metaclass=_TestMeta):
10+
pass
11+
12+
if not _init_test:
13+
print("SKIP")
14+
raise SystemExit
15+
116
class Meta(type):
217
def __init__(cls, name, bases, dct):
318
print("Meta.__init__", name, bases, dct)

0 commit comments

Comments
 (0)