1from functools import wraps 2import re 3import time 4 5import pytest 6 7from dogpile.util import compat 8from dogpile.util.compat import configparser # noqa 9from dogpile.util.compat import io # noqa 10 11 12def eq_(a, b, msg=None): 13 """Assert a == b, with repr messaging on failure.""" 14 assert a == b, msg or "%r != %r" % (a, b) 15 16 17def is_(a, b, msg=None): 18 """Assert a is b, with repr messaging on failure.""" 19 assert a is b, msg or "%r is not %r" % (a, b) 20 21 22def ne_(a, b, msg=None): 23 """Assert a != b, with repr messaging on failure.""" 24 assert a != b, msg or "%r == %r" % (a, b) 25 26 27def assert_raises_message(except_cls, msg, callable_, *args, **kwargs): 28 try: 29 callable_(*args, **kwargs) 30 assert False, "Callable did not raise an exception" 31 except except_cls as e: 32 assert re.search(msg, str(e)), "%r !~ %s" % (msg, e) 33 34 35def winsleep(): 36 # sleep a for an amount of time 37 # sufficient for windows time.time() 38 # to change 39 if compat.win32: 40 time.sleep(0.001) 41 42 43def requires_py3k(fn): 44 @wraps(fn) 45 def wrap(*arg, **kw): 46 if compat.py2k: 47 pytest.skip("Python 3 required") 48 return fn(*arg, **kw) 49 50 return wrap 51