kopia lustrzana https://github.com/micropython/micropython-lib
unittest: make unittest.main() work
Enables standalone test scripts to use the common idiom if __name__ == '__main__': unittest.main() e.g. https://docs.python.org/3.4/library/unittest.html#basic-examplepull/38/merge
rodzic
07830bd027
commit
c98be9b0fc
|
@ -1,4 +1,4 @@
|
|||
srctype = micropython-lib
|
||||
type = module
|
||||
version = 0.0.7
|
||||
version = 0.0.8
|
||||
author = Paul Sokolovsky
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
|
||||
class TestStringMethods(unittest.TestCase):
|
||||
|
||||
def test_upper(self):
|
||||
self.assertEqual('foo'.upper(), 'FOO')
|
||||
|
||||
def test_isupper(self):
|
||||
self.assertTrue('FOO'.isupper())
|
||||
self.assertFalse('Foo'.isupper())
|
||||
|
||||
def test_split(self):
|
||||
s = 'hello world'
|
||||
self.assertEqual(s.split(), ['hello', 'world'])
|
||||
# check that s.split fails when the separator is not a string
|
||||
with self.assertRaises(TypeError):
|
||||
s.split(2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -116,8 +116,19 @@ def run_class(c, test_result):
|
|||
|
||||
|
||||
def main(module="__main__"):
|
||||
def test_cases(m):
|
||||
for tn in dir(m):
|
||||
c = getattr(m, tn)
|
||||
if isinstance(c, object) and isinstance(c, type) and issubclass(c, TestCase):
|
||||
yield c
|
||||
|
||||
m = __import__(module)
|
||||
for tn in dir(m):
|
||||
c = getattr(m, tn)
|
||||
if isinstance(c, object) and issubclass(c, TestCase):
|
||||
run_class(c)
|
||||
suite = TestSuite()
|
||||
for c in test_cases(m):
|
||||
suite.addTest(c)
|
||||
runner = TestRunner()
|
||||
result = runner.run(suite)
|
||||
msg = "Ran %d tests" % result.testsRun
|
||||
if result.skippedNum > 0:
|
||||
msg += " (%d skipped)" % result.skippedNum
|
||||
print(msg)
|
||||
|
|
Ładowanie…
Reference in New Issue