"Error while error handling");
} else {
g_set_error(err, CR_XML_PARSER_ERROR, CRE_XMLPARSER,
- PyString_AsString(pystr));
+ "%s", PyString_AsString(pystr));
}
Py_XDECREF(pystr);
TEST_DATA_PATH = os.path.normpath(os.path.join(__file__, "../../../testdata"))
+COMPRESSED_FILES_PATH = os.path.join(TEST_DATA_PATH, "compressed_files")
+MODIFIED_REPO_FILES_PATH = os.path.join(TEST_DATA_PATH, "modified_repo_files")
PACKAGES_PATH = os.path.join(TEST_DATA_PATH, "packages")
REPOS_PATH = TEST_DATA_PATH
-COMPRESSED_FILES_PATH = os.path.join(TEST_DATA_PATH, "compressed_files")
TEST_FILES_PATH = os.path.join(TEST_DATA_PATH, "test_files")
-# Test packages
+# Modified repo files
+
+PRIMARY_ERROR_00_PATH = os.path.join(MODIFIED_REPO_FILES_PATH,
+ "error_00-primary.xml")
+PRIMARY_MULTI_WARN_00_PATH = os.path.join(MODIFIED_REPO_FILES_PATH,
+ "multiple_warnings_00-primary.xml")
+
+FILELISTS_ERROR_00_PATH = os.path.join(MODIFIED_REPO_FILES_PATH,
+ "error_00-filelists.xml")
+FILELISTS_MULTI_WARN_00_PATH = os.path.join(MODIFIED_REPO_FILES_PATH,
+ "multiple_warnings_00-filelists.xml")
+
+OTHER_ERROR_00_PATH = os.path.join(MODIFIED_REPO_FILES_PATH,
+ "error_00-other.xml")
+OTHER_MULTI_WARN_00_PATH = os.path.join(MODIFIED_REPO_FILES_PATH,
+ "multiple_warnings_00-other.xml")
+
+# Packages
+
PKG_ARCHER = "Archer-3.4.5-6.x86_64.rpm"
PKG_ARCHER_PATH = os.path.join(PACKAGES_PATH, PKG_ARCHER)
PKG_SUPER_KERNEL_PATH = os.path.join(PACKAGES_PATH, PKG_SUPER_KERNEL)
# Test repositories
+
REPO_00_PATH = os.path.join(REPOS_PATH, "repo_00")
REPO_00_PRIXML = os.path.join(REPO_00_PATH, "repodata/",
"dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9-primary.xml.gz")
REPO_02_OTHXML = os.path.join(REPO_02_PATH, "repodata/",
"ab5d3edeea50f9b4ec5ee13e4d25c147e318e3a433dbabc94d3461f58ac28255-other.xml.gz")
-# Other test files
+# Test files
FILE_BINARY = "binary_file"
FILE_BINARY_PATH = os.path.join(TEST_FILES_PATH, FILE_BINARY)
self.assertEqual(userdata["pkgcb_calls"], 2)
self.assertEqual(userdata["warnings"], [])
+ def test_xml_parser_primary_warnings(self):
+
+ userdata = {
+ "pkgs": [],
+ "warnings": []
+ }
+
+ def newpkgcb(pkgId, name, arch):
+ pkg = cr.Package()
+ userdata["pkgs"].append(pkg)
+ return pkg
+
+ def warningcb(warn_type, msg):
+ userdata["warnings"].append((warn_type, msg))
+
+ cr.xml_parse_primary(PRIMARY_MULTI_WARN_00_PATH,
+ newpkgcb,
+ None,
+ warningcb,
+ 1)
+
+ self.assertEqual([pkg.name for pkg in userdata["pkgs"]],
+ ['fake_bash', 'super_kernel'])
+ self.assertEqual(userdata["warnings"],
+ [(0, 'Unknown element "fooelement"'),
+ (1, 'Missing attribute "type" of a package element'),
+ (0, 'Unknown element "foo"'),
+ (3, 'Conversion of "foobar" to integer failed'),
+ (2, 'Unknown file type "xxx"'),
+ (0, 'Unknown element "bar"')])
+
+ def test_xml_parser_primary_error(self):
+
+ userdata = { "pkgs": [] }
+
+ def newpkgcb(pkgId, name, arch):
+ pkg = cr.Package()
+ userdata["pkgs"].append(pkg)
+ return pkg
+
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_primary,
+ PRIMARY_ERROR_00_PATH, newpkgcb, None, None, 1)
+
+ self.assertEqual([pkg.name for pkg in userdata["pkgs"]], ['fake_bash'])
+
+ def test_xml_parser_primary_newpkgcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_primary,
+ REPO_02_PRIXML, newpkgcb, None, None, 1)
+
+ def test_xml_parser_primary_pkgcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ return cr.Package()
+ def pkgcb():
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_primary,
+ REPO_02_PRIXML, newpkgcb, pkgcb, None, 1)
+
+ def test_xml_parser_primary_warningcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ return cr.Package()
+ def warningcb(type, msg):
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_primary,
+ PRIMARY_MULTI_WARN_00_PATH,
+ newpkgcb, None, warningcb, 1)
+
class TestCaseXmlParserFilelists(unittest.TestCase):
def test_xml_parser_filelists_repo01(self):
self.assertEqual(userdata["pkgcb_calls"], 2)
self.assertEqual(userdata["warnings"], [])
+ def test_xml_parser_filelists_warnings(self):
+
+ userdata = {
+ "pkgs": [],
+ "warnings": []
+ }
+
+ def newpkgcb(pkgId, name, arch):
+ pkg = cr.Package()
+ userdata["pkgs"].append(pkg)
+ return pkg
+
+ def warningcb(warn_type, msg):
+ userdata["warnings"].append((warn_type, msg))
+
+ cr.xml_parse_filelists(FILELISTS_MULTI_WARN_00_PATH,
+ newpkgcb,
+ None,
+ warningcb)
+
+ self.assertEqual([pkg.name for pkg in userdata["pkgs"]],
+ ['fake_bash', 'super_kernel'])
+ self.assertEqual(userdata["warnings"],
+ [(1, 'Missing attribute "arch" of a package element'),
+ (2, 'Unknown file type "xxx"'),
+ (0, 'Unknown element "bar"')])
+
+ def test_xml_parser_filelists_error(self):
+
+ userdata = { "pkgs": [] }
+
+ def newpkgcb(pkgId, name, arch):
+ pkg = cr.Package()
+ userdata["pkgs"].append(pkg)
+ return pkg
+
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_filelists,
+ FILELISTS_ERROR_00_PATH, newpkgcb, None, None)
+
+ self.assertEqual([pkg.name for pkg in userdata["pkgs"]], [])
+
+ def test_xml_parser_filelists_newpkgcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_filelists,
+ REPO_02_FILXML, newpkgcb, None, None)
+
+ def test_xml_parser_filelists_pkgcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ return cr.Package()
+ def pkgcb():
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_filelists,
+ REPO_02_FILXML, newpkgcb, pkgcb, None)
+
+ def test_xml_parser_filelists_warningcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ return cr.Package()
+ def warningcb(type, msg):
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_filelists,
+ FILELISTS_MULTI_WARN_00_PATH,
+ newpkgcb, None, warningcb)
+
class TestCaseXmlParserOther(unittest.TestCase):
def test_xml_parser_other_repo01(self):
self.assertEqual(userdata["pkgcb_calls"], 2)
self.assertEqual(userdata["warnings"], [])
+ def test_xml_parser_other_warnings(self):
+
+ userdata = {
+ "pkgs": [],
+ "warnings": []
+ }
-# TODO:
-# Test warnings
+ def newpkgcb(pkgId, name, arch):
+ pkg = cr.Package()
+ userdata["pkgs"].append(pkg)
+ return pkg
+
+ def warningcb(warn_type, msg):
+ userdata["warnings"].append((warn_type, msg))
+
+ cr.xml_parse_other(OTHER_MULTI_WARN_00_PATH,
+ newpkgcb,
+ None,
+ warningcb)
+
+ self.assertEqual([pkg.name for pkg in userdata["pkgs"]],
+ [None, 'super_kernel'])
+ self.assertEqual(userdata["warnings"],
+ [(1, 'Missing attribute "name" of a package element'),
+ (0, 'Unknown element "bar"'),
+ (3, 'Conversion of "xxx" to integer failed')])
+
+ def test_xml_parser_other_error(self):
+
+ userdata = { "pkgs": [] }
+
+ def newpkgcb(pkgId, name, arch):
+ pkg = cr.Package()
+ userdata["pkgs"].append(pkg)
+ return pkg
+
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_other,
+ OTHER_ERROR_00_PATH, newpkgcb, None, None)
+
+ self.assertEqual([pkg.name for pkg in userdata["pkgs"]], [])
+
+ def test_xml_parser_other_newpkgcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_other,
+ REPO_02_OTHXML, newpkgcb, None, None)
+
+ def test_xml_parser_other_pkgcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ return cr.Package()
+ def pkgcb():
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_other,
+ REPO_02_OTHXML, newpkgcb, pkgcb, None)
+
+ def test_xml_parser_other_warningcb_abort(self):
+ def newpkgcb(pkgId, name, arch):
+ return cr.Package()
+ def warningcb(type, msg):
+ raise Error("Foo error")
+ self.assertRaises(cr.CreaterepoCError,
+ cr.xml_parse_other,
+ OTHER_MULTI_WARN_00_PATH,
+ newpkgcb, None, warningcb)
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<filelists xmlns="http://linux.duke.edu/metadata/filelists" packages="2">
+<package name="fake_bash" arch="x86_64"> <!-- ERROR: Missing pkgid attr -->
+ <version epoch="0" ver="1.1.1" rel="1"/>
+ <file>/usr/bin/fake_bash</file>
+ <foo>foo_element</foo>
+</package>
+<package pkgid="6d43a638af70ef899933b1fd86a866f18f65b0e0e17dcbf2e42bfd0cdd7c63c3" name="super_kernel" arch="x86_64">
+ <version epoch="0" ver="6.0.1" rel="2"/>
+ <file>/usr/bin/super_kernel</file>
+ <file>/usr/share/man/super_kernel.8.gz</file>
+</package>
+</filelists>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<otherdata xmlns="http://linux.duke.edu/metadata/other" packages="2">
+<package name="fake_bash" arch="x86_64"> <!-- ERROR: Missing pkgid attr -->
+ <version epoch="0" ver="1.1.1" rel="1"/>
+ <changelog author="Tomas Mlcoch <tmlcoch@redhat.com> - 1.1.1-1" date="1334664000">- First release</changelog>
+ <foo>foo element</foo>
+</package>
+<package pkgid="6d43a638af70ef899933b1fd86a866f18f65b0e0e17dcbf2e42bfd0cdd7c63c3" name="super_kernel" arch="x86_64">
+ <version epoch="0" ver="6.0.1" rel="2"/>
+ <changelog author="Tomas Mlcoch <tmlcoch@redhat.com> - 6.0.1-1" date="1334664000">- First release</changelog>
+ <changelog author="Tomas Mlcoch <tmlcoch@redhat.com> - 6.0.1-2" date="1334664001">- Second release</changelog>
+</package>
+</otherdata>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata xmlns="http://linux.duke.edu/metadata/common" xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="2">
+<package type="rpm">
+ <name>fake_bash</name>
+ <arch>x86_64</arch>
+ <version epoch="0" ver="1.1.1" rel="1"/>
+ <!-- ERROR: Missing checksum! -->
+ <summary>Fake bash</summary>
+ <description>Fake bash package</description>
+ <packager></packager>
+ <url>http://fake_bash_shell.com/</url>
+ <time file="1334670842" build="1334670842"/>
+ <size package="2237" installed="0" archive="256"/>
+<location href="fake_bash-1.1.1-1.x86_64.rpm"/>
+ <format>
+ <rpm:license>GPL</rpm:license>
+ <rpm:vendor/>
+ <rpm:group>System Environment/Shells</rpm:group>
+ <rpm:buildhost>localhost.localdomain</rpm:buildhost>
+ <rpm:sourcerpm>fake_bash-1.1.1-1.src.rpm</rpm:sourcerpm>
+ <rpm:header-range start="280" end="2057"/>
+ <rpm:provides>
+ <rpm:entry name="bash"/>
+ <rpm:entry name="fake_bash" flags="EQ" epoch="0" ver="1.1.1" rel="1"/>
+ <rpm:entry name="fake_bash(x86-64)" flags="EQ" epoch="0" ver="1.1.1" rel="1"/>
+ </rpm:provides>
+ <rpm:requires>
+ <rpm:entry name="super_kernel"/>
+ </rpm:requires>
+ <file>/usr/bin/fake_bash</file>
+ </format>
+</package>
+<package type="rpm">
+ <name>super_kernel</name>
+ <arch>x86_64</arch>
+ <version epoch="0" ver="6.0.1" rel="2"/>
+ <checksum type="sha256" pkgid="YES">6d43a638af70ef899933b1fd86a866f18f65b0e0e17dcbf2e42bfd0cdd7c63c3</checksum>
+ <summary>Test package</summary>
+ <description>This package has provides, requires, obsoletes, conflicts options.</description>
+ <packager></packager>
+ <url>http://so_super_kernel.com/it_is_awesome/yep_it_really_is</url>
+ <time file="1334670843" build="1334670843"/>
+ <size package="2845" installed="0" archive="404"/>
+<location href="super_kernel-6.0.1-2.x86_64.rpm"/>
+ <format>
+ <rpm:license>LGPLv2</rpm:license>
+ <rpm:vendor/>
+ <rpm:group>Applications/System</rpm:group>
+ <rpm:buildhost>localhost.localdomain</rpm:buildhost>
+ <rpm:sourcerpm>super_kernel-6.0.1-2.src.rpm</rpm:sourcerpm>
+ <rpm:header-range start="280" end="2637"/>
+ <rpm:provides>
+ <rpm:entry name="not_so_super_kernel" flags="LT" epoch="0" ver="5.8.0"/>
+ <rpm:entry name="super_kernel" flags="EQ" epoch="0" ver="6.0.0"/>
+ <rpm:entry name="super_kernel" flags="EQ" epoch="0" ver="6.0.1" rel="2"/>
+ <rpm:entry name="super_kernel(x86-64)" flags="EQ" epoch="0" ver="6.0.1" rel="2"/>
+ </rpm:provides>
+ <rpm:requires>
+ <rpm:entry name="bzip2" flags="GE" epoch="0" ver="1.0.0" pre="1"/>
+ <rpm:entry name="expat" pre="1"/>
+ <rpm:entry name="glib" flags="GE" epoch="0" ver="2.26.0"/>
+ <rpm:entry name="zlib"/>
+ </rpm:requires>
+ <rpm:conflicts>
+ <rpm:entry name="kernel"/>
+ <rpm:entry name="super_kernel" flags="EQ" epoch="0" ver="5.0.0"/>
+ <rpm:entry name="super_kernel" flags="LT" epoch="0" ver="4.0.0"/>
+ </rpm:conflicts>
+ <rpm:obsoletes>
+ <rpm:entry name="kernel"/>
+ <rpm:entry name="super_kernel" flags="EQ" epoch="0" ver="5.9.0"/>
+ </rpm:obsoletes>
+ <file>/usr/bin/super_kernel</file>
+ </format>
+</package>
+</metadata>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<filelists xmlns="http://linux.duke.edu/metadata/filelists" packages="2">
+ <package pkgid="90f61e546938a11449b710160ad294618a5bd3062e46f8cf851fd0088af184b7" name="fake_bash"> <!-- WARNING: Missing "arch" attr -->
+ <version epoch="0" ver="1.1.1" rel="1"/>
+ <file type="xxx">/usr/bin/fake_bash</file> <!-- WARNING: Bad type "xxx" -->
+ <bar> <!-- WARNING: Unknown element -->
+ <foo>foo_element</foo>
+ <package pkgid="foobar"/>
+ </bar>
+</package>
+<package pkgid="6d43a638af70ef899933b1fd86a866f18f65b0e0e17dcbf2e42bfd0cdd7c63c3" name="super_kernel" arch="x86_64">
+ <version epoch="0" ver="6.0.1" rel="2"/>
+ <file>/usr/bin/super_kernel</file>
+ <file>/usr/share/man/super_kernel.8.gz</file>
+</package>
+</filelists>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<otherdata xmlns="http://linux.duke.edu/metadata/other" packages="2">
+ <package pkgid="90f61e546938a11449b710160ad294618a5bd3062e46f8cf851fd0088af184b7" arch="x86_64"> <!-- Missing "name" element -->
+ <version epoch="0" ver="1.1.1" rel="1"/>
+ <changelog author="Tomas Mlcoch <tmlcoch@redhat.com> - 1.1.1-1" date="1334664000">- First release</changelog>
+ <bar> <!-- WARNING: Unknown element -->
+ <foo>foo element</foo>
+ <package pkgid="foobar"/>
+ </bar>
+</package>
+<package pkgid="6d43a638af70ef899933b1fd86a866f18f65b0e0e17dcbf2e42bfd0cdd7c63c3" name="super_kernel" arch="x86_64">
+ <version epoch="0" ver="6.0.1" rel="2"/>
+ <changelog author="Tomas Mlcoch <tmlcoch@redhat.com> - 6.0.1-1" date="1334664000">- First release</changelog>
+ <changelog author="Tomas Mlcoch <tmlcoch@redhat.com> - 6.0.1-2" date="xxx">- Second release</changelog> <!-- WARNING: "xxx" string instead of number -->
+</package>
+</otherdata>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata xmlns="http://linux.duke.edu/metadata/common" xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="2">
+<fooelement/> <!-- WARNING: Unknown element -->
+<package> <!-- WARNING: Missing type attr -->
+ <name>fake_bash</name>
+ <arch>x86_64</arch>
+ <version epoch="0" ver="1.1.1" rel="1"/>
+ <checksum type="sha256" pkgid="YES">90f61e546938a11449b710160ad294618a5bd3062e46f8cf851fd0088af184b7</checksum>
+ <summary>Fake bash</summary>
+ <description>Fake bash package</description>
+ <packager></packager>
+ <foo>foo element</foo> <!-- WARNING: "foo" unknown element -->
+ <url>http://fake_bash_shell.com/</url>
+ <time file="1334670842" build="1334670842"/>
+ <size package="2237" installed="0" archive="256"/>
+<location href="fake_bash-1.1.1-1.x86_64.rpm"/>
+ <format>
+ <rpm:license>GPL</rpm:license>
+ <rpm:vendor/>
+ <rpm:group>System Environment/Shells</rpm:group>
+ <rpm:buildhost>localhost.localdomain</rpm:buildhost>
+ <rpm:sourcerpm>fake_bash-1.1.1-1.src.rpm</rpm:sourcerpm>
+ <rpm:header-range start="280" end="foobar"/> <!-- WARNING: "foobar" string instead of number -->
+ <rpm:provides>
+ <rpm:entry name="bash"/>
+ <rpm:entry name="fake_bash" flags="EQ" epoch="0" ver="1.1.1" rel="1"/>
+ <rpm:entry name="fake_bash(x86-64)" flags="EQ" epoch="0" ver="1.1.1" rel="1"/>
+ </rpm:provides>
+ <rpm:requires>
+ <rpm:entry name="super_kernel"/>
+ </rpm:requires>
+ <file type="xxx">/usr/bin/fake_bash</file> <!-- WARNING: Bad type "xxx" -->
+ </format>
+</package>
+<bar> <!-- WARNING: Unknwon element -->
+ <foo>foo element</foo>
+ <package type="foobar"/>
+</bar>
+<package type="rpm">
+ <name>super_kernel</name>
+ <arch>x86_64</arch>
+ <version epoch="0" ver="6.0.1" rel="2"/>
+ <checksum type="sha256" pkgid="YES">6d43a638af70ef899933b1fd86a866f18f65b0e0e17dcbf2e42bfd0cdd7c63c3</checksum>
+ <summary>Test package</summary>
+ <description>This package has provides, requires, obsoletes, conflicts options.</description>
+ <packager></packager>
+ <url>http://so_super_kernel.com/it_is_awesome/yep_it_really_is</url>
+ <time file="1334670843" build="1334670843"/>
+ <size package="2845" installed="0" archive="404"/>
+<location href="super_kernel-6.0.1-2.x86_64.rpm"/>
+ <format>
+ <rpm:license>LGPLv2</rpm:license>
+ <rpm:vendor/>
+ <rpm:group>Applications/System</rpm:group>
+ <rpm:buildhost>localhost.localdomain</rpm:buildhost>
+ <rpm:sourcerpm>super_kernel-6.0.1-2.src.rpm</rpm:sourcerpm>
+ <rpm:header-range start="280" end="2637"/>
+ <rpm:provides>
+ <rpm:entry name="not_so_super_kernel" flags="LT" epoch="0" ver="5.8.0"/>
+ <rpm:entry name="super_kernel" flags="EQ" epoch="0" ver="6.0.0"/>
+ <rpm:entry name="super_kernel" flags="EQ" epoch="0" ver="6.0.1" rel="2"/>
+ <rpm:entry name="super_kernel(x86-64)" flags="EQ" epoch="0" ver="6.0.1" rel="2"/>
+ </rpm:provides>
+ <rpm:requires>
+ <rpm:entry name="bzip2" flags="GE" epoch="0" ver="1.0.0" pre="1"/>
+ <rpm:entry name="expat" pre="1"/>
+ <rpm:entry name="glib" flags="GE" epoch="0" ver="2.26.0"/>
+ <rpm:entry name="zlib"/>
+ </rpm:requires>
+ <rpm:conflicts>
+ <rpm:entry name="kernel"/>
+ <rpm:entry name="super_kernel" flags="EQ" epoch="0" ver="5.0.0"/>
+ <rpm:entry name="super_kernel" flags="LT" epoch="0" ver="4.0.0"/>
+ </rpm:conflicts>
+ <rpm:obsoletes>
+ <rpm:entry name="kernel"/>
+ <rpm:entry name="super_kernel" flags="EQ" epoch="0" ver="5.9.0"/>
+ </rpm:obsoletes>
+ <file>/usr/bin/super_kernel</file>
+ </format>
+</package>
+</metadata>