kopia lustrzana https://github.com/micropython/micropython-lib
unittest: Add support for SkipTest, skip() and skipUnless().
rodzic
5e1007cf8b
commit
d75ad4867d
|
@ -1,3 +1,7 @@
|
||||||
|
class SkipTest(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestCase:
|
class TestCase:
|
||||||
|
|
||||||
def fail(self, msg=''):
|
def fail(self, msg=''):
|
||||||
|
@ -32,14 +36,32 @@ class TestCase:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def skip(msg):
|
||||||
|
def _decor(fun):
|
||||||
|
# We just replace original fun with _inner
|
||||||
|
def _inner(self):
|
||||||
|
raise SkipTest(msg)
|
||||||
|
return _inner
|
||||||
|
return _decor
|
||||||
|
|
||||||
|
|
||||||
|
def skipUnless(cond, msg):
|
||||||
|
if cond:
|
||||||
|
return lambda x: x
|
||||||
|
return skip(msg)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Uncompliant
|
# TODO: Uncompliant
|
||||||
def run_class(c):
|
def run_class(c):
|
||||||
o = c()
|
o = c()
|
||||||
for name in dir(o):
|
for name in dir(o):
|
||||||
if name.startswith("test"):
|
if name.startswith("test"):
|
||||||
m = getattr(o, name)
|
m = getattr(o, name)
|
||||||
m()
|
try:
|
||||||
print(name, "...ok")
|
m()
|
||||||
|
print(name, "...ok")
|
||||||
|
except SkipTest as e:
|
||||||
|
print(name, "...skipped:", e.args[0])
|
||||||
|
|
||||||
|
|
||||||
def main(module="__main__"):
|
def main(module="__main__"):
|
||||||
|
|
Ładowanie…
Reference in New Issue