core/tests/__init__.py

30 lines
871 B
Python
Raw Normal View History

"""Setup some common test helper things."""
import functools
2016-07-11 07:46:56 +00:00
import logging
2015-12-28 01:37:32 +00:00
from homeassistant import util
2016-02-03 05:33:59 +00:00
from homeassistant.util import location
2016-07-11 07:46:56 +00:00
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
2016-02-03 05:33:59 +00:00
def test_real(func):
"""Force a function to require a keyword _test_real to be passed in."""
@functools.wraps(func)
def guard_func(*args, **kwargs):
real = kwargs.pop('_test_real', None)
2016-02-05 06:26:02 +00:00
if not real:
raise Exception('Forgot to mock or pass "_test_real=True" to %s',
func.__name__)
return func(*args, **kwargs)
return guard_func
# Guard a few functions that would make network connections
location.detect_location_info = test_real(location.detect_location_info)
location.elevation = test_real(location.elevation)
util.get_local_ip = lambda: '127.0.0.1'