From 3409909b056bb4443de1aed26771508ed7b91116 Mon Sep 17 00:00:00 2001 From: Brandon Wallace Date: Thu, 19 Mar 2026 00:53:29 -0500 Subject: [PATCH] test: add failing tests for NaN/undefined variable integer comparison bug Add 5 tests covering the ValueError crash in __eval_basiccondition() when int() is called on empty/non-numeric variable values during integer comparisons. Tests verify expected behavior for warn mode (comparison evaluates to false) and stop mode (proper PPPInterrupt). --- tests/tests.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tests/tests.py b/tests/tests.py index 7489c0d..c037fef 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1328,6 +1328,82 @@ class TestPromptPostProcessor(TestPromptPostProcessorBase): ppp=self.nocupppp, ) + # NaN/undefined variable integer comparison tests + + def test_cmd_if_undefined_var_int_compare_warn(self): # undefined var integer compare with on_warning=warn + self.process( + PromptPair( + "YESNO", + "", + ), + PromptPair("NO", ""), + ppp=PromptPostProcessor( + self.ppp_logger, + self.interrupt, + self.def_env_info, + {**self.defopts, "on_warning": PromptPostProcessor.ONWARNING_CHOICES.warn.value}, + self.grammar_content, + self.wildcards_obj, + self.extranetwork_maps_obj, + ), + ) + + def test_cmd_if_undefined_var_int_compare_stop(self): # undefined var integer compare with on_warning=stop + self.process( + PromptPair( + "YESNO", + "", + ), + PromptPair("", ""), + interrupted=True, + ) + + def test_cmd_if_nonnumeric_var_int_compare_warn(self): # non-numeric var integer compare with on_warning=warn + self.process( + PromptPair( + "abcYESNO", + "", + ), + PromptPair("NO", ""), + ppp=PromptPostProcessor( + self.ppp_logger, + self.interrupt, + self.def_env_info, + {**self.defopts, "on_warning": PromptPostProcessor.ONWARNING_CHOICES.warn.value}, + self.grammar_content, + self.wildcards_obj, + self.extranetwork_maps_obj, + ), + ) + + def test_cmd_if_nonnumeric_var_int_compare_stop(self): # non-numeric var integer compare with on_warning=stop + self.process( + PromptPair( + "abcYESNO", + "", + ), + PromptPair("", ""), + interrupted=True, + ) + + def test_cmd_if_empty_var_int_compare(self): # empty string var integer compare with on_warning=warn + self.process( + PromptPair( + "YESNO", + "", + ), + PromptPair("NO", ""), + ppp=PromptPostProcessor( + self.ppp_logger, + self.interrupt, + self.def_env_info, + {**self.defopts, "on_warning": PromptPostProcessor.ONWARNING_CHOICES.warn.value}, + self.grammar_content, + self.wildcards_obj, + self.extranetwork_maps_obj, + ), + ) + if __name__ == "__main__": unittest.main()