Add rpmver-py inequality operator
The inequality operator of the python ver objects would always return True if the compared objects were not the actual same python object. That was leading to situations as (v := rpm.ver('1.0')) != v # False rpm.ver('1.0') != rpm.ver('1.0') # True This commit aims to support the inequality operator among different python objects that hold the same version the (opposite) way we expect the equality operator to work. To do so, it adds the PY_NE case to the tp_richcompare slot function and adds extra checks to a related rpmpython test case. Signed-off-by: Beñat Gartzia <bgartzia@redhat.com>
This commit is contained in:
parent
d80bf405fc
commit
f1b68c9e76
|
@ -80,6 +80,9 @@ static PyObject *ver_richcmp(rpmverObject *s, rpmverObject *o, int op)
|
||||||
case Py_EQ:
|
case Py_EQ:
|
||||||
v = rpmverCmp(s->ver, o->ver) == 0;
|
v = rpmverCmp(s->ver, o->ver) == 0;
|
||||||
break;
|
break;
|
||||||
|
case Py_NE:
|
||||||
|
v = rpmverCmp(s->ver, o->ver) != 0;
|
||||||
|
break;
|
||||||
case Py_GE:
|
case Py_GE:
|
||||||
v = rpmverCmp(s->ver, o->ver) >= 0;
|
v = rpmverCmp(s->ver, o->ver) >= 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -705,11 +705,13 @@ RPMPY_TEST([version objects 1],[
|
||||||
pv = None
|
pv = None
|
||||||
for vs in [ '1.0', '1.0', '4:1.0', '1.5-1', '3:2.0-1']:
|
for vs in [ '1.0', '1.0', '4:1.0', '1.5-1', '3:2.0-1']:
|
||||||
v = rpm.ver(vs)
|
v = rpm.ver(vs)
|
||||||
|
v_eq = rpm.ver(vs)
|
||||||
myprint('(%s, %s, %s)' % (v.e, v.v, v.r))
|
myprint('(%s, %s, %s)' % (v.e, v.v, v.r))
|
||||||
if pv:
|
if pv:
|
||||||
myprint('%s < %s: %s' % (pv.evr, v.evr, pv < v))
|
myprint('%s < %s: %s' % (pv.evr, v.evr, pv < v))
|
||||||
myprint('%s > %s: %s' % (pv.evr, v.evr, pv > v))
|
myprint('%s > %s: %s' % (pv.evr, v.evr, pv > v))
|
||||||
myprint('%s == %s: %s' % (pv.evr, v.evr, pv == v))
|
myprint('%s == %s: %s' % (pv.evr, v.evr, pv == v))
|
||||||
|
myprint('%s != %s: %s' % (v.evr, v_eq.evr, v != v_eq))
|
||||||
pv = v
|
pv = v
|
||||||
],
|
],
|
||||||
[(None, 1.0, None)
|
[(None, 1.0, None)
|
||||||
|
@ -717,18 +719,22 @@ for vs in [ '1.0', '1.0', '4:1.0', '1.5-1', '3:2.0-1']:
|
||||||
1.0 < 1.0: False
|
1.0 < 1.0: False
|
||||||
1.0 > 1.0: False
|
1.0 > 1.0: False
|
||||||
1.0 == 1.0: True
|
1.0 == 1.0: True
|
||||||
|
1.0 != 1.0: False
|
||||||
(4, 1.0, None)
|
(4, 1.0, None)
|
||||||
1.0 < 4:1.0: True
|
1.0 < 4:1.0: True
|
||||||
1.0 > 4:1.0: False
|
1.0 > 4:1.0: False
|
||||||
1.0 == 4:1.0: False
|
1.0 == 4:1.0: False
|
||||||
|
4:1.0 != 4:1.0: False
|
||||||
(None, 1.5, 1)
|
(None, 1.5, 1)
|
||||||
4:1.0 < 1.5-1: False
|
4:1.0 < 1.5-1: False
|
||||||
4:1.0 > 1.5-1: True
|
4:1.0 > 1.5-1: True
|
||||||
4:1.0 == 1.5-1: False
|
4:1.0 == 1.5-1: False
|
||||||
|
1.5-1 != 1.5-1: False
|
||||||
(3, 2.0, 1)
|
(3, 2.0, 1)
|
||||||
1.5-1 < 3:2.0-1: True
|
1.5-1 < 3:2.0-1: True
|
||||||
1.5-1 > 3:2.0-1: False
|
1.5-1 > 3:2.0-1: False
|
||||||
1.5-1 == 3:2.0-1: False
|
1.5-1 == 3:2.0-1: False
|
||||||
|
3:2.0-1 != 3:2.0-1: False
|
||||||
],
|
],
|
||||||
[])
|
[])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue