Skip to content

Commit a5207af

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 a5207af

File tree

6 files changed

+90
-5
lines changed

6 files changed

+90
-5
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_property.py

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

tests/basics/enum_auto.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
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+
310
# Skip test if __prepare__ is not supported
411
_prepare_test = []
512
class _TestMeta(type):
@@ -15,9 +22,6 @@ class _Test(metaclass=_TestMeta):
1522
print("SKIP")
1623
raise SystemExit
1724

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

tests/basics/enum_flag.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
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 __prepare__ is not supported (needed for auto())
11+
_prepare_test = []
12+
class _TestMeta(type):
13+
@classmethod
14+
def __prepare__(mcs, name, bases):
15+
_prepare_test.append(1)
16+
return {}
17+
18+
class _Test(metaclass=_TestMeta):
19+
pass
20+
21+
if not _prepare_test:
22+
print("SKIP")
23+
raise SystemExit
324

425
print("Test 1: Basic Flag operations")
526
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)