Skip to content

Commit 13147af

Browse files
committed
Again
1 parent ab9dc22 commit 13147af

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
python -m pip install wheel
121121
pip install -r requirements_test.txt
122122
- name: Add numba
123-
if: ${{ !contains(fromJSON('["pypy3.9"]'), matrix.python-version) }}
123+
if: ${{ !contains(fromJSON('["pypy3.9", "3.13t"]'), matrix.python-version) }}
124124
run: |
125125
pip install numba
126126
- name: Test with pytest

.github/workflows/micropython.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
micropython -c "import mip; mip.install('datetime')"
2929
micropython -c "import mip; mip.install('__future__')"
3030
31+
- name: Install pytest shim
32+
run: |
33+
mkdir -p ~/.micropython/lib/pytest
34+
cp dev/micropython_pytest_shim.py ~/.micropython/lib/pytest/__init__.py
35+
3136
- name: Run tests
3237
run: |
3338
cd tests

dev/micropython_pytest_shim.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import os
2+
class raises():
3+
def __init__(self, err):
4+
self.err = err
5+
6+
def __enter__(self):
7+
pass
8+
9+
def __exit__(self, *args):
10+
if len(args) < 2 or not isinstance(args[1], self.err):
11+
raise ValueError("Did not raise")
12+
return True
13+
14+
15+
def istestfunc(func):
16+
return (
17+
hasattr(func, "__call__")
18+
and getattr(func, "__name__", "<lambda>") != "<lambda>"
19+
)
20+
21+
# import attr
22+
23+
# @attr.s(frozen=True)
24+
class Mark(object):
25+
26+
def __init__(self, name, args, kwargs):
27+
self.name = name
28+
self.args = args
29+
self.kwargs = kwargs
30+
31+
def combined_with(self, other):
32+
"""
33+
:param other: the mark to combine with
34+
:type other: Mark
35+
:rtype: Mark
36+
37+
combines by appending args and merging the mappings
38+
"""
39+
assert self.name == other.name
40+
return Mark(
41+
self.name, self.args + other.args, dict(self.kwargs, **other.kwargs)
42+
)
43+
44+
45+
# @attr.s
46+
class MarkDecorator(object):
47+
# mark = attr.ib(validator=attr.validators.instance_of(Mark))
48+
49+
# name = alias("mark.name")
50+
# args = alias("mark.args")
51+
# kwargs = alias("mark.kwargs")
52+
def __init__(self, mark):
53+
self.mark = mark
54+
self.name = mark.name
55+
self.args = mark.args
56+
self.kwargs = mark.kwargs
57+
58+
@property
59+
def markname(self):
60+
return self.name # for backward-compat (2.4.1 had this attr)
61+
62+
def __eq__(self, other):
63+
return self.mark == other.mark if isinstance(other, MarkDecorator) else False
64+
65+
def __repr__(self):
66+
return "<MarkDecorator %r>" % (self.mark,)
67+
68+
def with_args(self, *args, **kwargs):
69+
""" return a MarkDecorator with extra arguments added
70+
71+
unlike call this can be used even if the sole argument is a callable/class
72+
73+
:return: MarkDecorator
74+
"""
75+
76+
mark = Mark(self.name, args, kwargs)
77+
return self.__class__(self.mark.combined_with(mark))
78+
79+
def __call__(self, *args, **kwargs):
80+
""" if passed a single callable argument: decorate it with mark info.
81+
otherwise add *args/**kwargs in-place to mark information. """
82+
if args and not kwargs:
83+
func = args[0]
84+
is_class = False
85+
if len(args) == 1 and (istestfunc(func) or is_class):
86+
return func
87+
return self.with_args(*args, **kwargs)
88+
89+
class MarkGenerator(object):
90+
_config = None
91+
_markers = set()
92+
93+
def __getattr__(self, name):
94+
if name[0] == "_":
95+
raise AttributeError("Marker name must NOT start with underscore")
96+
return MarkDecorator(Mark(name, (), {}))
97+
98+
mark = MarkGenerator()

0 commit comments

Comments
 (0)