2016-06-27 09:02:45 -07:00
|
|
|
"""Setup some common test helper things."""
|
|
|
|
import functools
|
2016-07-11 00:46:56 -07:00
|
|
|
import logging
|
2015-12-27 17:37:32 -08:00
|
|
|
|
2016-02-14 22:01:30 -08:00
|
|
|
from homeassistant import util
|
2016-02-02 21:33:59 -08:00
|
|
|
from homeassistant.util import location
|
|
|
|
|
2016-07-11 00:46:56 -07:00
|
|
|
logging.basicConfig()
|
|
|
|
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
|
|
|
|
|
2016-02-02 21:33:59 -08:00
|
|
|
|
2016-06-27 09:02:45 -07: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-04 22:26:02 -08:00
|
|
|
|
2016-06-27 09:02:45 -07: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)
|
2016-02-14 22:01:30 -08:00
|
|
|
util.get_local_ip = lambda: '127.0.0.1'
|