Working on party stuff, mostly works
This commit is contained in:
@@ -3,11 +3,13 @@ import struct
|
||||
import pytest
|
||||
|
||||
from src.decode import photon
|
||||
from src.decode import party_memory
|
||||
from src.decode import translate
|
||||
from src.decode.photon import PhotonDecoder, decode_message18
|
||||
from src.decode.translate import into_game_message
|
||||
from src.decode.world import IdCache, World
|
||||
from src.net.capture import _extract_udp_payload
|
||||
from src.utils import platform_utils
|
||||
|
||||
|
||||
# --- Protocol18 value builders -------------------------------------------------
|
||||
@@ -194,6 +196,27 @@ def test_unknown_opcode_ignored():
|
||||
assert into_game_message(message) is None
|
||||
|
||||
|
||||
def test_party_roster_without_opcode_translates():
|
||||
message = photon.PhotonMessage('Event', 1, {
|
||||
0: 123,
|
||||
9: ['bionicKatana', 'Sweetpea23042'],
|
||||
}, None, None)
|
||||
|
||||
game = into_game_message(message)
|
||||
|
||||
assert game is not None
|
||||
assert game.name == 'PartyRoster'
|
||||
assert translate.msg_party_roster_names(game) == [
|
||||
'bionicKatana', 'Sweetpea23042']
|
||||
|
||||
|
||||
def test_unlock_response_string_lists_are_not_party_rosters():
|
||||
message = photon.PhotonMessage('Response', 1, {
|
||||
9: ['UNLOCKED_CLAIMABLE', 'UNLOCKED_CLAIMABLE'],
|
||||
}, None, None)
|
||||
assert into_game_message(message) is None
|
||||
|
||||
|
||||
# --- world ----------------------------------------------------------------------
|
||||
|
||||
def game(name, params=None):
|
||||
@@ -375,6 +398,71 @@ def test_party_events_from_structures():
|
||||
assert left[0]['value']['player_names'] == ['Alice']
|
||||
|
||||
|
||||
def test_party_roster_event_updates_party():
|
||||
world = World()
|
||||
events = world.transform(game('PartyRoster', {
|
||||
9: ['bionicKatana', 'Sweetpea23042'],
|
||||
}))
|
||||
|
||||
assert events == [{
|
||||
'name': 'UpdateParty',
|
||||
'value': {'player_names': ['bionicKatana', 'Sweetpea23042']},
|
||||
}]
|
||||
|
||||
|
||||
def test_remembered_party_reemits_on_join(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(platform_utils, 'config_dir', lambda: str(tmp_path))
|
||||
party_memory.save_last_party([
|
||||
'bionicKatana', 'fatbrick', 'Froedrick712', 'rainbowShade'])
|
||||
|
||||
world = World(remember_last_party=True)
|
||||
events = world.transform(game('Join', {0: 98, 2: 'bionicKatana'}))
|
||||
|
||||
assert events[-1] == {
|
||||
'name': 'UpdateParty',
|
||||
'value': {'player_names': [
|
||||
'bionicKatana', 'fatbrick', 'Froedrick712', 'rainbowShade']},
|
||||
}
|
||||
|
||||
|
||||
def test_party_inference_grows_during_zone_load(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(platform_utils, 'config_dir', lambda: str(tmp_path))
|
||||
world = World(remember_last_party=True)
|
||||
|
||||
world.transform(game('NewCharacter', {0: 97, 1: 'rainbowShade'}))
|
||||
join = world.transform(game('Join', {0: 98, 2: 'bionicKatana'}))
|
||||
fatbrick = world.transform(game('NewCharacter', {0: 161, 1: 'fatbrick'}))
|
||||
froedrick = world.transform(game('NewCharacter', {0: 211, 1: 'Froedrick712'}))
|
||||
|
||||
assert _last_party_names(join) == [
|
||||
'rainbowShade', 'bionicKatana']
|
||||
assert _last_party_names(fatbrick) == [
|
||||
'rainbowShade', 'bionicKatana', 'fatbrick']
|
||||
assert _last_party_names(froedrick) == [
|
||||
'rainbowShade', 'bionicKatana', 'fatbrick', 'Froedrick712']
|
||||
assert party_memory.load_last_party() == [
|
||||
'rainbowShade', 'bionicKatana', 'fatbrick', 'Froedrick712']
|
||||
|
||||
|
||||
def test_party_disband_clears_remembered_party(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(platform_utils, 'config_dir', lambda: str(tmp_path))
|
||||
world = World(remember_last_party=True)
|
||||
|
||||
world.transform(game('PartyRoster', {
|
||||
9: ['bionicKatana', 'fatbrick'],
|
||||
}))
|
||||
assert party_memory.load_last_party() == ['bionicKatana', 'fatbrick']
|
||||
|
||||
world.transform(game('PartyDisbanded'))
|
||||
|
||||
assert party_memory.load_last_party() == []
|
||||
|
||||
|
||||
def _last_party_names(events):
|
||||
party_events = [e for e in events if e['name'] == 'UpdateParty']
|
||||
return party_events[-1]['value']['player_names']
|
||||
|
||||
|
||||
def test_party_main_player_left_disbands():
|
||||
world = World()
|
||||
world.party.set_main_player_name('Alice')
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
import src.environment as environment
|
||||
|
||||
|
||||
def test_remember_last_party_flag_is_removed_from_qt_args(monkeypatch):
|
||||
monkeypatch.setattr(sys, 'argv', ['aostats', '--remember-last-party'])
|
||||
reloaded = importlib.reload(environment)
|
||||
|
||||
assert reloaded.remember_last_party() is True
|
||||
assert reloaded.qt_args(['aostats', '--remember-last-party', '--verbose']) == [
|
||||
'aostats']
|
||||
|
||||
sys.argv = ['aostats']
|
||||
importlib.reload(environment)
|
||||
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
from src.decode import party_memory
|
||||
from src.utils import platform_utils
|
||||
|
||||
|
||||
def test_party_memory_save_load_and_clear(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(platform_utils, 'config_dir', lambda: str(tmp_path))
|
||||
|
||||
party_memory.save_last_party([
|
||||
'bionicKatana', 'fatbrick', 'fatbrick', '', None])
|
||||
|
||||
assert party_memory.load_last_party() == ['bionicKatana', 'fatbrick']
|
||||
assert os.path.isfile(tmp_path / 'last-party.json')
|
||||
|
||||
party_memory.clear_last_party()
|
||||
|
||||
assert party_memory.load_last_party() == []
|
||||
assert not os.path.exists(tmp_path / 'last-party.json')
|
||||
|
||||
|
||||
def test_party_memory_ignores_corrupt_file(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(platform_utils, 'config_dir', lambda: str(tmp_path))
|
||||
path = tmp_path / 'last-party.json'
|
||||
path.write_text('{not json')
|
||||
|
||||
assert party_memory.load_last_party() == []
|
||||
@@ -0,0 +1,32 @@
|
||||
from src.stats import visibility as visibility_module
|
||||
from src.stats.visibility import Visibility
|
||||
|
||||
|
||||
def test_visibility_uses_exact_names(monkeypatch):
|
||||
monkeypatch.delenv('TESTING', raising=False)
|
||||
monkeypatch.setattr(visibility_module, 'config', lambda: {'app': {}})
|
||||
visibility_module._is_visible_by_config.cache_clear()
|
||||
|
||||
visibility = Visibility()
|
||||
visibility.on_player_appeared('bionicKatana')
|
||||
visibility.on_visible_players_changed(['Sweetpea23042'])
|
||||
|
||||
assert visibility.test('bionicKatana')
|
||||
assert visibility.test('Sweetpea23042')
|
||||
assert not visibility.test('Sweetpea')
|
||||
assert not visibility.test('bionicKatanaExtra')
|
||||
|
||||
|
||||
def test_visibility_treats_regex_characters_as_plain_names(monkeypatch):
|
||||
monkeypatch.delenv('TESTING', raising=False)
|
||||
monkeypatch.setattr(visibility_module, 'config', lambda: {'app': {}})
|
||||
visibility_module._is_visible_by_config.cache_clear()
|
||||
|
||||
visibility = Visibility()
|
||||
visibility.on_player_appeared('main.player')
|
||||
visibility.on_visible_players_changed(['Arcane+Fire'])
|
||||
|
||||
assert visibility.test('main.player')
|
||||
assert visibility.test('Arcane+Fire')
|
||||
assert not visibility.test('mainXplayer')
|
||||
assert not visibility.test('ArcaneeeFire')
|
||||
Reference in New Issue
Block a user