Base working for damage
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import os
|
||||
import re
|
||||
from collections import Counter
|
||||
|
||||
import pytest
|
||||
|
||||
from src.decode.pipeline import Pipeline
|
||||
|
||||
LOG_PATH = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'aoaddons.log')
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not os.path.exists(LOG_PATH),
|
||||
reason='aoaddons.log capture fixture is not available')
|
||||
|
||||
|
||||
def _raw_payloads():
|
||||
payloads = []
|
||||
pattern = re.compile(r'Raw payload: \[([0-9, ]+)\]')
|
||||
with open(LOG_PATH, encoding='utf-8', errors='replace') as log:
|
||||
for line in log:
|
||||
match = pattern.search(line)
|
||||
if match:
|
||||
payloads.append(
|
||||
bytes(int(part) for part in match.group(1).split(',')))
|
||||
return payloads
|
||||
|
||||
|
||||
def test_offline_capture_produces_expected_events():
|
||||
payloads = _raw_payloads()
|
||||
assert payloads, 'no raw payloads found in aoaddons.log'
|
||||
|
||||
events = []
|
||||
pipeline = Pipeline(events.append)
|
||||
for payload in payloads:
|
||||
pipeline.on_udp(payload)
|
||||
|
||||
counts = Counter(event['name'] for event in events)
|
||||
assert counts['MainPlayerAppeared'] >= 1
|
||||
assert counts['PlayerAppeared'] == 2
|
||||
assert counts['ZoneChange'] == 3
|
||||
assert counts['UpdateItems'] >= 4
|
||||
|
||||
|
||||
def test_offline_capture_main_player_stream_is_consistent():
|
||||
events = []
|
||||
pipeline = Pipeline(events.append)
|
||||
for payload in _raw_payloads():
|
||||
pipeline.on_udp(payload)
|
||||
|
||||
assert any(e['name'] == 'ZoneChange' for e in events)
|
||||
main = next(e for e in events if e['name'] == 'MainPlayerAppeared')
|
||||
assert main['value']['name']
|
||||
|
||||
appeared = [e['value']['id'] for e in events
|
||||
if e['name'] == 'PlayerAppeared']
|
||||
assert appeared == [0, 1]
|
||||
Reference in New Issue
Block a user