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.
 
 
 

50 lines
1.2 KiB

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