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.
 
 
 
 

65 lines
1.5 KiB

  1. # Just some helpers for test functions
  2. import io
  3. import os
  4. import re
  5. import sys
  6. import time
  7. import shlex
  8. import shutil
  9. import nilmdb.server
  10. import nilmdb.utils
  11. import nilmdb.utils.timestamper
  12. from nilmdb.utils.printf import printf
  13. def myrepr(x):
  14. if isinstance(x, str):
  15. return '"' + x + '"'
  16. else:
  17. return repr(x)
  18. def eq_(a, b):
  19. if not a == b:
  20. raise AssertionError("%s != %s" % (myrepr(a), myrepr(b)))
  21. def lt_(a, b):
  22. if not a < b:
  23. raise AssertionError("%s is not less than %s" % (myrepr(a), myrepr(b)))
  24. def in_(a, b):
  25. if a not in b:
  26. raise AssertionError("%s not in %s" % (myrepr(a), myrepr(b)))
  27. def nin_(a, b):
  28. if a in b:
  29. raise AssertionError("unexpected %s in %s" % (myrepr(a), myrepr(b)))
  30. def in2_(a1, a2, b):
  31. if a1 not in b and a2 not in b:
  32. raise AssertionError("(%s or %s) not in %s" % (myrepr(a1), myrepr(a2),
  33. myrepr(b)))
  34. def ne_(a, b):
  35. if not a != b:
  36. raise AssertionError("unexpected %s == %s" % (myrepr(a), myrepr(b)))
  37. def lines_(a, n):
  38. l = a.count('\n')
  39. if not l == n:
  40. if len(a) > 5000:
  41. a = a[0:5000] + " ... truncated"
  42. raise AssertionError("wanted %d lines, got %d in output: '%s'"
  43. % (n, l, a))
  44. def recursive_unlink(path):
  45. try:
  46. shutil.rmtree(path)
  47. except OSError:
  48. pass
  49. try:
  50. os.unlink(path)
  51. except OSError:
  52. pass