]> Repositories - Adafruit_Blinka-hackapet.git/blob - python/testing/mcp.py
Initial intro regarding approach
[Adafruit_Blinka-hackapet.git] / python / testing / mcp.py
1 import unittest
2
3
4 class TestEnum(unittest.TestCase):
5     """
6         Verifies the repl() and str() behaviour of an example Enum
7         Enums represent configuration values such as digitalio.Direction, digitalio.Pull etc.
8     """
9
10     def setUp(self):
11         import mcp
12         class Cls(mcp.Enum):
13             pass
14         Cls.one = Cls()
15         Cls.two = Cls()
16         # class refs would be implicitly populated correctly in a real module
17         Cls.__module__ = "ho.hum"
18         Cls.__qualname__ = "Example"
19         self.Cls = Cls
20
21
22     def test_iteritems(self):
23         items = list(self.Cls.iteritems())
24         self.assertEqual( items, [("one",self.Cls.one),("two",self.Cls.two),])
25
26
27     def test_repr(self):
28         name = "one"
29         actual = repr(getattr(self.Cls, name))
30         expected = "{}.{}.{}".format(self.Cls.__module__, self.Cls.__qualname__, name)
31         self.assertEqual( actual, expected)
32
33
34     def test_str(self):
35         self.assertEqual(str(self.Cls.one), repr(self.Cls.one))