Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

move remove_color_codes to utils and add tests (#3260)

k-boikovc1f1da27e705
diff --git a/tests/test_logs.py b/tests/test_logs.py
new file mode 100644
index 0000000000..0e8660b6cf
--- /dev/null
+++ b/tests/test_logs.py
@@ -0,0 +1,28 @@
+import pytest
+
+from autogpt.logs import remove_color_codes
+
+
+ "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