def test_ProxyThread_calls_sleep(mock_update_proxy, mock_sleep): proxy = mock_data.create_sample_proxy() proxy.update({'refresh_time': 0.01}) t = ProxyThread(proxy=proxy) t.start() t.terminate() mock_sleep.assert_called()
def test_updates_proxy_arg(mock_update_proxy): proxy = mock_data.create_sample_proxy() t = ProxyThread(proxy=proxy) proxy.update({'refresh_time': 0.01}) t.start() t.terminate() mock_update_proxy.assert_called_with(proxy)
def test_kills_thread_at_terminate(mock_update_proxy): proxy = mock_data.create_sample_proxy() proxy.update({'refresh_time': 0.01}) t = ProxyThread(proxy=proxy) t.start() t.terminate() time.sleep(0.1) assert not t.is_alive(), 'thread is alive.'
def test_sets_terminated_at_terminate(mock_update_proxy): proxy = mock_data.create_sample_proxy() proxy.update({'refresh_time': 0.01}) t = ProxyThread(proxy=proxy) t.start() t.terminate() assert t.terminated.is_set( ), 'terminated not set after terminate be called.'
def test_not_set_terminated_at_start(mock_update_proxy): proxy = mock_data.create_sample_proxy() proxy.update({'refresh_time': 0.01}) t = ProxyThread(proxy=proxy) t.start() assert isinstance(t.terminated, Event), 'terminated attr isn\'t an event.' assert not t.terminated.is_set(), 'terminated event not clear by default.' t.terminate()
def test_is_thread(): proxy = mock_data.create_sample_proxy() t = ProxyThread(proxy=proxy) assert isinstance(t, Thread), 'ProxyThread is\'nt a thread'
def test_not_set_terminated_as_default(mock_update_proxy): proxy = mock_data.create_sample_proxy() t = ProxyThread(proxy=proxy) assert isinstance(t.terminated, Event), 'terminated attr isn\'t an event.' assert not t.terminated.is_set(), 'terminated event not clear by default.'
def test_has_terminate(mock_update_proxy): proxy = mock_data.create_sample_proxy() t = ProxyThread(proxy=proxy) getattr(t, 'terminate'), 'ProxyThread doesn\'t have interrupt method.'