def test_no_ignore_empty(self): """ Ensure that empty tags are not ignored if ignore_empty_tags is set to False. """ doc_1 = get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + "<foo></foo>" doc_2 = ( get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + "<foo><bar /></foo>" ) f1 = file_obj_from_string(doc_1) f2 = file_obj_from_string(doc_2) with self.assertRaises(Exception): xml_compare.compare_files(f1, f2, ignore_empty_tags=False)
def test_text_compare(self): # Basic document doc_1 = get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + "<foo>bar</foo>" doc_2 = get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + "<foo>bar</foo>" f1 = file_obj_from_string(doc_1) f2 = file_obj_from_string(doc_2) self.assertIsNone(xml_compare.compare_files(f1, f2))
def test_custom_compare_function(self): def lower_case_compare(s1, s2): return s1.lower() == s2.lower() doc_1 = ( get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + '<foo a="HeLlO"></foo>' ) doc_2 = ( get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + '<foo a="hElLo"></foo>' ) f1 = file_obj_from_string(doc_1) f2 = file_obj_from_string(doc_2) with self.assertRaises(Exception): # Compare using the default compare function, which should fail xml_compare.compare_files(f1, f2) # Compare using the custom, lower-case compare function self.assertIsNone(xml_compare.compare_files(f1, f2, compare_function=lower_case_compare))
def test_text_no_ignore_whitespace(self): """ Ensure that whitespace is not ignored if ignore_whitespace is set to false. """ # Basic document doc_1 = get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + "<foo>bar</foo>" doc_2 = ( get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + """<foo> bar </foo>""" ) f1 = file_obj_from_string(doc_1) f2 = file_obj_from_string(doc_2) with self.assertRaises(Exception): xml_compare.compare_files(f1, f2, ignore_whitespace=False)
def test_ignore_empty(self): """ Ensure that empty tags are ignored if ignore_empty_tags is set to True. """ doc_1 = get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + "<foo></foo>" doc_2 = ( get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + "<foo><bar /></foo>" ) f1 = file_obj_from_string(doc_1) f2 = file_obj_from_string(doc_2) self.assertIsNone(xml_compare.compare_files(f1, f2))
def test_files(input_file_path, output_file_path, working_file_path_no_ext): """ Test all of the EAGLE files (sch, brd, and lbr) in a dictory by parsing each file, writing the parsed data to another file (the working file), and ensuring that the input and output files are identical. :param input_file_path: The directory from which to read input files. :param output_file_path: The directory to which to move files which have been successfully parsed, or ``None``. :param working_file_path_no_ext: The file name (without extension) to use to store the output file. """ # Make the output file path if it doesn't exist if not os.path.isdir(output_file_path): os.makedirs(output_file_path) # Iterate over all of the input files for f in os.listdir(input_file_path): input_file_name = input_file_path + os.sep + f ext = os.path.splitext(f)[1] if ext != '.sch' and ext != '.brd' and ext != '.lbr': continue working_file_name = working_file_path_no_ext + ext print('Parsing {0}...'.format(f)) e = Eagle.load(input_file_name) print('Saving...') e.save(working_file_name) print('Testing...') xml_compare.compare_files(input_file_name, working_file_name, compare_function) if output_file_path != None: output_file_name = output_file_path + os.sep + f shutil.move(input_file_name, output_file_name)
def test_successful_comapre_with_param(self): # Basic document doc_1 = ( get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + '<foo a="1" b="c"><bar /></foo>' ) doc_2 = ( get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + '<foo a="1" b="c"><bar /></foo>' ) f1 = file_obj_from_string(doc_1) f2 = file_obj_from_string(doc_2) self.assertIsNone(xml_compare.compare_files(f1, f2))
def test_text_compare_with_whitespace(self): """ Ensure that whitespace is ignored if ignore_whitespace is set to True. """ # Basic document doc_1 = get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + "<foo>bar</foo>" doc_2 = ( get_xml_declaration("1.0", "utf-8") + get_xml_doctype("foo", "SYSTEM", "test.dtd") + """<foo> bar </foo>""" ) f1 = file_obj_from_string(doc_1) f2 = file_obj_from_string(doc_2) self.assertIsNone(xml_compare.compare_files(f1, f2))