Beispiel #1
0
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()
Beispiel #2
0
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)
Beispiel #3
0
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.'
Beispiel #4
0
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.'
Beispiel #5
0
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()
Beispiel #6
0
def test_is_thread():
    proxy = mock_data.create_sample_proxy()
    t = ProxyThread(proxy=proxy)
    assert isinstance(t, Thread), 'ProxyThread is\'nt a thread'
Beispiel #7
0
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.'
Beispiel #8
0
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.'