__init__.py
Go to the documentation of this file.
1 import unittest
2 
4  class EnumTester(unittest.TestCase):
5  """
6  Generic Enum testing framework
7 
8  Tests expected values of enum and string conversions
9  Inherit this class to test typical gnsstk strongly typed enums.
10 
11  For each subclass, create the `ENUM`, `EXP_ENUM_STRS`, and `STR_CONVERTER`
12  class variables.
13 
14  ENUM: The enum to test (e.g. gnsstk.CorrDupHandling)
15  EXP_ENUM_STRS: A dictionary of enum values and their expected string equivalent
16  STR_CONVERTER: the function the converts strings into enum values
17 
18  """
19 
20  def test_enum(self):
21  """
22  Test enum
23  """
24  actual_items = set(self.ENUM) - {self.ENUM.Last}
25  self.assertEqual(set(self.EXP_ENUM_STRS.keys()), actual_items)
26 
27  for exp_enum, exp_enum_str in self.EXP_ENUM_STRS.items():
28  with self.subTest(enum=exp_enum):
29  self.assertEqual(str(exp_enum), exp_enum_str)
30  # A weird hack since adding a function as an attribute
31  # causes automatic binding.
32  str_converter = self.STR_CONVERTER.__func__
33  self.assertEqual(str_converter(exp_enum_str), exp_enum)
tests.AbstractBaseTesters
Definition: __init__.py:3
tests.AbstractBaseTesters.EnumTester
Definition: __init__.py:4
tests.AbstractBaseTesters.EnumTester.test_enum
def test_enum(self)
Definition: __init__.py:20


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:38