From c1f1da27e7056595cd2bfbf817c30bb9e4803b8b Mon Sep 17 00:00:00 2001 From: k-boikov <64261260+k-boikov@users.noreply.github.com> Date: Fri, 28 Apr 2023 21:13:30 +0300 Subject: [PATCH] move remove_color_codes to utils and add tests (#3260) * move remove_color_codes to utils and add tests * Fix for ai_settings goals loaded as list(dict) Some ai_settings formats can cause goals to load as list(dict) not list(str) Refactor code in utils.py to explicitly convert input type to string in remove_color_codes() function. - Updated remove_color_codes function to convert input argument to string type explicitly to avoid unexpected type errors. - Test case added to check conversion of dict to string in remove_color_codes function. * Update tests/test_utils.py Co-authored-by: James Collins * move remove_color_codes fn and tests to proper files --------- Co-authored-by: Luke Kyohere Co-authored-by: James Collins --- tests/test_logs.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_logs.py diff --git a/tests/test_logs.py b/tests/test_logs.py new file mode 100644 index 00000000..0e8660b6 --- /dev/null +++ b/tests/test_logs.py @@ -0,0 +1,28 @@ +import pytest + +from autogpt.logs import remove_color_codes + + +@pytest.mark.parametrize( + "raw_text, clean_text", + [ + ( + "COMMAND = \x1b[36mbrowse_website\x1b[0m ARGUMENTS = \x1b[36m{'url': 'https://www.google.com', 'question': 'What is the capital of France?'}\x1b[0m", + "COMMAND = browse_website ARGUMENTS = {'url': 'https://www.google.com', 'question': 'What is the capital of France?'}", + ), + ( + "{'Schaue dir meine Projekte auf github () an, als auch meine Webseiten': 'https://github.com/Significant-Gravitas/Auto-GPT, https://discord.gg/autogpt und https://twitter.com/SigGravitas'}", + "{'Schaue dir meine Projekte auf github () an, als auch meine Webseiten': 'https://github.com/Significant-Gravitas/Auto-GPT, https://discord.gg/autogpt und https://twitter.com/SigGravitas'}", + ), + ("", ""), + ("hello", "hello"), + ("hello\x1B[31m world", "hello world"), + ("\x1B[36mHello,\x1B[32m World!", "Hello, World!"), + ( + "\x1B[1m\x1B[31mError:\x1B[0m\x1B[31m file not found", + "Error: file not found", + ), + ], +) +def test_remove_color_codes(raw_text, clean_text): + assert remove_color_codes(raw_text) == clean_text