p≡p for Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Regression test against API breakage
  4. # colors used to be represented as a simple int
  5. # NEW: colors are represented by colorvalue enum
  6. # Test for equal resolution of colors using int (OLD) vs using colorvalue (NEW)
  7. print("Running PYADPT-55")
  8. """
  9. >>> resolveOLDvsNEW(pEp.colorvalue.no_color)
  10. True
  11. >>> resolveOLDvsNEW(pEp.colorvalue.yellow)
  12. True
  13. >>> resolveOLDvsNEW(pEp.colorvalue.green)
  14. True
  15. >>> resolveOLDvsNEW(pEp.colorvalue.red)
  16. True
  17. """
  18. import pEp
  19. # resolves a color represented as int, the OLD way, as an int.
  20. # returns colorvalue
  21. def resolveColorOLD(col):
  22. ret = pEp.colorvalue()
  23. c = pEp.colorvalue(col)
  24. if(c == 0):
  25. ret = pEp.colorvalue.no_color
  26. if(c == 1):
  27. ret = pEp.colorvalue.yellow
  28. if(c == 2):
  29. ret = pEp.colorvalue.green
  30. if(c == -1):
  31. ret = pEp.colorvalue.red
  32. return ret
  33. # resolves a color represented as colorvalue, the NEW way
  34. # returns colorvalue
  35. def resolveColorNEW(col):
  36. c = pEp.colorvalue(col)
  37. return c
  38. # Compare color resolution OLD vs NEW way
  39. # return True if results are equal
  40. def resolveOLDvsNEW(col):
  41. return resolveColorOLD(col) == resolveColorNEW(col)
  42. if __name__ == "__main__":
  43. import doctest
  44. doctest.testmod()