def clean_path(path_enum: EnumMeta, path): if isinstance(path, Queue): return path else: try: return get_enum_value(path_enum, path) except Exception as e: raise InvalidPathError( "Unable to cast your path identifier to an enum.") from e
def test_enum(self): AutoEnum = Enum("Auto", ["FOO", "BAR"]) data = {AutoEnum.FOO: "wizbang"} encoded = json.dumps( {str(k): v for k, v in data.items()}, cls=utils.AutoEncoder ) decoded = { utils.get_enum_value(AutoEnum, k): v for k, v in json.loads(encoded).items() } assert data == decoded
def normalize_path(path_enum: EnumMeta, path: Union[str, Enum]) -> Enum: try: return utils.get_enum_value(path_enum, path) except Exception as e: raise lpipe.exceptions.InvalidPathError( "Unable to cast your path identifier to an enum.") from e
def test_default(self): d = {"foo": "bar", "wiz": "bang"} output = utils.generate_enum(d) assert isinstance(output, EnumMeta) for k in d.keys(): assert utils.get_enum_value(output, k)
def test_get_bad_enum_value(fixture_name, fixture, raises): path_enum = Enum("TestPath", ["FOO", "BAR"]) with pytest.raises(raises): utils.get_enum_value(e=path_enum, k=fixture)
def test_get_enum_value(fixture_name, fixture): assert utils.get_enum_value(**fixture) == FakePath.FOO