summaryrefslogtreecommitdiff
path: root/swig/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'swig/python/tests')
-rw-r--r--swig/python/tests/CMakeLists.txt11
-rw-r--r--swig/python/tests/arch.py46
-rw-r--r--swig/python/tests/commit_callbacks.py273
-rw-r--r--swig/python/tests/installed_path.py27
-rw-r--r--swig/python/tests/loading.py16
-rw-r--r--swig/python/tests/problems.py21
-rw-r--r--swig/python/tests/repoinfo.py70
-rw-r--r--swig/python/tests/starting.py19
8 files changed, 483 insertions, 0 deletions
diff --git a/swig/python/tests/CMakeLists.txt b/swig/python/tests/CMakeLists.txt
new file mode 100644
index 0000000..932da25
--- /dev/null
+++ b/swig/python/tests/CMakeLists.txt
@@ -0,0 +1,11 @@
+##
+# CMakeLists.txt for libzypp-bindings/swig/python/tests
+#
+
+ENABLE_TESTING()
+
+ADD_TEST(bindings_python_loading python ${CMAKE_CURRENT_SOURCE_DIR}/loading.py)
+ADD_TEST(bindings_python_repoinfo python ${CMAKE_CURRENT_SOURCE_DIR}/repoinfo.py)
+ADD_TEST(bindings_python_commit_callbacks python ${CMAKE_CURRENT_SOURCE_DIR}/commit_callbacks.py)
+ADD_TEST(bindings_python_problems python ${CMAKE_CURRENT_SOURCE_DIR}/problems.py)
+# ADD_TEST(bindings_python_installed_path python ${CMAKE_CURRENT_SOURCE_DIR}/installed_path.py)
diff --git a/swig/python/tests/arch.py b/swig/python/tests/arch.py
new file mode 100644
index 0000000..524d217
--- /dev/null
+++ b/swig/python/tests/arch.py
@@ -0,0 +1,46 @@
+#
+# Arch
+#
+import unittest
+
+import os
+cwd = os.path.abspath(os.path.dirname(__file__))
+
+import sys
+sys.path.insert(0, cwd + "/../../../build/swig/python")
+from zypp import Arch
+
+class TestSequenceFunctions(unittest.TestCase):
+
+ def testarch(self):
+ a = Arch("i386")
+ assert a
+ assert "i386" == a.__str__()
+ assert a.is_builtin()
+
+ b = Arch("i486")
+ assert b
+ assert "i486" == b.__str__()
+ assert b.is_builtin()
+ assert a == b.base_arch()
+ assert a < b
+ assert a.compatible_with(b)
+
+ z = Arch("xyzzy")
+ assert z
+ assert "xyzzy" == z.__str__()
+ assert not z.is_builtin()
+
+ assert Arch("noarch") == Arch.noarch()
+ assert a, Arch.i386()
+ assert b, Arch.i486()
+ assert Arch("i586") == Arch.i586()
+ assert Arch("i686") == Arch.i686()
+ assert Arch("x86_64") == Arch.x86_64()
+ assert Arch("ia64") == Arch.ia64()
+ assert Arch("ppc") == Arch.ppc()
+ assert Arch("ppc64") == Arch.ppc64()
+ assert Arch("s390") == Arch.s390()
+ assert Arch("s390x") == Arch.s390x()
+if __name__ == '__main__':
+ unittest.main()
diff --git a/swig/python/tests/commit_callbacks.py b/swig/python/tests/commit_callbacks.py
new file mode 100644
index 0000000..24a1ff3
--- /dev/null
+++ b/swig/python/tests/commit_callbacks.py
@@ -0,0 +1,273 @@
+#
+# Test commit callbacks
+#
+#
+# Callbacks are implemented by calling a specific object function
+#
+# You need
+# - define a (receiver) class which include the function(s) you're interested in.
+# - create an object instance of this class
+# - tell Zypp where to send the callbacks
+#
+# There can only be one receiver instance be active at any time.
+# So if you want to receive different callbacks, define the appropriate
+# functions in the one receiver class
+#
+#
+# See below for sample code
+#
+#
+import unittest
+
+import os
+cwd = os.path.abspath(os.path.dirname(__file__))
+
+import sys
+sys.path.insert(0, cwd + "/../../../build/swig/python")
+
+import zypp
+
+#
+# This is counting the number of times our callback was called
+# (its just for testing purposes to assert() that the callback was
+# actually run)
+#
+removals = 0
+installs = 0
+
+
+#
+# This is the receiver class.
+# The _class name_ does not matter, but the _function name_ does
+#
+# TODO: provide a complete list of function names and parameters
+#
+# I. Patch message
+# patch_message(zypp::Patch) - show patch message
+#
+# II. Patch script
+# patch_script_start(zypp::Package, String)
+# patch_script_progress(zypp::Notify, String)
+# patch_script_problem(String)
+# patch_script_finish()
+#
+# III. Removal
+# removal_start(zypp::Resolvable) - start of resolvable uninstall
+# removal_progress(zypp::Resolvable, Integer) - progress in percent
+# removal_problem(zypp::Resolvable, zypp::Error, String) - problem report
+# removal_finish(zypp::Resolvable, zypp::Error, String) - uninstall finish
+#
+# IV. Install
+# install_start(zypp::Resolvable) - start of resolvable uninstall
+# install_progress(zypp::Resolvable, Integer) - progress in percent
+# install_problem(zypp::Resolvable, zypp::Error, String) - problem report
+# install_finish(zypp::Resolvable, zypp::Error, String) - uninstall finish
+#
+
+class CommitReceiver:
+
+ ################################
+ # removal callbacks
+
+ #
+ # removal_start() will be called at the beginning of a resolvable (typically package) uninstall
+ # and be passed the resolvable to-be-removed
+ #
+ def removal_start(self, resolvable):
+ # testing: increment the number of removals and print the resolvable
+ global removals
+ removals += 1
+ print "Starting to remove ", resolvable
+
+ #
+ # removal_progress() is called during a resolvable (typically package) uninstall
+ # and be passed the resolvable to-be-removed and a percentage value
+ # Must return True (continue) or False (abort removal)
+ #
+ def removal_progress(self, resolvable, percentage):
+ assert percentage == 42
+ print "Remove of ", resolvable, " at ", percentage, "%"
+ return True
+
+ #
+ # removal_finish() is called after a resolvable (typically package) was uninstalled
+ # and be passed the resolvable just removed and a status (string) with detail (string)
+ # status is either
+ # - "no_error": typical 'good' status
+ # - "not_found": resolvable not found (i.e. not installed)
+ # - "io": (disk) I/O error
+ # - "invalid": any other error
+ #
+ def removal_finish(self, resolvable, status, detail):
+ print "Remove of ", resolvable.name(), " finished with problem ", status, ": ", detail
+
+ #
+ # report a problem during resolvable removal
+ # error is the same as 'status' of removal_finish()
+ #
+ # Must return "abort", "retry" or "ignore"
+ #
+ def removal_problem(self, resolvable, error, description):
+ print "Remove of ", resolvable.name(), " has problem ", error, ": ", description
+ return "ignore"
+
+ ################################
+ # install callbacks
+
+ #
+ # install_start() will be called at the beginning of a resolvable (typically package) install
+ # and be passed the resolvable to-be-installed
+ #
+ def install_start(self, resolvable):
+ # testing: increment the number of removals and print the resolvable
+ global installs
+ installs += 1
+ print "Starting to install ", resolvable
+
+ #
+ # install_progress() is called during a resolvable (typically package) install
+ # and be passed the resolvable to-be-removed and a percentage value
+ # Must return True (continue) or False (abort install)
+ #
+ def install_progress(self, resolvable, percentage):
+ assert percentage == 42
+ print "Install of ", resolvable, " at ", percentage, "%"
+ return True
+
+ #
+ # install_finish() is called after a resolvable (typically package) was installed
+ # and be passed the resolvable just installed and a status (string) with detail (string)
+ # status is either
+ # - "no_error": typical 'good' status
+ # - "not_found": resolvable not found
+ # - "io": (disk) I/O error
+ # - "invalid": any other error
+ #
+ def install_finish(self, resolvable, status, detail):
+ print "Install of ", resolvable.name(), " finished with problem ", status, ": ", detail
+
+ #
+ # report a problem during resolvable install
+ # error is the same as 'status' of install_finish()
+ #
+ # Must return "abort", "retry" or "ignore"
+ #
+ def install_problem(self, resolvable, error, description):
+ print "Install of ", resolvable.name(), " has problem ", error, ": ", description
+ return "ignore"
+
+#
+# Testcase for Callbacks
+#
+
+class CommitCallbacksTestCase(unittest.TestCase):
+ def setUp(self):
+ #
+ # Normal zypp startup
+ #
+ self.Z = zypp.ZYppFactory_instance().getZYpp()
+ self.Z.initializeTarget( zypp.Pathname("/") )
+ self.Z.target().load()
+
+ # The 'zypp.CommitCallbacksEmitter()' is a test/debug class
+ # which can be used to trigger various callbacks
+ # (This is callback test code - we cannot do an actual package uninstall here!)
+ self.commit_callbacks_emitter = zypp.CommitCallbacksEmitter()
+
+ #
+ # create an instance of our CommitReceiver class defined above
+ #
+ self.commit_receiver = CommitReceiver()
+
+ # zypp.CommitCallbacks is the callback 'handler' which must be informed
+ # about the receiver
+ self.commit_callbacks = zypp.CommitCallbacks()
+
+ #
+ # Ensure that no other receiver is registered
+ #
+ assert None == self.commit_callbacks.receiver()
+
+ #
+ # Connect the receiver instance with the callback handler
+ #
+ self.commit_callbacks.connect(self.commit_receiver)
+
+ #
+ # Ensure that its set correctly
+ #
+ assert self.commit_receiver == self.commit_callbacks.receiver()
+
+ def tearDown(self):
+ #
+ # Disconnect the receiver from the callback handler
+ #
+ self.commit_callbacks.disconnect()
+
+ #
+ # Ensure that the disconnect was successful
+ #
+ assert None == self.commit_callbacks.receiver()
+
+ # test patch message
+ def testPatchMessageCallback(self):
+ #
+ # Ugh, this would need a patch with a message :-/
+ #
+ # FIXME
+ assert True
+
+ # test patch script
+ def testPatchScriptCallback(self):
+ #
+ # Ugh, this would need a patch with a script :-/
+ #
+ # FIXME
+ assert True
+
+ # this will test the remove callback
+ def testRemoveCallback(self):
+
+ #
+ # Loop over pool - just to get real instances of Resolvable
+ #
+ for item in self.Z.pool():
+ print "Emitting removal of ", item.resolvable()
+ #
+ # Use the zypp.CommitCallbacksEmitter to fake an actual package removal
+ #
+ resolvable = item.resolvable()
+ self.commit_callbacks_emitter.remove_start(resolvable)
+ self.commit_callbacks_emitter.remove_progress(resolvable, 42)
+# self.commit_callbacks_emitter.remove_problem(resolvable, zypp.REMOVE_NO_ERROR, "All fine")
+# self.commit_callbacks_emitter.remove_finish(resolvable, zypp.REMOVE_NO_ERROR, "Done")
+ break # one is sufficient
+ #
+ # Did the actual callback got executed ?
+ #
+ assert removals == 1
+
+ # this will test the install callback
+ def testInstallCallback(self):
+
+ #
+ # Loop over pool - just to get real instances of Resolvable
+ #
+ for item in self.Z.pool():
+ print "Emitting install of ", item.resolvable()
+ #
+ # Use the zypp.CommitCallbacksEmitter to fake an actual package removal
+ #
+ resolvable = item.resolvable()
+ self.commit_callbacks_emitter.install_start(resolvable)
+ self.commit_callbacks_emitter.install_progress(resolvable, 42)
+# self.commit_callbacks_emitter.install_problem(resolvable, zypp.REMOVE_NO_ERROR, "All fine")
+# self.commit_callbacks_emitter.install_finish(resolvable, zypp.REMOVE_NO_ERROR, "Done")
+ break # one is sufficient
+ #
+ # Did the actual callback got executed ?
+ #
+ assert installs == 1
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/swig/python/tests/installed_path.py b/swig/python/tests/installed_path.py
new file mode 100644
index 0000000..95cecd7
--- /dev/null
+++ b/swig/python/tests/installed_path.py
@@ -0,0 +1,27 @@
+import unittest
+
+import os
+cwd = os.path.abspath(os.path.dirname(__file__))
+
+import sys
+sys.path.insert(0, cwd + "/../../../build/swig/python")
+
+class TestSequenceFunctions(unittest.TestCase):
+
+ def testpath(self):
+ import zypp
+ Z = zypp.ZYppFactory.instance().getZYpp()
+ assert Z
+ Z.initializeTarget( zypp.Pathname("/") )
+ Z.target().load()
+ installed_pkgs = Z.pool()
+ for item in installed_pkgs:
+ if zypp.isKindPackage(item):
+ print "Repopath %s" % item.repoInfo().packagesPath()
+ item = zypp.asKindPackage(item)
+ print "Location filename %s" % item.location().filename()
+ print "%s.%s %s:%d" % (item.name(), item.arch(), item.edition(), item.installSize())
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/swig/python/tests/loading.py b/swig/python/tests/loading.py
new file mode 100644
index 0000000..4072ea7
--- /dev/null
+++ b/swig/python/tests/loading.py
@@ -0,0 +1,16 @@
+import unittest
+
+import os
+cwd = os.path.abspath(os.path.dirname(__file__))
+
+import sys
+sys.path.insert(0, cwd + "/../../../build/swig/python")
+
+class TestSequenceFunctions(unittest.TestCase):
+
+ def testloading(self):
+ import zypp
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/swig/python/tests/problems.py b/swig/python/tests/problems.py
new file mode 100644
index 0000000..0406290
--- /dev/null
+++ b/swig/python/tests/problems.py
@@ -0,0 +1,21 @@
+import unittest
+
+import os
+cwd = os.path.abspath(os.path.dirname(__file__))
+
+import sys
+sys.path.insert(0, cwd + "/../../../build/swig/python")
+
+class TestSequenceFunctions(unittest.TestCase):
+
+ def testproblems(self):
+ import zypp
+ Z = zypp.ZYppFactory.instance().getZYpp()
+ assert Z
+ if not Z.resolver().resolvePool():
+ for problem in Z.resolver().problems():
+ print "Problem %s" % problem.description()
+# raise "Solver Error"
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/swig/python/tests/repoinfo.py b/swig/python/tests/repoinfo.py
new file mode 100644
index 0000000..9934f09
--- /dev/null
+++ b/swig/python/tests/repoinfo.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+#
+# Author: Jan Blunck <jblunck@suse.de>
+#
+
+import unittest
+
+import os
+cwd = os.path.abspath(os.path.dirname(__file__))
+
+import sys
+sys.path.insert(0, cwd + "/../../../build/swig/python")
+
+from zypp import RepoInfo, Url, UrlSet, RepoType
+
+repo_urls = [ "file:/mounts/mirror/SuSE/ftp.opensuse.org/srv/ftp/pub/opensuse/debug/update/11.1/",
+ "http://download.opensuse.org/debug/update/11.1/" ]
+
+class RepoInfoTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.info = RepoInfo()
+ self.info.addBaseUrl(Url(repo_urls[0]))
+ self.info.addBaseUrl(Url(repo_urls[1]))
+ self.info.setAlias("default")
+ self.info.setName("default")
+ self.info.setEnabled(True)
+ self.info.setType(RepoType.RPMMD)
+ self.info.setGpgCheck(False)
+
+ def testUrlSetIsUrlSet(self):
+ urls = UrlSet()
+ assert urls.__class__.__name__ == "UrlSet", 'Incorrect class (' + urls.__class__.__name__ + ')'
+
+ def testUrlSetAppend(self):
+ urls = UrlSet()
+ urls.append(Url(repo_urls[0]))
+ urls.append(Url(repo_urls[1]))
+ assert urls.size() == 2, 'Incorrect size ' + urls.size()
+
+ def testBaseUrlsReturnsTuple(self):
+ baseurls = self.info.baseUrls()
+ assert baseurls.__class__.__name__ == "tuple", 'Incorrect class (' + baseurls.__class__.__name__ + ')'
+
+ def testBaseUrlsIteratable(self):
+ baseurls = self.info.baseUrls()
+ for url in baseurls:
+ assert url.__str__() in repo_urls, 'Incorrect URL ' + url.__str__()
+
+ def testSetBaseUrl(self):
+ baseurls = self.info.baseUrls()
+ assert len(baseurls) == 2
+ self.info.setBaseUrl(Url(repo_urls[0]))
+ baseurls = self.info.baseUrls()
+ assert len(baseurls) == 1
+
+ def testDump(self):
+ out = self.info.dump()
+ assert len(out) == 396, 'Invalid output length %d' % len(out)
+
+ def testDumpIni(self):
+ out = self.info.dumpAsIni()
+ assert len(out) == 208, 'Invalid output length %d' % len(out)
+
+ def testDumpXML(self):
+ out = self.info.dumpAsXML()
+ assert len(out) == 253, 'Invalid output length %d' % len(out)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/swig/python/tests/starting.py b/swig/python/tests/starting.py
new file mode 100644
index 0000000..91d4f4d
--- /dev/null
+++ b/swig/python/tests/starting.py
@@ -0,0 +1,19 @@
+import unittest
+
+import os
+cwd = os.path.abspath(os.path.dirname(__file__))
+
+import sys
+sys.path.insert(0, cwd + "/../../../build/swig/python")
+
+class TestSequenceFunctions(unittest.TestCase):
+
+ def teststarting(self):
+ import zypp
+ Z = zypp.ZYppFactory.instance().getZYpp()
+ assert Z
+ Z.initializeTarget( zypp.Pathname("/") )
+ Z.target().load();
+
+if __name__ == '__main__':
+ unittest.main()