def test_objectnode_copy_simple_with_arg(): """Copy with an arg""" # Establish types tc = TypeContext() AInixType(tc, "footype") bartype = AInixType(tc, "bartype") arg1 = AInixArgument(tc, "arg1", "bartype", required=True) foo_object = AInixObject(tc, "foo_object", "footype", [arg1]) bar_object = AInixObject(tc, "bar_object", "bartype") # Make an ast arg_choice = ObjectChoiceNode(bartype) ob_chosen = ObjectNode(bar_object) arg_choice.set_choice(ob_chosen) instance = ObjectNode(foo_object) instance.set_arg_value("arg1", arg_choice) # Do the tests: # Unfrozen clone, leaf = instance.path_clone() assert id(clone) != id(instance) assert leaf is None # with a path clone, leaf = instance.path_clone([instance]) assert id(clone) != id(instance) assert leaf.cur_node == clone assert leaf.parent is None # with a deep path clone, leaf = instance.path_clone([instance, arg_choice]) assert id(clone) != id(instance) assert leaf.cur_node.choice is None # with a deeper path clone, leaf = instance.path_clone([instance, arg_choice, ob_chosen]) assert id(clone) != id(instance) assert clone == instance assert leaf.cur_node == ob_chosen assert leaf.parent.cur_node.choice == ob_chosen
def _create_root_types(type_context: TypeContext): """Creates the underlying types for handling generid strings""" AInixType(type_context, WORD_PART_TYPE_NAME, WORD_PART_TYPE_PARSER_NAME) AInixObject(type_context, WORD_PART_TERMINAL_NAME, WORD_PART_TYPE_NAME) _create_modifier_types(type_context) AInixType(type_context, WORD_TYPE_NAME) # Create a word which cannot be empty str parts = AInixArgument(type_context, "parts", WORD_PART_TYPE_NAME, required=True) def non_empty_word_parser(run: parse_primitives.ObjectParserRun, string: str, result: parse_primitives.ObjectParserResult): if string == "": raise AInixParseError("Expect a non-empty word") deleg = yield run.left_fill_arg(parts, (0, len(string))) result.accept_delegation(deleg) def unparser(arg_map: parse_primitives.ObjectNodeArgMap, result: parse_primitives.ObjectToStringResult): result.add_arg_tostring(parts) parser = ObjectParser(type_context, "non_empty_word_parser", non_empty_word_parser, unparser) AInixObject(type_context, WORD_OBJ_NAME, WORD_TYPE_NAME, [parts], parser.name)
def test_dfs_in_set(): tc = get_toy_strings_context() footype = AInixType(tc, "footype") bartype = AInixType(tc, "bartype") arg1 = AInixArgument(tc, "arg1", "bartype", required=True) foo_object = AInixObject(tc, "foo_object", "footype", [arg1]) bar_object = AInixObject(tc, "bar_object", "bartype") other_bar_obj = AInixObject(tc, "other_bar_ob", "bartype") # arg_choice = ObjectChoiceNode(bartype) ob_chosen = ObjectNode(bar_object) arg_choice.set_choice(ob_chosen) instance = ObjectNode(foo_object) instance.set_arg_value("arg1", arg_choice) ast = ObjectChoiceNode(footype) ast.set_choice(instance) # ast_set = AstObjectChoiceSet(footype) ast_set.add(ast, True, 1, 1) path = [pointer.cur_node for pointer in list(ast.depth_first_iter())] assert path == [ast, instance, arg_choice, ob_chosen] result = list(depth_first_iterate_ast_set_along_path(ast_set, path)) assert len(result) == len(path) assert isinstance(result[0], AstObjectChoiceSet) assert result[0].type_to_choose == footype assert isinstance(result[1], ObjectNodeSet) assert result[1].implementation == foo_object assert isinstance(result[2], AstObjectChoiceSet) assert result[2].type_to_choose == bartype assert isinstance(result[3], ObjectNodeSet) assert result[3].implementation == bar_object
def test_make_copy_optional_arg(): tc = TypeContext() ft = AInixType(tc, "ft") bt = AInixType(tc, "bt") arg1 = AInixArgument(tc, "arg1", "bt", required=False, parent_object_name="fo") fo = AInixObject( tc, "fo", "ft", [arg1], preferred_object_parser_name=create_object_parser_from_grammar( tc, "masfoo_parser", '"foo" arg1?').name) bo = AInixObject( tc, "bo", "bt", None, preferred_object_parser_name=create_object_parser_from_grammar( tc, "masdfo_parser", '"bar"').name) tc.finalize_data() parser = StringParser(tc) unparser = AstUnparser(tc) ast = parser.create_parse_tree("foobar", "ft") tokenizer = SpaceTokenizer() in_str = "Hello bar sdf cow" tokens, metadata = tokenizer.tokenize(in_str) unpar_res = unparser.to_string(ast) assert unpar_res.total_string == "foobar" result = make_copy_version_of_tree(ast, unparser, metadata) assert result.next_node_not_copy.get_choice_node_for_arg( "arg1").copy_was_chosen
def test_pointer_change_here(freeze_first): """Test an arg change""" # Establish types tc = TypeContext() AInixType(tc, "footype") bartype = AInixType(tc, "bartype") arg1 = AInixArgument(tc, "arg1", "bartype", required=True) foo_object = AInixObject(tc, "foo_object", "footype", [arg1]) bar_object = AInixObject(tc, "bar_object", "bartype") other_bar_obj = AInixObject(tc, "other_bar_ob", "bartype") # Make an ast arg_choice = ObjectChoiceNode(bartype) ob_chosen = ObjectNode(bar_object) arg_choice.set_choice(ob_chosen) instance = ObjectNode(foo_object) instance.set_arg_value("arg1", arg_choice) if freeze_first: instance.freeze() # Try change deepest = list(instance.depth_first_iter())[-1] assert deepest.cur_node == ob_chosen new_node = ObjectNode(other_bar_obj) new_point = deepest.change_here(new_node) assert new_point.cur_node == new_node assert new_point.cur_node.is_frozen == freeze_first
def test_objectnode_copy_with_child(): """Copy with an arg""" # Establish types tc = TypeContext() AInixType(tc, "footype") bartype = AInixType(tc, "bartype") arg1 = AInixArgument(tc, "arg1", "bartype", parent_object_name="foo_object") foo_object = AInixObject(tc, "foo_object", "footype", [arg1]) bar_object = AInixObject(tc, "bar_object", "bartype") # Make an ast fin_choice = ObjectNode(bar_object) is_pres = ObjectChoiceNode(bartype) is_pres.set_choice(fin_choice) arg_node = ObjectNode(arg1.is_present_object) arg_node.set_arg_value(OPTIONAL_ARGUMENT_NEXT_ARG_NAME, is_pres) is_pres_top = ObjectChoiceNode(arg1.present_choice_type) is_pres_top.set_choice(arg_node) instance = ObjectNode(foo_object) instance.set_arg_value("arg1", is_pres_top) # Do the tests: # Unfrozen clone, leaf = instance.path_clone() assert id(clone) != id(instance) assert leaf is None # Freeze part is_pres_top.freeze() clone, leaf = instance.path_clone() assert id(clone) != id(instance) assert not clone.is_frozen assert clone == instance assert id(clone.get_choice_node_for_arg("arg1")) == id(is_pres_top) # Freeze all instance.freeze() clone, leaf = instance.path_clone() assert id(clone) == id(instance) assert clone == instance assert id(clone.get_choice_node_for_arg("arg1")) == id(is_pres_top) # Full unfreeze path clone, leaf = instance.path_clone( [instance, is_pres_top, arg_node, is_pres, fin_choice]) assert id(clone) != id(instance) assert not clone.is_frozen assert clone == instance assert leaf.get_nodes_to_here() == [ instance, is_pres_top, arg_node, is_pres, fin_choice ] # Partial unfreeze path (stop early) clone, leaf = instance.path_clone([instance, is_pres_top, arg_node]) assert id(clone) != id(instance) assert not clone.is_frozen assert clone != instance path = leaf.get_nodes_to_here() assert len(path) == 3 new_arg_node: ObjectNode = leaf.cur_node assert new_arg_node.get_choice_node_for_arg( OPTIONAL_ARGUMENT_NEXT_ARG_NAME) is None
def test_nearest_example(): type_context = TypeContext() type_name = "DeepThoughts" other_type_name = "PythonThoughts" top_type = AInixType(type_context, type_name) other_type = AInixType(type_context, other_type_name) parsed_rep = ainix_common.parsing.ast_components.indexable_repr_classify_type( top_type.name) print(parsed_rep) other_parsed_rep = ainix_common.parsing.ast_components.indexable_repr_classify_type( other_type.name) print(other_parsed_rep) index = ExamplesIndex(type_context, backend=ExamplesIndex.get_default_ram_backend()) index.add_example( XValue(0, "what is the meaning of life", "42", index.DEFAULT_X_TYPE, type_name, 1, "sdff", DataSplits.TRAIN.value, parsed_rep)) index.add_example( XValue(1, "what is the meaning of the universe", "forty two", index.DEFAULT_X_TYPE, type_name, 1, "bdffg", DataSplits.TRAIN.value, parsed_rep)) index.add_example( XValue(2, "what... is the airspeed of an unladen swallow?", "African or European?", index.DEFAULT_X_TYPE, other_type_name, 1, "sfasdf", DataSplits.TRAIN.value, other_parsed_rep)) index.add_example( XValue(3, "what is the meaning of everything else", "four two", index.DEFAULT_X_TYPE, type_name, 1, "sdfasdf", DataSplits.TRAIN.value, parsed_rep)) index.add_example( XValue(4, "what... is your quest?", "To seek the Holy Grail", index.DEFAULT_X_TYPE, other_type_name, 1, "sdfanb", DataSplits.TRAIN.value, other_parsed_rep)) #result = list(index.get_nearest_examples("what... is your quest?", other_type.name)) #print(result) #assert len(result) == 2 #assert result[0].xquery == "what... is your quest?" result = list( index.get_nearest_examples("what... is your quest?", other_type.name, max_results=1)) assert len(result) == 1 assert result[0].xquery == "what... is your quest?" result = list( index.get_nearest_examples("everything else", top_type.name, max_results=1)) assert len(result) == 1 assert result[0].xquery == "what is the meaning of everything else"
def test_objectnode_copy_simple(): """Copy with no children""" tc = TypeContext() AInixType(tc, "footype") foo_object = AInixObject(tc, "foo_object", "footype") instance = ObjectNode(foo_object) # Unfrozen clone, path = instance.path_clone() assert id(clone) != id(instance) assert clone.implementation == foo_object assert instance == clone assert path is None # Frozen instance.freeze() clone, path = instance.path_clone() assert id(clone) == id(instance) assert clone == instance assert path is None assert clone.is_frozen # Frozen but on unfreeze path clone, path = instance.path_clone([instance]) assert id(clone) != id(instance) assert instance == clone assert clone.implementation == foo_object assert not clone.is_frozen
def test_parse_set_optional(): """Manually build up an ast, and make sure the ast set is representing optional args correctly.""" tc = TypeContext() foo_type = AInixType(tc, "FooType") test_arg = AInixArgument(tc, "test_arg", "FooType", parent_object_name="foo_ob") foo_ob = AInixObject(tc, "foo_ob", "FooType", [test_arg]) ast_set = AstObjectChoiceSet(foo_type, None) ast = ObjectChoiceNode(foo_type) next_o = ObjectNode(foo_ob) ast.set_choice(next_o) arg_choice_node = ObjectChoiceNode(test_arg.present_choice_type) arg_choice_node.set_choice(ObjectNode(test_arg.not_present_object)) next_o.set_arg_value("test_arg", arg_choice_node) ast.freeze() ast_set.add(ast, True, 1, 1) data = ast_set._impl_name_to_data["foo_ob"].next_node.get_arg_set_data( next_o.as_childless_node()) assert data is not None assert data.arg_to_choice_set["test_arg"].type_to_choose_name == \ test_arg.present_choice_type.name
def test_string_parse_e2e_pos_unparse(type_context): fooType = AInixType(type_context, "FooType") fo = AInixObject( type_context, "fo", "FooType", [], preferred_object_parser_name=create_object_parser_from_grammar( type_context, "fooname", '"foo"').name) twoargs = AInixObject(type_context, "FooProgram", "Program", [ AInixArgument(type_context, "p1", "FooType", arg_data={ POSITION: 0, MULTIWORD_POS_ARG: False }, parent_object_name="bw", required=True) ], type_data={"invoke_name": "hello"}) type_context.finalize_data() parser = StringParser(type_context) ast = parser.create_parse_tree("hello foo", "Program") unparser = AstUnparser(type_context) unparse_result = unparser.to_string(ast) assert unparse_result.total_string == "hello foo" for p in ast.depth_first_iter(): n = p.cur_node if isinstance(n, ObjectChoiceNode) and n.type_to_choose.name == "FooType": arg_node_pointer = p break assert unparse_result.pointer_to_string(arg_node_pointer) == "foo"
def test_string_parse_e2e_multiword2(type_context): fooType = AInixType(type_context, "FooType") fo = AInixObject( type_context, "fo", "FooType", [], preferred_object_parser_name=create_object_parser_from_grammar( type_context, "fooname", '"foo bar"').name) twoargs = AInixObject(type_context, "FooProgram", "Program", [ AInixArgument(type_context, "a", None, arg_data={"short_name": "a"}, parent_object_name="sdf"), AInixArgument(type_context, "p1", "FooType", arg_data={ POSITION: 0, MULTIWORD_POS_ARG: True }, parent_object_name="sdf") ], type_data={"invoke_name": "hello"}) type_context.finalize_data() parser = StringParser(type_context) ast = parser.create_parse_tree("hello foo bar -a", "Program") unparser = AstUnparser(type_context) to_string = unparser.to_string(ast) assert to_string.total_string == "hello -a foo bar"
def test_string_parse_e2e_multiword3(type_context): fooType = AInixType(type_context, "FooType") fo = AInixObject( type_context, "fo", "FooType", [], preferred_object_parser_name=create_object_parser_from_grammar( type_context, "fooname", '"foo"').name) twoargs = AInixObject(type_context, "FooProgram", "Program", [ AInixArgument(type_context, "a", None, arg_data={"short_name": "a"}, parent_object_name="sdf"), AInixArgument(type_context, "barg", None, arg_data={"short_name": "b"}, parent_object_name="bw"), _make_positional() ], type_data={"invoke_name": "hello"}) type_context.finalize_data() parser = StringParser(type_context) ast = parser.create_parse_tree("hello -a", "CommandSequence") unparser = AstUnparser(type_context) to_string = unparser.to_string(ast) assert to_string.total_string == "hello -a"
def test_max_munch(): tc = TypeContext() loader.load_path("builtin_types/generic_parsers.ainix.yaml", tc, up_search_limit=3) foo_type = "MMTestType" AInixType(tc, foo_type, default_type_parser_name="max_munch_type_parser") def make_mock_with_parse_rep(representation: str): loader._load_object( { "name": representation, "type": foo_type, "preferred_object_parser": { "grammar": f'"{representation}"' } }, tc, "foopathsdf") assert tc.get_object_by_name( representation).preferred_object_parser_name is not None objects = [ make_mock_with_parse_rep(rep) for rep in ("fo", "bar", "f", "foo", "foot", 'baz') ] parser = StringParser(tc) ast = parser.create_parse_tree("foobar", foo_type, allow_partial_consume=True) assert ast.next_node_not_copy.implementation.name == "foo"
def test_prog_object_parser_posarg(type_context): fooType = AInixType(type_context, "FooType") argval = AInixObject(type_context, "FooProgram", "Program", [ AInixArgument(type_context, "p1", fooType.name, arg_data={POSITION: 0}, required=True) ]) parser = type_context.get_object_parser_by_name("ProgramObjectParser") result = gen_result(parser.parse_string("hello", argval)) assert result.get_arg_present("p1") is not None assert result.get_arg_present("p1").slice_string == "hello"
def basic_classify_tc(base_tc): tc = base_tc AInixType(tc, "FooBarBazType", default_type_parser_name="max_munch_type_parser") for word in ("foo", "baz", "bar", "pop"): AInixObject( tc, word, "FooBarBazType", preferred_object_parser_name=create_object_parser_from_grammar( tc, f"par{word}", f'"{word}"').name) return tc
def test_get_all_docs(): type_context = TypeContext() type_name = "DeepThoughts" other_type_name = "PythonThoughts" top_type = AInixType(type_context, type_name) other_type = AInixType(type_context, other_type_name) parsed_rep = ainix_common.parsing.ast_components.indexable_repr_classify_type( top_type.name) other_parsed_rep = ainix_common.parsing.ast_components.indexable_repr_classify_type( other_type.name) index = ExamplesIndex(type_context, backend=ExamplesIndex.get_default_ram_backend()) index.add_example( XValue(0, "what is the meaning of life", "42", index.DEFAULT_X_TYPE, type_name, 1, "sdf", DataSplits.TRAIN.value, parsed_rep)) index.add_example( XValue(1, "what is the meaning of the universe", "forty two", index.DEFAULT_X_TYPE, type_name, 1, "sdfnb", DataSplits.TEST.value, parsed_rep)) index.add_example( XValue(2, "what... is the airspeed of an unladen swallow?", "African or European?", index.DEFAULT_X_TYPE, other_type_name, 1, "basdf", DataSplits.VALIDATION.value, other_parsed_rep)) index.add_example( XValue(3, "what is the meaning of everything else", "four two", index.DEFAULT_X_TYPE, type_name, 1, "sdbf", DataSplits.TRAIN.value, parsed_rep)) index.add_example( XValue(4, "what... is your quest?", "To seek the Holy Grail", index.DEFAULT_X_TYPE, other_type_name, 1, "nwand", DataSplits.VALIDATION.value, other_parsed_rep)) assert len(list(index.get_all_x_values())) == 5 assert len(list(index.get_all_x_values((DataSplits.VALIDATION, )))) == 2 assert len( list(index.get_all_x_values( (DataSplits.VALIDATION, DataSplits.TRAIN)))) == 4
def test_prog_object_parser_argval(type_context): fooType = AInixType(type_context, "FooType") argval = AInixObject(type_context, "FooProgram", "Program", [ AInixArgument(type_context, "a", fooType.name, arg_data={"short_name": "a"}, parent_object_name="sdf") ]) parser = type_context.get_object_parser_by_name("ProgramObjectParser") result = gen_result(parser.parse_string("-a hello", argval)) assert result.get_arg_present("a") is not None assert result.get_arg_present("a").slice_string == "hello" assert result.remaining_start_i == len("-a hello")
def test_prog_object_parser_argval_combined_style(type_context): fooType = AInixType(type_context, "FooType") argval = AInixObject(type_context, "FooProgram", "Program", [ AInixArgument(type_context, "a", fooType.name, arg_data={"short_name": "a"}, parent_object_name="sdf") ]) parser = type_context.get_object_parser_by_name("ProgramObjectParser") # Combined style result = gen_result(parser.parse_string("-afoo", argval)) assert result.get_arg_present("a") is not None assert result.get_arg_present("a").slice_string == "foo"
def basic_string_tc(basic_classify_tc): tc = basic_classify_tc AInixType(tc, "FooStringType") lhsArg = AInixArgument(tc, "lhs", "FooBarBazType", required=True, parent_object_name="wer") rhsArg = AInixArgument(tc, "rhs", "FooStringType", required=False, parent_object_name="sdf") AInixObject(tc, "foo_string", "FooStringType", [lhsArg, rhsArg], preferred_object_parser_name=create_object_parser_from_grammar( tc, "itasdf", 'lhs (" " rhs)?').name) return tc
def test_prog_object_parser_2posarg_multword_end(type_context): fooType = AInixType(type_context, "FooType") argval = AInixObject(type_context, "FooProgram", "Program", [ AInixArgument(type_context, "p1", fooType.name, arg_data={POSITION: 0}, required=True), AInixArgument(type_context, "p2", fooType.name, arg_data={ POSITION: 1, MULTIWORD_POS_ARG: True }, required=True) ]) parser = type_context.get_object_parser_by_name("ProgramObjectParser") result = gen_result(parser.parse_string("hello yo there woo", argval)) assert result.get_arg_present("p1") is not None assert result.get_arg_present("p1").slice_string == "hello" assert result.get_arg_present("p2") is not None assert result.get_arg_present("p2").slice_string == "yo there woo"
def test_multi_copy(): tc = TypeContext() loader.load_path(f"builtin_types/generic_parsers.ainix.yaml", tc, up_search_limit=3) ft = AInixType(tc, "ft") bt = AInixType(tc, "bt", default_type_parser_name="max_munch_type_parser") arg1 = AInixArgument(tc, "lhs", "bt", required=True, parent_object_name="fo") arg2 = AInixArgument(tc, "right", "bt", required=True, parent_object_name="sg") fo = AInixObject( tc, "fo", "ft", [arg1, arg2], preferred_object_parser_name=create_object_parser_from_grammar( tc, "mp", 'lhs right').name) bfoo = AInixObject( tc, "bfoo", "bt", None, preferred_object_parser_name=create_object_parser_from_grammar( tc, "masdfo_parser", '"foo"').name) bbar = AInixObject( tc, "bbar", "bt", None, preferred_object_parser_name=create_object_parser_from_grammar( tc, "mdf", '"bar"').name) tc.finalize_data() parser = StringParser(tc) unparser = AstUnparser(tc) ast = parser.create_parse_tree("foofoo", "ft") tokenizer = SpaceTokenizer() in_str = "Hello foo" tokens, metadata = tokenizer.tokenize(in_str) unpar_res = unparser.to_string(ast) assert unpar_res.total_string == "foofoo" cset = AstObjectChoiceSet(ft) cset.add(ast, True, 1, 1) assert cset.is_node_known_valid(ast) add_copies_to_ast_set(ast, cset, unparser, metadata) copy_left = ObjectChoiceNode( ft, ObjectNode( fo, pmap({ "lhs": ObjectChoiceNode(bt, CopyNode(bt, 1, 1)), "right": ObjectChoiceNode(bt, ObjectNode(bfoo, pmap())) }))) assert cset.is_node_known_valid(copy_left) copy_right = ObjectChoiceNode( ft, ObjectNode( fo, pmap({ "lhs": ObjectChoiceNode(bt, ObjectNode(bfoo, pmap())), "right": ObjectChoiceNode(bt, CopyNode(bt, 1, 1)) }))) assert cset.is_node_known_valid(copy_right) copy_both = ObjectChoiceNode( ft, ObjectNode( fo, pmap({ "lhs": ObjectChoiceNode(bt, CopyNode(bt, 1, 1)), "right": ObjectChoiceNode(bt, CopyNode(bt, 1, 1)) }))) assert cset.is_node_known_valid(copy_both)
def _create_modifier_types(type_context: TypeContext): AInixType(type_context, "GenericWordPartModifier") AInixObject(type_context, MODIFIER_LOWER_NAME, "GenericWordPartModifier") AInixObject(type_context, MODIFIER_FIRST_CAP_NAME, "GenericWordPartModifier") AInixObject(type_context, MODIFIER_ALL_UPPER, "GenericWordPartModifier")
def test_objectnode_copy_with_2children(): """Copypasta of the above test, just with an extra arg thrown in""" # Establish types tc = TypeContext() AInixType(tc, "footype") bartype = AInixType(tc, "bartype") arg1 = AInixArgument(tc, "arg1", "bartype", parent_object_name="foo_obj") arg2 = AInixArgument(tc, "arg2", "bartype", parent_object_name="bar_obj") foo_object = AInixObject(tc, "foo_object", "footype", [arg1, arg2]) bar_object = AInixObject(tc, "bar_object", "bartype") # Make an ast fin_choice = ObjectNode(bar_object) is_pres = ObjectChoiceNode(bartype) is_pres.set_choice(fin_choice) arg_node = ObjectNode(arg1.is_present_object) arg_node.set_arg_value(OPTIONAL_ARGUMENT_NEXT_ARG_NAME, is_pres) is_pres_top = ObjectChoiceNode(arg1.present_choice_type) is_pres_top.set_choice(arg_node) instance = ObjectNode(foo_object) instance.set_arg_value("arg1", is_pres_top) fin_choice2 = ObjectNode(bar_object) is_pres2 = ObjectChoiceNode(bartype) is_pres2.set_choice(fin_choice2) arg_node2 = ObjectNode(arg2.is_present_object) arg_node2.set_arg_value(OPTIONAL_ARGUMENT_NEXT_ARG_NAME, is_pres2) is_pres_top2 = ObjectChoiceNode(arg2.present_choice_type) is_pres_top2.set_choice(arg_node2) instance.set_arg_value("arg2", is_pres_top2) # Do the tests: # Unfrozen clone, leaf_pointer = instance.path_clone() assert id(clone) != id(instance) assert clone == instance # Freeze part is_pres_top.freeze() clone, leaf_pointer = instance.path_clone() assert id(clone) != id(instance) assert not clone.is_frozen assert clone == instance assert id(clone.get_choice_node_for_arg("arg1")) == id(is_pres_top) assert id(clone.get_choice_node_for_arg("arg2")) != id(is_pres_top2) # Freeze all instance.freeze() clone, leaf_pointer = instance.path_clone() assert id(clone) == id(instance) assert clone == instance assert id(clone.get_choice_node_for_arg("arg1")) == id(is_pres_top) assert id(clone.get_choice_node_for_arg("arg2")) == id(is_pres_top2) # Full unfreeze path clone, leaf_pointer = instance.path_clone( [instance, is_pres_top, arg_node, is_pres, fin_choice]) assert id(clone) != id(instance) assert not clone.is_frozen assert clone == instance assert leaf_pointer.get_nodes_to_here() == \ [instance, is_pres_top, arg_node, is_pres, fin_choice] assert id(clone.get_choice_node_for_arg("arg2")) == id(is_pres_top2) assert clone.get_choice_node_for_arg("arg2").is_frozen # Partial unfreeze path (stop early) clone, leaf_pointer = instance.path_clone( [instance, is_pres_top, arg_node]) assert id(clone) != id(instance) assert not clone.is_frozen assert clone != instance assert len(leaf_pointer.get_nodes_to_here()) == 3 new_arg_node: ObjectNode = leaf_pointer.cur_node assert new_arg_node.get_choice_node_for_arg( OPTIONAL_ARGUMENT_NEXT_ARG_NAME) is None assert new_arg_node.get_choice_node_for_arg( OPTIONAL_ARGUMENT_NEXT_ARG_NAME) is None assert clone.get_choice_node_for_arg("arg2") == is_pres_top2 assert id(clone.get_choice_node_for_arg("arg2")) == id(is_pres_top2)