def _check(reporter): assert not diff(ElementTree.fromstring("<moo>cow</moo>"), ElementTree.fromstring("<moo>cow</moo>"), reporter) assert diff(ElementTree.fromstring("<moo>cow</moo>"), ElementTree.fromstring("<moo>cow1</moo>"), reporter) assert diff(ElementTree.fromstring("<moo><c/><c1/></moo>"), ElementTree.fromstring("<moo><c/></moo>"), reporter) assert diff(ElementTree.fromstring("<moo><c/></moo>"), ElementTree.fromstring("<moo><c/>a</moo>"), reporter) assert diff(ElementTree.fromstring("<moo>*</moo>"), ElementTree.fromstring("<moo>*a</moo>"), reporter) assert not diff(_root("repository_dependencies.xml"), _root("repository_dependencies.xml"), reporter) assert not diff(_root("repository_dependencies_shed.xml"), _root("repository_dependencies_shed.xml"), reporter) assert diff(_root("repository_dependencies.xml"), _root("repository_dependencies_shed.xml"), reporter) assert diff(_root("repository_dependencies.xml"), _root("tool_dependencies_good_1.xml"), reporter) assert diff(_root("tool_dependencies_good_1.xml"), _root("tool_dependencies_good_2.xml"), reporter)
def test_diff_xunit(self): with self._isolate_repo("multi_repos_nested") as f: upload_command = [ "shed_upload", "-r", "--force_repository_creation" ] upload_command.extend(self._shed_args()) self._check_exit_code(upload_command) xunit_report = tempfile.NamedTemporaryFile(delete=False) xunit_report.flush() xunit_report.close() diff_command = ["shed_diff", "-r", "--report_xunit", xunit_report.name] diff_command.extend(self._shed_args(read_only=True)) known_good_xunit_report = os.path.join(TEST_REPOS_DIR, 'multi_repos_nested.xunit.xml') known_bad_xunit_report = os.path.join(TEST_REPOS_DIR, 'multi_repos_nested.xunit-bad.xml') self._check_exit_code(diff_command, exit_code=0) compare = open(xunit_report.name, 'r').read() if not diff( ElementTree.parse(known_good_xunit_report).getroot(), ElementTree.fromstring(compare), reporter=sys.stdout.write ): self.assertTrue(True) else: sys.stdout.write(compare) self.assertTrue(False) io.write_file( join(f, "cat1", "related_file"), "A related non-tool file (modified).\n", ) self._check_exit_code(diff_command, exit_code=1) compare = open(xunit_report.name, 'r').read() if not diff( ElementTree.parse(known_bad_xunit_report).getroot(), ElementTree.fromstring(compare), reporter=sys.stdout.write ): self.assertTrue(True) else: sys.stdout.write(compare) self.assertTrue(False) os.unlink(xunit_report.name)
def test_diff_xunit(self): with self._isolate_repo("multi_repos_nested") as f: upload_command = [ "shed_upload", "-r", "--force_repository_creation" ] upload_command.extend(self._shed_args()) self._check_exit_code(upload_command) xunit_report = tempfile.NamedTemporaryFile(delete=False) xunit_report.flush() xunit_report.close() diff_command = [ "shed_diff", "-r", "--report_xunit", xunit_report.name ] diff_command.extend(self._shed_args(read_only=True)) known_good_xunit_report = os.path.join( TEST_REPOS_DIR, 'multi_repos_nested.xunit.xml') known_bad_xunit_report = os.path.join( TEST_REPOS_DIR, 'multi_repos_nested.xunit-bad.xml') self._check_exit_code(diff_command, exit_code=0) compare = open(xunit_report.name, 'r').read() if not diff(ElementTree.parse(known_good_xunit_report).getroot(), ElementTree.fromstring(compare), reporter=sys.stdout.write): self.assertTrue(True) else: sys.stdout.write(compare) self.assertTrue(False) io.write_file( join(f, "cat1", "related_file"), "A related non-tool file (modified).\n", ) self._check_exit_code(diff_command, exit_code=1) compare = open(xunit_report.name, 'r').read() if not diff(ElementTree.parse(known_bad_xunit_report).getroot(), ElementTree.fromstring(compare), reporter=sys.stdout.write): self.assertTrue(True) else: sys.stdout.write(compare) self.assertTrue(False) os.unlink(xunit_report.name)
def test_diff_xunit(self): with self._isolate_repo("multi_repos_nested") as f: self._shed_create(recursive=True) xunit_report = tempfile.NamedTemporaryFile(delete=False) xunit_report.flush() xunit_report.close() diff_command = ["shed_diff", "-r", "--report_xunit", xunit_report.name] diff_command.extend(self._shed_args(read_only=True)) known_good_xunit_report = os.path.join(TEST_REPOS_DIR, 'multi_repos_nested.xunit.xml') known_bad_xunit_report = os.path.join(TEST_REPOS_DIR, 'multi_repos_nested.xunit-bad.xml') self._check_exit_code(diff_command, exit_code=0) with open(xunit_report.name, 'r') as fh: compare = fh.read() if diff( self._make_deterministic(ElementTree.parse(known_good_xunit_report).getroot()), self._make_deterministic(ElementTree.fromstring(compare)), reporter=sys.stdout.write ): sys.stdout.write(compare) assert False, "XUnit report different from multi_repos_nested.xunit.xml." io.write_file( join(f, "cat1", "related_file"), "A related non-tool file (modified).\n", ) self._check_exit_code(diff_command, exit_code=1) with open(xunit_report.name, 'r') as fh: compare = fh.read() if diff( self._make_deterministic(ElementTree.parse(known_bad_xunit_report).getroot()), self._make_deterministic(ElementTree.fromstring(compare)), reporter=sys.stdout.write ): sys.stdout.write(compare) assert False, "XUnit report different from multi_repos_nested.xunit-bad.xml." os.unlink(xunit_report.name)
def _shed_diff(file_a, file_b, f=sys.stdout): """Strip attributes the tool shed writes and do smart XML diff. Returns 0 if and only if the XML content is the same after stripping ``tool_shed`` and ``changeset_revision`` attributes. """ xml_a = ElementTree.parse(file_a).getroot() xml_b = ElementTree.parse(file_b).getroot() _strip_shed_attributes(xml_a) _strip_shed_attributes(xml_b) return diff.diff(xml_a, xml_b, reporter=f.write)
def test_diff_xunit(self): with self._isolate_repo("multi_repos_nested") as f: self._shed_create(recursive=True) xunit_report = tempfile.NamedTemporaryFile(delete=False) xunit_report.flush() xunit_report.close() diff_command = ["shed_diff", "-r", "--report_xunit", xunit_report.name] diff_command.extend(self._shed_args(read_only=True)) known_good_xunit_report = os.path.join(TEST_REPOS_DIR, 'multi_repos_nested.xunit.xml') known_bad_xunit_report = os.path.join(TEST_REPOS_DIR, 'multi_repos_nested.xunit-bad.xml') self._check_exit_code(diff_command, exit_code=0) compare = open(xunit_report.name, 'r').read() if diff( self._make_deterministic(ElementTree.parse(known_good_xunit_report).getroot()), self._make_deterministic(ElementTree.fromstring(compare)), reporter=sys.stdout.write ): sys.stdout.write(compare) assert False, "XUnit report different from multi_repos_nested.xunit.xml." io.write_file( join(f, "cat1", "related_file"), "A related non-tool file (modified).\n", ) self._check_exit_code(diff_command, exit_code=1) compare = open(xunit_report.name, 'r').read() if diff( self._make_deterministic(ElementTree.parse(known_bad_xunit_report).getroot()), self._make_deterministic(ElementTree.fromstring(compare)), reporter=sys.stdout.write ): sys.stdout.write(compare) assert False, "XUnit report different from multi_repos_nested.xunit-bad.xml." os.unlink(xunit_report.name)
def _shed_diff(file_a, file_b, f=sys.stdout): xml_a = ElementTree.parse(file_a).getroot() xml_b = ElementTree.parse(file_b).getroot() _strip_shed_attributes(xml_a) _strip_shed_attributes(xml_b) return diff.diff(xml_a, xml_b, reporter=f.write)