Base working for damage
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import pytest
|
||||
|
||||
from src import backend_proxy
|
||||
from src import engine
|
||||
|
||||
|
||||
def test_native_backend_available_on_linux():
|
||||
import src.utils.platform_utils as pu
|
||||
|
||||
assert backend_proxy.NATIVE_BACKEND_AVAILABLE == pu.is_linux()
|
||||
|
||||
|
||||
def test_initialize_ok_with_native_backend(monkeypatch):
|
||||
monkeypatch.setattr(backend_proxy, 'NATIVE_BACKEND_AVAILABLE', True)
|
||||
|
||||
assert backend_proxy.initialize() == backend_proxy.InitializationResult.Ok
|
||||
|
||||
|
||||
def test_initialize_without_backend_returns_not_installed(monkeypatch):
|
||||
if backend_proxy.BACKEND_AVAILABLE:
|
||||
pytest.skip('pyaoaddons is installed')
|
||||
|
||||
monkeypatch.setattr(backend_proxy, 'NATIVE_BACKEND_AVAILABLE', False)
|
||||
|
||||
assert backend_proxy.initialize() == \
|
||||
backend_proxy.InitializationResult.BackendNotInstalled
|
||||
|
||||
|
||||
def test_subscribe_starts_native_backend(monkeypatch):
|
||||
started = []
|
||||
monkeypatch.setattr(backend_proxy, 'NATIVE_BACKEND_AVAILABLE', True)
|
||||
monkeypatch.setattr(
|
||||
backend_proxy, '_start_native_backend',
|
||||
lambda callback: started.append(callback) or True)
|
||||
|
||||
callback = lambda event: event
|
||||
result = backend_proxy.subscribe(callback)
|
||||
|
||||
assert started == [callback]
|
||||
assert result is True
|
||||
|
||||
|
||||
def test_subscribe_is_noop_without_backend(monkeypatch):
|
||||
if backend_proxy.BACKEND_AVAILABLE:
|
||||
pytest.skip('pyaoaddons is installed')
|
||||
|
||||
monkeypatch.setattr(backend_proxy, 'NATIVE_BACKEND_AVAILABLE', False)
|
||||
|
||||
assert backend_proxy.subscribe(lambda event: event) is False
|
||||
|
||||
|
||||
def test_start_native_backend_uses_pipeline(monkeypatch):
|
||||
import src.net.capture as capture_mod
|
||||
|
||||
monkeypatch.setattr(backend_proxy, '_capture', None)
|
||||
|
||||
created = {}
|
||||
|
||||
class FakeCapture:
|
||||
def __init__(self, on_udp):
|
||||
created['on_udp'] = on_udp
|
||||
|
||||
def start(self):
|
||||
created['started'] = True
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(capture_mod, 'CaptureEngine', FakeCapture)
|
||||
|
||||
events = []
|
||||
assert backend_proxy._start_native_backend(events.append) is True
|
||||
|
||||
assert created['started'] is True
|
||||
assert callable(created['on_udp'])
|
||||
assert backend_proxy._capture is not None
|
||||
backend_proxy._capture = None
|
||||
|
||||
|
||||
def test_start_native_backend_reports_start_failure(monkeypatch):
|
||||
import src.net.capture as capture_mod
|
||||
|
||||
monkeypatch.setattr(backend_proxy, '_capture', None)
|
||||
|
||||
class FakeCapture:
|
||||
def __init__(self, on_udp):
|
||||
self.on_udp = on_udp
|
||||
|
||||
def start(self):
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(capture_mod, 'CaptureEngine', FakeCapture)
|
||||
|
||||
assert backend_proxy._start_native_backend(lambda event: event) is False
|
||||
assert backend_proxy._capture is None
|
||||
|
||||
|
||||
def test_engine_initialize_reports_subscribe_failure(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
engine.backend_proxy, 'initialize',
|
||||
lambda: backend_proxy.InitializationResult.Ok)
|
||||
monkeypatch.setattr(
|
||||
engine.backend_proxy, 'subscribe',
|
||||
lambda callback: False)
|
||||
|
||||
assert engine.initialize() == backend_proxy.InitializationResult.UnknownFailure
|
||||
Reference in New Issue
Block a user