unittest: add assertIsNone() and assertIsNotNone() methods to TestCase

pull/52/merge
Delio Brignoli 2015-11-01 14:26:49 +01:00 zatwierdzone przez Paul Sokolovsky
rodzic 711eba3a7e
commit 1260289917
4 zmienionych plików z 22 dodań i 2 usunięć

Wyświetl plik

@ -1,3 +1,3 @@
srctype = micropython-lib
type = module
version = 0.1
version = 0.2

Wyświetl plik

@ -6,7 +6,7 @@ from setuptools import setup
setup(name='micropython-unittest',
version='0.1',
version='0.2',
description='unittest module for MicroPython',
long_description="This is a module reimplemented specifically for MicroPython standard library,\nwith efficient and lean design in mind. Note that this module is likely work\nin progress and likely supports just a subset of CPython's corresponding\nmodule. Please help with the development if you are interested in this\nmodule.",
url='https://github.com/micropython/micropython/issues/405',

Wyświetl plik

@ -72,6 +72,16 @@ class TestUnittestAssertions(unittest.TestCase):
with self.assertRaises(AssertionError):
self.assertIsNot(None, None)
def testIsNone(self):
self.assertIsNone(None)
with self.assertRaises(AssertionError):
self.assertIsNone(0)
def testIsNotNone(self):
self.assertIsNotNone(0)
with self.assertRaises(AssertionError):
self.assertIsNotNone(None)
def testTrue(self):
self.assertTrue(True)
with self.assertRaises(AssertionError):

Wyświetl plik

@ -83,6 +83,16 @@ class TestCase:
msg = "%r is %r" % (x, y)
assert x is not y, msg
def assertIsNone(self, x, msg=''):
if not msg:
msg = "%r is not None" % x
assert x is None, msg
def assertIsNotNone(self, x, msg=''):
if not msg:
msg = "%r is None" % x
assert x is not None, msg
def assertTrue(self, x, msg=''):
if not msg:
msg = "Expected %r to be True" % x