From 9822ecf90a60f60e2e2f32271e1444e3a10b23d0 Mon Sep 17 00:00:00 2001 From: Anthony van Winkle Date: Wed, 21 Feb 2024 17:17:34 -0800 Subject: [PATCH] Add tests for optional auditor vars --- mpf/plugins/auditor.py | 5 +++-- mpf/tests/machine_files/auditor/config/config.yaml | 7 +++++++ .../machine_files/auditor/modes/base/config/base.yaml | 2 ++ mpf/tests/test_Auditor.py | 6 +++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mpf/plugins/auditor.py b/mpf/plugins/auditor.py index ba658eaa0..37b0edf72 100644 --- a/mpf/plugins/auditor.py +++ b/mpf/plugins/auditor.py @@ -232,8 +232,9 @@ def audit_player(self, **kwargs): for item in set(self.config['player']): for player in self.machine.game.player_list: - # Don't audit empty values, except score - if item != "score" and not self.machine.game.player[item]: + # Don't audit values that haven't been initialized on the player, either by + # a value set during gameplay or with an initial_value in the player_vars config + if not item in self.machine.game.player.vars: continue self.current_audits['player'][item]['top'] = ( diff --git a/mpf/tests/machine_files/auditor/config/config.yaml b/mpf/tests/machine_files/auditor/config/config.yaml index 203b5ec5c..ff3ac123b 100644 --- a/mpf/tests/machine_files/auditor/config/config.yaml +++ b/mpf/tests/machine_files/auditor/config/config.yaml @@ -3,12 +3,19 @@ game: balls_per_game: 1 +player_vars: + score: + initial_value: 0 + my_var: + initial_value: 0 + auditor: events: - test_event1 - test_event2 player: - my_var + - optional_var modes: - base diff --git a/mpf/tests/machine_files/auditor/modes/base/config/base.yaml b/mpf/tests/machine_files/auditor/modes/base/config/base.yaml index 379cfd0a2..541220a88 100644 --- a/mpf/tests/machine_files/auditor/modes/base/config/base.yaml +++ b/mpf/tests/machine_files/auditor/modes/base/config/base.yaml @@ -11,3 +11,5 @@ variable_player: not_audited: 100 add_score_odd: score: 123 + add_optional_var: + optional_var: 20 \ No newline at end of file diff --git a/mpf/tests/test_Auditor.py b/mpf/tests/test_Auditor.py index 52eb8ed2c..7b9987765 100644 --- a/mpf/tests/test_Auditor.py +++ b/mpf/tests/test_Auditor.py @@ -40,6 +40,7 @@ def test_auditor_player_vars(self): self.assertEqual(200, auditor.current_audits['player']['my_var']['average']) self.assertEqual([200], auditor.current_audits['player']['my_var']['top']) self.assertEqual(1, auditor.current_audits['player']['my_var']['total']) + self.assertEqual(0, auditor.current_audits['player']['optional_var']['total']) self.assertNotIn("not_audited", auditor.current_audits['player']) # start a game @@ -47,7 +48,9 @@ def test_auditor_player_vars(self): self.post_event("add_score") self.post_event("add_score") + self.post_event("add_optional_var") self.assertPlayerVarEqual(200, "score") + self.assertPlayerVarEqual(20, "optional_var") self.drain_all_balls() self.assertGameIsNotRunning() @@ -61,7 +64,8 @@ def test_auditor_player_vars(self): self.assertNotIn("not_audited", auditor.current_audits['player']) self.assertEqual({'score': {'top': [200, 100], 'average': 150.0, 'total': 2}, - 'my_var': {'top': [200, 0], 'average': 100.0, 'total': 2}}, + 'my_var': {'top': [200, 0], 'average': 100.0, 'total': 2}, + 'optional_var': {'top': [20], 'average': 20.0, 'total': 1}}, auditor.data_manager.written_data["player"]) # test rounding the average to an integer