Blob Blame History Raw
From 257df5670310775a9c279f5f34e3d088966759b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Date: Mon, 7 Oct 2019 12:14:22 +0200
Subject: [PATCH 1/3] Update couple of tests

- list indices cannot by of type float
- remove unnecessary print
- update print with parenthesis which are now required in python
---
 libcomps/src/python/tests/__test.py           | 2 +-
 libcomps/src/python/tests/test_libcomps.py    | 1 -
 libcomps/src/python/tests/test_merge_comps.py | 4 ++--
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py
index c9b4dd4..c7529f3 100644
--- a/libcomps/src/python/tests/__test.py
+++ b/libcomps/src/python/tests/__test.py
@@ -225,7 +225,7 @@ def test_union3(self):
     def test_hash(self):
         s = set()
         for x in range(6):
-            s.add(self.obj_constructor(**self.obj_data[x/2]))
+            s.add(self.obj_constructor(**self.obj_data[int(x/2)]))
         self.assertTrue(len(s) == 3)
         self.assertTrue(hash(self.obj_constructor(**self.obj_data[0])) ==\
                         hash(self.obj_constructor(**self.obj_data[0])))
diff --git a/libcomps/src/python/tests/test_libcomps.py b/libcomps/src/python/tests/test_libcomps.py
index 2a18984..71311ef 100755
--- a/libcomps/src/python/tests/test_libcomps.py
+++ b/libcomps/src/python/tests/test_libcomps.py
@@ -19,7 +19,6 @@
 class TestLibcomps(unittest.TestCase):
 
     def setUp(self):
-        print (dir(libcomps))
         self.comps = libcomps.Comps()
         self.comps.fromxml_f("comps/comps-f21.xml")
         self.tmp_dir = tempfile.mkdtemp()
diff --git a/libcomps/src/python/tests/test_merge_comps.py b/libcomps/src/python/tests/test_merge_comps.py
index beef2cf..73e743f 100755
--- a/libcomps/src/python/tests/test_merge_comps.py
+++ b/libcomps/src/python/tests/test_merge_comps.py
@@ -7,10 +7,10 @@
 
 try:
     import _libpycomps as libcomps
-    print "local tests"
+    print("local tests")
 except ImportError:
     import libcomps
-    print "global tests"
+    print("global tests")
 
 
 class TestMergeComps(unittest.TestCase):

From 1b7add27595b12b9f47e54c3e5f1bda2177da346 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Date: Mon, 7 Oct 2019 12:50:21 +0200
Subject: [PATCH 2/3] Fix segfault when converting empty dict to string
 (RhBug:1757959)

Handle all elements in single loop consistently, instead of handling
last element separately which caused problems with empty dictionary.

https://bugzilla.redhat.com/show_bug.cgi?id=1757959
---
 libcomps/src/python/src/pycomps_dict.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/libcomps/src/python/src/pycomps_dict.c b/libcomps/src/python/src/pycomps_dict.c
index 1b42909..4a20cf7 100644
--- a/libcomps/src/python/src/pycomps_dict.c
+++ b/libcomps/src/python/src/pycomps_dict.c
@@ -78,7 +78,7 @@ PyObject* PyCOMPSDict_str(PyObject *self) {
     pairlist = comps_objdict_pairs(((PyCOMPS_Dict*)self)->dict);
     char *tmpstr;
 
-    for (it = pairlist->first; it != pairlist->last; it = it->next) {
+    for (it = pairlist->first; it != NULL; it = it->next) {
         tmp = ret;
         tmpkey = __pycomps_lang_decode(((COMPS_ObjRTreePair*)it->data)->key);
         if (!tmpkey) {
@@ -99,24 +99,6 @@ PyObject* PyCOMPSDict_str(PyObject *self) {
         Py_XDECREF(tmpkey);
         Py_XDECREF(tmpval);
     }
-    tmp = ret;
-    tmpkey = __pycomps_lang_decode(((COMPS_RTreePair*)it->data)->key);
-    if (!tmpkey) {
-        goto out;
-    }
-    tmpstr = comps_object_tostr(((COMPS_ObjRTreePair*)it->data)->data);
-    tmpval = __pycomps_lang_decode(tmpstr);
-    free(tmpstr);
-    if (!tmpval) {
-        //PyErr_SetString(PyExc_TypeError, "val convert error");
-        goto out;
-    }
-    tmp2 = PyUnicode_FromFormat("%U = '%U'", tmpkey, tmpval);
-    ret = PyUnicode_Concat(ret, tmp2);
-    Py_XDECREF(tmp);
-    Py_XDECREF(tmp2);
-    Py_XDECREF(tmpkey);
-    Py_XDECREF(tmpval);
     
     tmp = ret;
     tmp2 = PyUnicode_FromString("}");

From 6b4bffb541e70a1715e91ba06de8172b57cd26f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
Date: Mon, 7 Oct 2019 12:52:59 +0200
Subject: [PATCH 3/3] Add test for python API with empty *_by_lang dictionary
 input

---
 .../python/tests/comps/comps_empty_by_lang_tags.xml  | 12 ++++++++++++
 libcomps/src/python/tests/test_libcomps.py           | 10 ++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml

diff --git a/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml b/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml
new file mode 100644
index 0000000..2f40a86
--- /dev/null
+++ b/libcomps/src/python/tests/comps/comps_empty_by_lang_tags.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
+<comps>
+  <group>
+   <id>birds</id>
+   <description></description>
+  </group>
+  <category>
+   <id>all</id>
+   <name>all</name>
+  </category>
+</comps>
diff --git a/libcomps/src/python/tests/test_libcomps.py b/libcomps/src/python/tests/test_libcomps.py
index 71311ef..64c2b59 100755
--- a/libcomps/src/python/tests/test_libcomps.py
+++ b/libcomps/src/python/tests/test_libcomps.py
@@ -153,6 +153,16 @@ def test_duplicate_groups(self):
         #print self.comps.xml_str()
         self.comps.fromxml_str(self.comps.xml_str())
 
+    def test_empty_by_lang_tags(self):
+        self.comps = libcomps.Comps()
+        self.comps.fromxml_f("comps/comps_empty_by_lang_tags.xml")
+        for group in self.comps.groups:
+            self.assertEqual("{}", str(group.name_by_lang))
+            self.assertEqual("{}", str(group.desc_by_lang))
+
+        for category in self.comps.categories:
+            self.assertEqual("{}", str(category.name_by_lang))
+            self.assertEqual("{}", str(category.desc_by_lang))
 
 if __name__ == "__main__":
     unittest.main(testRunner = utest.MyRunner)