Browse Source

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

PYADPT-55
heck 2 years ago
parent
commit
b3b725fc2e
3 changed files with 53 additions and 3 deletions
  1. +2
    -2
      src/message_api.cc
  2. +1
    -1
      src/message_api.hh
  3. +50
    -0
      test/doctest_PYADPT-55.py

+ 2
- 2
src/message_api.cc View File

@ -62,9 +62,9 @@ namespace pEp {
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)


+ 1
- 1
src/message_api.hh View File

@ -10,7 +10,7 @@ namespace pEp {
Message encrypt_message(Message src, boost::python::list extra = boost::python::list(),
int enc_format = 4, 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 distribution_search(string name);
}


+ 50
- 0
test/doctest_PYADPT-55.py View File

@ -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