def parse_rxspec(rxspec): if not isinstance(rxspec, list): rxspec = [rxspec] node_spec = {"rw_name": rxspec[0]} for spec in rxspec[1:]: if first_nested(spec) in mods.values(): node_spec["modifier"] = parse_rxspec(spec) else: node_spec["children"] = [parse_rxspec(child) for child in spec] return node_spec
def parse_rxspec(self, rxspec: RxSpec) -> NodeSpec: if not isinstance(rxspec, list): rxspec = [rxspec] node_spec = {"rw_name": rxspec[0]} for spec in rxspec[1:]: if self._rxwrappers.wrapper_is_type(first_nested(spec), "mod"): node_spec["modifier"] = self.parse_rxspec(spec) else: node_spec["children"] = [ self.parse_rxspec(child) for child in spec ] return node_spec
def test_nested_first_nested_list(self): data = [[["first", "second"], [["third"], "fourth", "fifth"], "sixth"]] result = first_nested(data) self.assertEqual(result, "first")
def test_nested_first_flat_list(self): data = ["first", "second", "third"] result = first_nested(data) self.assertEqual(result, "first")
def test_nested_first_value(self): data = "first" result = first_nested(data) self.assertEqual(result, "first")