""" Common setup and patching for tests """

from datetime import datetime as orig_datetime, timedelta
from mock import patch
import threading
#pylint: disable=W0401,W0614
from test.fixtures import *

_thread_state = threading.local()

def _new_utcnow():
    """ Return last set datetime, or set it to current datetime if not set """
    if not hasattr(_thread_state, 'utcnow'):
        _thread_state.utcnow = orig_datetime.utcnow()
    return _thread_state.utcnow

def _new_now():
    """ Work out current local datetime """
    return _new_utcnow() + (orig_datetime.now() - orig_datetime.utcnow())

def clock_load(utcnow):
    """ Set datetie """
    _thread_state.utcnow = utcnow
    return _thread_state.utcnow

def clock_tick(delta=timedelta()):
    """ Tick clock """
    return clock_load(_new_utcnow() + delta)

def clock_reset():
    """ Forget set datetime """
    if hasattr(_thread_state, 'utcnow'):
        delattr(_thread_state, 'utcnow')

#pylint: disable=W0142
_config = {'utcnow.side_effect': _new_utcnow,
           'now.side_effect': _new_now}
_patcher = patch('datetime.datetime', **_config)
_mocker = _patcher.start()

""" Common setup and patching for tests """

from datetime import datetime as orig_datetime, timedelta
from mock import patch
import threading
#pylint: disable=W0401,W0614
from test.fixtures import *

_thread_state = threading.local()

def _new_utcnow():
    """ Return last set datetime, or set it to current datetime if not set """
    if not hasattr(_thread_state, 'utcnow'):
        _thread_state.utcnow = orig_datetime.utcnow()
    return _thread_state.utcnow

def _new_now():
    """ Work out current local datetime """
    return _new_utcnow() + (orig_datetime.now() - orig_datetime.utcnow())

def clock_load(utcnow):
    """ Set datetie """
    _thread_state.utcnow = utcnow
    return _thread_state.utcnow

def clock_tick(delta=timedelta()):
    """ Tick clock """
    return clock_load(_new_utcnow() + delta)

def clock_reset():
    """ Forget set datetime """
    if hasattr(_thread_state, 'utcnow'):
        delattr(_thread_state, 'utcnow')

_config = {'utcnow.side_effect': _new_utcnow,
           'now.side_effect': _new_now}
_patcher = patch('datetime.datetime', **_config)
_mocker = _patcher.start()

Fix lint