Browse Source

Add doctest_PYADPT-55.py: Test for equal resolution of colors using int (OLD) vs using PEP_color (NEW)

PYADPT-55
heck 5 years ago
parent
commit
b3b725fc2e
  1. 4
      src/message_api.cc
  2. 2
      src/message_api.hh
  3. 50
      test/doctest_PYADPT-55.py

4
src/message_api.cc

@ -62,9 +62,9 @@ namespace pEp {
return boost::python::make_tuple(dst, keylist, _rating, _flags); return boost::python::make_tuple(dst, keylist, _rating, _flags);
} }
int _color(int rating) PEP_color _color(int rating)
{ {
return (int) ::color_from_rating((PEP_rating) rating); return ::color_from_rating((PEP_rating) rating);
} }
boost::python::tuple sync_decode(object buffer) boost::python::tuple sync_decode(object buffer)

2
src/message_api.hh

@ -10,7 +10,7 @@ namespace pEp {
Message encrypt_message(Message src, boost::python::list extra = boost::python::list(), Message encrypt_message(Message src, boost::python::list extra = boost::python::list(),
int enc_format = 4, int flags = 0); int enc_format = 4, int flags = 0);
boost::python::tuple decrypt_message(Message src, int flags=0); boost::python::tuple decrypt_message(Message src, int flags=0);
int _color(int rating); PEP_color _color(int rating);
object sync_search(string name); object sync_search(string name);
object distribution_search(string name); object distribution_search(string name);
} }

50
test/doctest_PYADPT-55.py

@ -0,0 +1,50 @@
# Regression test against API breakage
# colors used to be represented as a simple int
# NEW: colors are represented by PEP_color enum
# Test for equal resolution of colors using int (OLD) vs using PEP_color (NEW)
"""
>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_no_color)
True
>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_yellow)
True
>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_green)
True
>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_red)
True
"""
import pEp
# resolves a color represented as int, the OLD way
# returns PEP_color
def resolveColorOLD(col):
ret = pEp.PEP_color()
c = pEp.PEP_color(col)
if(c == 0):
ret = pEp.PEP_color.PEP_color_no_color
if(c == 1):
ret = pEp.PEP_color.PEP_color_yellow
if(c == 2):
ret = pEp.PEP_color.PEP_color_green
if(c == -1):
ret = pEp.PEP_color.PEP_color_red
return ret
# resolves a color represented as PEP_color, the NEW way
# returns PEP_color
def resolveColorNEW(col):
c = pEp.PEP_color(col)
return col
# Compare color resolution OLD vs NEW way
# return True if results are equal
def resolveOLDvsNEW(col):
return resolveColorOLD(col) == resolveColorNEW(col)
if __name__ == "__main__":
import doctest
doctest.testmod()
Loading…
Cancel
Save