X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka.git/blobdiff_plain/5c2512abe5fa4f633afa94c742f3cd6bbf24c401..a3770186a94117be56a8d9a8038a2d540bd2884c:/test/src/testing/adafruit_blinka.py diff --git a/test/src/testing/adafruit_blinka.py b/test/src/testing/adafruit_blinka.py index 91a2c84..5ad38e2 100644 --- a/test/src/testing/adafruit_blinka.py +++ b/test/src/testing/adafruit_blinka.py @@ -10,8 +10,10 @@ class TestEnum(unittest.TestCase): def setUp(self): """Create an example Enum, mocking __module__ and __qualname__""" import adafruit_blinka + class Cls(adafruit_blinka.Enum): pass + Cls.one = Cls() Cls.two = Cls() # class refs would be implicitly populated correctly in a real module @@ -19,21 +21,31 @@ class TestEnum(unittest.TestCase): Cls.__qualname__ = "Example" self.Cls = Cls - def test_iteritems(self): """A subtype of Enum can list all attributes of its own type""" items = list(self.Cls.iteritems()) - self.assertEqual( items, [("one",self.Cls.one),("two",self.Cls.two),]) - + self.assertEqual(items, [("one", self.Cls.one), ("two", self.Cls.two),]) def test_repr(self): """A repr() call on an Enum gives its fully-qualified name""" name = "one" actual = repr(getattr(self.Cls, name)) expected = "{}.{}.{}".format(self.Cls.__module__, self.Cls.__qualname__, name) - self.assertEqual( actual, expected) - + self.assertEqual(actual, expected) def test_str(self): """A str() call on an Enum performs the same as repr()""" - self.assertEqual(str(self.Cls.one), repr(self.Cls.one)) \ No newline at end of file + self.assertEqual(str(self.Cls.one), repr(self.Cls.one)) + + +class TestDigitalInOut(unittest.TestCase): + def test_context_manager(self): + import digitalio + from testing.board import default_pin + + """Deinitialisation is triggered by __exit__() and should dispose machine.pin reference""" + dio = digitalio.DigitalInOut(default_pin) + self.assertIsNotNone(dio._pin) + with dio: + pass + self.assertIsNone(dio._pin)