def test_custom_asdict_omit_none_multiple(): @dataclass class ToyDataclassOne: foo: str = OmitNone() @dataclass class ToyDataclassTwo: bar: str = OmitNone() dc = ToyDataclassOne() expected = {} assert asdict(dc, dict_factory=custom_asdict_factory()) == expected dc = ToyDataclassTwo() expected = {} assert asdict(dc, dict_factory=custom_asdict_factory()) == expected
def render(self) -> Dict[LanguageCode, dict]: languages: List[LanguageCode] = agent_supported_languages(self.agent_cls) result = {} for lang in languages: rendered = self.render_agent(lang) rendered.interactionModel.languageModel.intents.extend(DEFAULT_INTENTS) result[lang] = asdict(rendered, dict_factory=custom_asdict_factory()) return result
def render(connector: SnipsConnector) -> Dict[LanguageCode, dict]: languages: List[LanguageCode] = agent_supported_languages(connector.agent_cls) result = {} for lang in languages: try: rendered = render_dataset(connector, lang) result[lang] = asdict(rendered, dict_factory=custom_asdict_factory()) except NotImplementedError as exc: logger.error("Could not export Agent for language %s: %s", lang, exc) return result
def test_custom_asdict_omit_none(): @dataclass class ToyDataclass: foo: str = OmitNone() dc = ToyDataclass("bar") expected = { "foo": "bar", } assert asdict(dc, dict_factory=custom_asdict_factory()) == expected dc = ToyDataclass(None) expected = { "foo": None, } assert asdict(dc, dict_factory=custom_asdict_factory()) == expected dc = ToyDataclass() expected = {} assert asdict(dc, dict_factory=custom_asdict_factory()) == expected
def test_custom_asdict_enums_are_converted(): class ToyEnum(Enum): ONE = "one" TWO = "two" @dataclass class ToyDataclass: foo: str enum: ToyEnum dc = ToyDataclass("bar", ToyEnum.TWO) expected = {"foo": "bar", "enum": "two"} assert asdict(dc, dict_factory=custom_asdict_factory()) == expected