Fix RepoInfo::baseUrls() etc.
authorKlaus Kämpf <kkaempf@suse.de>
Thu, 12 Mar 2009 14:07:16 +0000 (15:07 +0100)
committerKlaus Kämpf <kkaempf@suse.de>
Thu, 12 Mar 2009 14:07:16 +0000 (15:07 +0100)
Add a testcase for RepoInfo and fix the problems with UrlSet.

swig/RepoInfo.i
swig/python/tests/CMakeLists.txt
swig/python/tests/repoinfo.py [new file with mode: 0644]
swig/zypp.i

index 6ca7ccf..f86a254 100644 (file)
@@ -1,6 +1,6 @@
 #ifdef SWIGPERL5
 #else
-    %template(UrlSet) std::set<Url>;
+%template(UrlSet) std::set<zypp::Url>;
 #endif
 
 namespace zypp
@@ -12,13 +12,45 @@ namespace zypp
     %ignore operator<<;
     %ignore operator<;
   }
+  typedef std::list<Url> UrlSet;
 }
-%include <zypp/repo/RepoInfoBase.h>
 
+%ignore zypp::repo::RepoInfoBase::dumpOn(std::ostream &) const;
+%ignore zypp::repo::RepoInfoBase::dumpAsIniOn(std::ostream &) const;
+%ignore zypp::repo::RepoInfoBase::dumpAsXMLOn(std::ostream &) const;
+%include <zypp/repo/RepoInfoBase.h>
 
 // This is due to a typo in libzypp < 5.4.0
 %ignore zypp::RepoInfo::defaultPrioity();
 
+%ignore zypp::RepoInfo::dumpOn(std::ostream &) const;
+%ignore zypp::RepoInfo::dumpAsIniOn(std::ostream &) const;
+%ignore zypp::RepoInfo::dumpAsXMLOn(std::ostream &) const;
+
 %include <zypp/RepoInfo.h>
 typedef std::list<zypp::RepoInfo> RepoInfoList;
 %template(RepoInfoList) std::list<zypp::RepoInfo>;
+
+%extend zypp::RepoInfo 
+{
+       std::string dump(void) const
+       {
+               std::ostringstream str;
+               self->dumpOn(str);
+               return str.str();
+       }
+
+       std::string dumpAsIni(void) const
+       {
+               std::ostringstream str;
+               self->dumpAsIniOn(str);
+               return str.str();
+       }
+
+       std::string dumpAsXML(void) const
+       {
+               std::ostringstream str;
+               self->dumpAsXMLOn(str);
+               return str.str();
+       }
+}
index 216dd21..70eb6df 100644 (file)
@@ -5,3 +5,4 @@
 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)
diff --git a/swig/python/tests/repoinfo.py b/swig/python/tests/repoinfo.py
new file mode 100644 (file)
index 0000000..e134709
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+#
+# Author: Jan Blunck <jblunck@suse.de>
+#
+
+import unittest
+from zypp import RepoInfo, Url, UrlSet, RepoType
+import sys
+
+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) == 414, '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()
index 896119c..cabcde8 100644 (file)
@@ -49,7 +49,6 @@ using namespace zypp::repo;
 using namespace zypp::resfilter;
 using namespace zypp::filesystem;
 
-typedef std::set<Url> UrlSet;
 typedef std::list<std::string> StringList;
 %}