From d0d14b87e155ee6a4e2fef3bdb04cb5548b22bc4 Mon Sep 17 00:00:00 2001 From: Dor-bl <59066376+Dor-bl@users.noreply.github.com> Date: Mon, 19 Oct 2026 04:41:24 +0000 Subject: [PATCH 1/4] test: add unit tests for format_stacktrace Add unit tests for `format_stacktrace` in `test/unit/webdriver/errorhandler_test.py` covering empty inputs, string stack traces, sequence of frame dicts with optional keys, non-dict elements, and non-iterable inputs. --- test/unit/webdriver/errorhandler_test.py | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/unit/webdriver/errorhandler_test.py diff --git a/test/unit/webdriver/errorhandler_test.py b/test/unit/webdriver/errorhandler_test.py new file mode 100644 index 00000000..f5220156 --- /dev/null +++ b/test/unit/webdriver/errorhandler_test.py @@ -0,0 +1,67 @@ +import pytest + +from appium.webdriver.errorhandler import format_stacktrace + + +class TestFormatStacktrace: + @pytest.mark.parametrize( + ('input_data', 'expected'), + [ + (None, []), + ('', []), + ([], []), + ({}, []), + ], + ) + def test_format_stacktrace_empty(self, input_data: None | str | list | dict, expected: list[str]) -> None: + assert format_stacktrace(input_data) == expected + + def test_format_stacktrace_string(self) -> None: + stack = 'Error: Something went wrong\n at foo (file.js:10)\n at bar (file.js:20)' + expected = [ + 'Error: Something went wrong', + ' at foo (file.js:10)', + ' at bar (file.js:20)', + ] + assert format_stacktrace(stack) == expected + + def test_format_stacktrace_sequence_dicts(self) -> None: + frames = [ + { + 'lineNumber': 42, + 'fileName': 'index.js', + 'methodName': 'handleClick', + 'className': 'MyComponent', + }, + { + 'fileName': 'utils.js', + 'methodName': 'helper', + }, + {}, + ] + expected = [ + ' at MyComponent.handleClick (index.js:42)', + ' at helper (utils.js)', + ' at ()', + ] + assert format_stacktrace(frames) == expected + + def test_format_stacktrace_sequence_with_non_dict_elements(self) -> None: + frames = [ + 'not a dict', + 123, + None, + { + 'lineNumber': 5, + 'fileName': 'main.py', + 'methodName': 'run', + }, + ] + expected = [ + ' at run (main.py:5)', + ] + assert format_stacktrace(frames) == expected + + def test_format_stacktrace_non_iterable_type_error(self) -> None: + assert format_stacktrace(123) == [] + assert format_stacktrace(True) == [] From 2b852b2260fbbd6293262b729e30c67904970559 Mon Sep 17 00:00:00 2001 From: Dor-bl <59066376+Dor-bl@users.noreply.github.com> Date: Mon, 19 Oct 2026 05:15:51 +0000 Subject: [PATCH 2/4] test: add unit tests for format_stacktrace Add unit tests for `format_stacktrace` in `test/unit/webdriver/errorhandler_test.py` covering empty inputs, string stack traces, sequence of frame dicts with optional keys, non-dict elements, and non-iterable inputs. From c16ec020ca428fd47c9caa69c68f12ccdf353cf2 Mon Sep 17 00:00:00 2001 From: Dor-bl <59066376+Dor-bl@users.noreply.github.com> Date: Mon, 19 Oct 2026 05:51:42 +0000 Subject: [PATCH 3/4] test: add unit tests for format_stacktrace Add unit tests for `format_stacktrace` in `test/unit/webdriver/errorhandler_test.py` covering empty inputs, string stack traces, sequence of frame dicts with optional keys, non-dict elements, and non-iterable inputs. From 166bd904932b6f2f060eb9ef4cf8462a47952903 Mon Sep 17 00:00:00 2001 From: Dor-bl <59066376+Dor-bl@users.noreply.github.com> Date: Mon, 19 Oct 2026 06:42:59 +0000 Subject: [PATCH 4/4] test: add unit tests for format_stacktrace Add unit tests for `format_stacktrace` in `test/unit/webdriver/errorhandler_test.py` covering empty inputs, string stack traces, sequence of frame dicts with optional keys, non-dict elements, and non-iterable inputs.