def add_formatted_flags(flags_name, format): """Print CMake flags using macros_printer. Arguments: flags_name - Name to search for in config_compilers. format - Function that takes a build type and flag match, and returns the string to print out. """ paths = ["compiler/"+flags_name, "compiler/ADD_"+flags_name] # This creates an iterable over elements in config_compilers # that match in non-debug mode. normal_matches = chain.from_iterable( all_matches(self.compiler_xml_tree, path, normal_dict) for path in paths ) for match in normal_matches: macros_printer.print(format(model, match.text)) # Now the same for debug mode. debug_matches = chain.from_iterable( all_matches(self.compiler_xml_tree, path, debug_dict) for path in paths ) for match in debug_matches: macros_printer.print(format(model+"_DEBUG", match.text))
def add_formatted_flags(flags_name, format): """Print CMake flags using macros_printer. Arguments: flags_name - Name to search for in config_compilers. format - Function that takes a build type and flag match, and returns the string to print out. """ paths = ["compiler/" + flags_name, "compiler/ADD_" + flags_name] # This creates an iterable over elements in config_compilers # that match in non-debug mode. normal_matches = chain.from_iterable( all_matches(self.compiler_xml_tree, path, normal_dict) for path in paths) for match in normal_matches: macros_printer.print(format("CESM", match.text)) # Now the same for debug mode. debug_matches = chain.from_iterable( all_matches(self.compiler_xml_tree, path, debug_dict) for path in paths) for match in debug_matches: macros_printer.print(format("CESM_DEBUG", match.text))
def test_no_attr_matches(self): """all_matches returns no elements if none match attributes.""" self.assertEqual( [e.text for e in all_matches(self.xml_tree, "test4/data", {"valid": "true"})], [], )
def test_ignore_attribute(self): """all_matches can ignore "extra" attributes.""" self.assertEqual( [e.text for e in all_matches(self.xml_tree, "test6/data", ignore=["ignore"])], ["the_text"] )
def test_attr_matches(self): """all_matches returns elements that match attributes.""" self.assertEqual( [e.text for e in all_matches(self.xml_tree, "test5/data", {"valid": "true", "invalid": "false"})], ["first_text", "second_text", "third_text", "fourth_text"], )
def test_multiple_matches(self): """all_matches returns many elements successfully. Elements must be returned in the right order as well. """ self.assertEqual( [e.text for e in all_matches(self.xml_tree, "test2/data")], ["first_text", "second_text"], )
def test_no_attr_matches(self): """all_matches returns no elements if none match attributes.""" self.assertEqual( [ e.text for e in all_matches(self.xml_tree, "test4/data", {"valid": "true"}) ], [], )
def test_attr_matches(self): """all_matches returns elements that match attributes.""" self.assertEqual( [ e.text for e in all_matches(self.xml_tree, "test5/data", { "valid": "true", "invalid": "false" }) ], ["first_text", "second_text", "third_text", "fourth_text"], )
def string_to_elements(xml_str, ignore="key"): """Converts an XML string to a list of its "ENV" elements.""" return all_matches(ElementTree(XML(xml_str)), "ENV", ignore=ignore)
def test_no_matches(self): """all_matches returns no elements if none are found.""" self.assertEqual( [e.text for e in all_matches(self.xml_tree, "test3/data")], [], )
def test_one_match(self): """all_matches returns one element successfully.""" self.assertEqual( [e.text for e in all_matches(self.xml_tree, "test1/data")], ["the_text"], )
def test_ignore_attribute(self): """all_matches can ignore "extra" attributes.""" self.assertEqual([ e.text for e in all_matches( self.xml_tree, "test6/data", ignore=["ignore"]) ], ["the_text"])