commit e64e96f108ad350c59bc83dd257043009aa26de3 Author: Damian Johnson atagar@torproject.org Date: Wed Jan 24 09:34:44 2018 -0800
Test new enum class
We pretty well excercised it via our existing tests, but we didn't explicitly check its error handling. --- stem/client/__init__.py | 2 +- test/unit/client/address.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/stem/client/__init__.py b/stem/client/__init__.py index a247c7ba..42ce9966 100644 --- a/stem/client/__init__.py +++ b/stem/client/__init__.py @@ -158,7 +158,7 @@ class _IntegerEnum(stem.util.enum.Enum): elif val in self: return val, self._enum_to_int.get(val, val) else: - raise ValueError('Invalid %s type: %s' % (self.__name__, val)) + raise ValueError("Invalid enumeration '%s', options are %s" % (val, ', '.join(self)))
AddrType = _IntegerEnum( diff --git a/test/unit/client/address.py b/test/unit/client/address.py index acda251b..f5dc4a00 100644 --- a/test/unit/client/address.py +++ b/test/unit/client/address.py @@ -12,6 +12,13 @@ ExpectedAddress = collections.namedtuple('ExpectedAddress', ['type', 'type_int',
class TestAddress(unittest.TestCase): + def test_enum(self): + self.assertEqual(('IPv4', 4), AddrType.get(AddrType.IPv4)) + self.assertEqual(('IPv4', 4), AddrType.get(4)) + + self.assertEqual(('UNKNOWN', 25), AddrType.get(25)) + self.assertRaisesRegexp(ValueError, "Invalid enumeration 'boom', options are HOSTNAME, IPv4, IPv6, ERROR_TRANSIENT, ERROR_PERMANENT, UNKNOWN", AddrType.get, 'boom') + def test_constructor(self): test_data = ( ((4, '\x7f\x00\x00\x01'), ExpectedAddress(AddrType.IPv4, 4, '127.0.0.1', '\x7f\x00\x00\x01')),
tor-commits@lists.torproject.org