From 2dc34fb9b4f3b95d6ac2fcddfc2101bb3e788004 Mon Sep 17 00:00:00 2001 From: stellaHSR Date: Sat, 22 Jul 2023 11:04:24 +0800 Subject: [PATCH] split test cases --- tests/metagpt/test_sd_tool.py | 25 +++ tests/metagpt/test_ui.py | 296 +------------------------------- tests/metagpt/test_ui_design.py | 285 ++++++++++++++++++++++++++++++ 3 files changed, 312 insertions(+), 294 deletions(-) create mode 100644 tests/metagpt/test_sd_tool.py create mode 100644 tests/metagpt/test_ui_design.py diff --git a/tests/metagpt/test_sd_tool.py b/tests/metagpt/test_sd_tool.py new file mode 100644 index 000000000..77e53c7dc --- /dev/null +++ b/tests/metagpt/test_sd_tool.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# @Date : 2023/7/22 02:40 +# @Author : stellahong (stellahong@fuzhi.ai) +# +import os + +from metagpt.tools.sd_engine import SDEngine, WORKSPACE_ROOT + + +def test_sd_engine_init(): + sd_engine = SDEngine() + assert sd_engine.payload["seed"] == -1 + + +def test_sd_engine_generate_prompt(): + sd_engine = SDEngine() + sd_engine.construct_payload(prompt="test") + assert sd_engine.payload["prompt"] == "test" + + +async def test_sd_engine_run_t2i(): + sd_engine = SDEngine() + await sd_engine.run_t2i(prompts=["test"]) + img_path = WORKSPACE_ROOT / "resources" / "SD_Output" / "output_0.png" + assert os.path.exists(img_path) == True diff --git a/tests/metagpt/test_ui.py b/tests/metagpt/test_ui.py index 098cdbffa..a52320676 100644 --- a/tests/metagpt/test_ui.py +++ b/tests/metagpt/test_ui.py @@ -6,305 +6,13 @@ import os from metagpt.software_company import SoftwareCompany from metagpt.roles import ProductManager -from examples.ui_role import UI, UIDesign -from metagpt.tools.sd_engine import SDEngine, WORKSPACE_ROOT +from examples.ui_role import UI -def test_add_UI(): +def test_add_ui(): ui = UI() assert ui.profile == "UI Design" -def test_UIDesign_parse_css(): - ui_design_work = UIDesign(name="UI design action") - llm_resp = ''' - # UI Design Description -```The user interface for the snake game will be designed in a way that is simple, clean, and intuitive. The main elements of the game such as the game grid, snake, food, score, and game over message will be clearly defined and easy to understand. The game grid will be centered on the screen with the score displayed at the top. The game controls will be intuitive and easy to use. The design will be modern and minimalist with a pleasing color scheme.``` - -## Selected Elements - -Game Grid: The game grid will be a rectangular area in the center of the screen where the game will take place. It will be defined by a border and will have a darker background color. - -Snake: The snake will be represented by a series of connected blocks that move across the grid. The color of the snake will be different from the background color to make it stand out. - -Food: The food will be represented by small objects that are a different color from the snake and the background. The food will be randomly placed on the grid. - -Score: The score will be displayed at the top of the screen. The score will increase each time the snake eats a piece of food. - -Game Over: When the game is over, a message will be displayed in the center of the screen. The player will be given the option to restart the game. - -## HTML Layout -```html - - - - - - Snake Game - - - -
Score: 0
-
- -
-
Game Over
- - -``` - -## CSS Styles (styles.css) -```css -body { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - height: 100vh; - margin: 0; - background-color: #f0f0f0; -} - -.score { - font-size: 2em; - margin-bottom: 1em; -} - -.game-grid { - width: 400px; - height: 400px; - display: grid; - grid-template-columns: repeat(20, 1fr); - grid-template-rows: repeat(20, 1fr); - gap: 1px; - background-color: #222; - border: 1px solid #555; -} - -.snake-segment { - background-color: #00cc66; -} - -.food { - background-color: #cc3300; -} - -.control-panel { - display: flex; - justify-content: space-around; - width: 400px; - margin-top: 1em; -} - -.control-button { - padding: 1em; - font-size: 1em; - border: none; - background-color: #555; - color: #fff; - cursor: pointer; -} - -.game-over { - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - font-size: 3em; - ''' - - css = ''' - body { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - height: 100vh; - margin: 0; - background-color: #f0f0f0; -} - -.score { - font-size: 2em; - margin-bottom: 1em; -} - -.game-grid { - width: 400px; - height: 400px; - display: grid; - grid-template-columns: repeat(20, 1fr); - grid-template-rows: repeat(20, 1fr); - gap: 1px; - background-color: #222; - border: 1px solid #555; -} - -.snake-segment { - background-color: #00cc66; -} - -.food { - background-color: #cc3300; -} - -.control-panel { - display: flex; - justify-content: space-around; - width: 400px; - margin-top: 1em; -} - -.control-button { - padding: 1em; - font-size: 1em; - border: none; - background-color: #555; - color: #fff; - cursor: pointer; -} - -.game-over { - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - font-size: 3em; - ''' - assert ui_design_work.parse_css_code(context=llm_resp)==css - - -def test_UIDesign_parse_html(): - ui_design_work = UIDesign(name="UI design action") - llm_resp = ''' - # UI Design Description -```The user interface for the snake game will be designed in a way that is simple, clean, and intuitive. The main elements of the game such as the game grid, snake, food, score, and game over message will be clearly defined and easy to understand. The game grid will be centered on the screen with the score displayed at the top. The game controls will be intuitive and easy to use. The design will be modern and minimalist with a pleasing color scheme.``` - -## Selected Elements - -Game Grid: The game grid will be a rectangular area in the center of the screen where the game will take place. It will be defined by a border and will have a darker background color. - -Snake: The snake will be represented by a series of connected blocks that move across the grid. The color of the snake will be different from the background color to make it stand out. - -Food: The food will be represented by small objects that are a different color from the snake and the background. The food will be randomly placed on the grid. - -Score: The score will be displayed at the top of the screen. The score will increase each time the snake eats a piece of food. - -Game Over: When the game is over, a message will be displayed in the center of the screen. The player will be given the option to restart the game. - -## HTML Layout -```html - - - - - - Snake Game - - - -
Score: 0
-
- -
-
Game Over
- - -``` - -## CSS Styles (styles.css) -```css -body { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - height: 100vh; - margin: 0; - background-color: #f0f0f0; -} - -.score { - font-size: 2em; - margin-bottom: 1em; -} - -.game-grid { - width: 400px; - height: 400px; - display: grid; - grid-template-columns: repeat(20, 1fr); - grid-template-rows: repeat(20, 1fr); - gap: 1px; - background-color: #222; - border: 1px solid #555; -} - -.snake-segment { - background-color: #00cc66; -} - -.food { - background-color: #cc3300; -} - -.control-panel { - display: flex; - justify-content: space-around; - width: 400px; - margin-top: 1em; -} - -.control-button { - padding: 1em; - font-size: 1em; - border: none; - background-color: #555; - color: #fff; - cursor: pointer; -} - -.game-over { - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - font-size: 3em; - ''' - - html = ''' - - - - - - Snake Game - - - -
Score: 0
-
- -
-
Game Over
- - - ''' - assert ui_design_work.parse_css_code(context=llm_resp)==html - -def test_sd_engine_init(): - sd_engine = SDEngine() - assert sd_engine.payload["seed"]==-1 - -def test_sd_engine_generate_prompt(): - sd_engine = SDEngine() - sd_engine.construct_payload(prompt="test") - assert sd_engine.payload["prompt"] == "test" - -async def test_sd_engine_run_t2i(): - sd_engine = SDEngine() - await sd_engine.run_t2i(prompts=["test"]) - img_path = WORKSPACE_ROOT / "SD_Output"/ "output_0.png" - assert os.path.exists(img_path)==True async def test_ui_role(idea: str, investment: float = 3.0, n_round: int = 5): """Run a startup. Be a boss.""" diff --git a/tests/metagpt/test_ui_design.py b/tests/metagpt/test_ui_design.py new file mode 100644 index 000000000..304241a6c --- /dev/null +++ b/tests/metagpt/test_ui_design.py @@ -0,0 +1,285 @@ +# -*- coding: utf-8 -*- +# @Date : 2023/7/22 02:40 +# @Author : stellahong (stellahong@fuzhi.ai) +# +from examples.ui_role import UIDesign + +def test_ui_design_parse_css(): + ui_design_work = UIDesign(name="UI design action") + llm_resp = ''' + # UI Design Description +```The user interface for the snake game will be designed in a way that is simple, clean, and intuitive. The main elements of the game such as the game grid, snake, food, score, and game over message will be clearly defined and easy to understand. The game grid will be centered on the screen with the score displayed at the top. The game controls will be intuitive and easy to use. The design will be modern and minimalist with a pleasing color scheme.``` + +## Selected Elements + +Game Grid: The game grid will be a rectangular area in the center of the screen where the game will take place. It will be defined by a border and will have a darker background color. + +Snake: The snake will be represented by a series of connected blocks that move across the grid. The color of the snake will be different from the background color to make it stand out. + +Food: The food will be represented by small objects that are a different color from the snake and the background. The food will be randomly placed on the grid. + +Score: The score will be displayed at the top of the screen. The score will increase each time the snake eats a piece of food. + +Game Over: When the game is over, a message will be displayed in the center of the screen. The player will be given the option to restart the game. + +## HTML Layout +```html + + + + + + Snake Game + + + +
Score: 0
+
+ +
+
Game Over
+ + +``` + +## CSS Styles (styles.css) +```css +body { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f0f0; +} + +.score { + font-size: 2em; + margin-bottom: 1em; +} + +.game-grid { + width: 400px; + height: 400px; + display: grid; + grid-template-columns: repeat(20, 1fr); + grid-template-rows: repeat(20, 1fr); + gap: 1px; + background-color: #222; + border: 1px solid #555; +} + +.snake-segment { + background-color: #00cc66; +} + +.food { + background-color: #cc3300; +} + +.control-panel { + display: flex; + justify-content: space-around; + width: 400px; + margin-top: 1em; +} + +.control-button { + padding: 1em; + font-size: 1em; + border: none; + background-color: #555; + color: #fff; + cursor: pointer; +} + +.game-over { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + font-size: 3em; + ''' + + css = ''' + body { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f0f0; +} + +.score { + font-size: 2em; + margin-bottom: 1em; +} + +.game-grid { + width: 400px; + height: 400px; + display: grid; + grid-template-columns: repeat(20, 1fr); + grid-template-rows: repeat(20, 1fr); + gap: 1px; + background-color: #222; + border: 1px solid #555; +} + +.snake-segment { + background-color: #00cc66; +} + +.food { + background-color: #cc3300; +} + +.control-panel { + display: flex; + justify-content: space-around; + width: 400px; + margin-top: 1em; +} + +.control-button { + padding: 1em; + font-size: 1em; + border: none; + background-color: #555; + color: #fff; + cursor: pointer; +} + +.game-over { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + font-size: 3em; + ''' + assert ui_design_work.parse_css_code(context=llm_resp)==css + + +def test_ui_design_parse_html(): + ui_design_work = UIDesign(name="UI design action") + llm_resp = ''' + # UI Design Description +```The user interface for the snake game will be designed in a way that is simple, clean, and intuitive. The main elements of the game such as the game grid, snake, food, score, and game over message will be clearly defined and easy to understand. The game grid will be centered on the screen with the score displayed at the top. The game controls will be intuitive and easy to use. The design will be modern and minimalist with a pleasing color scheme.``` + +## Selected Elements + +Game Grid: The game grid will be a rectangular area in the center of the screen where the game will take place. It will be defined by a border and will have a darker background color. + +Snake: The snake will be represented by a series of connected blocks that move across the grid. The color of the snake will be different from the background color to make it stand out. + +Food: The food will be represented by small objects that are a different color from the snake and the background. The food will be randomly placed on the grid. + +Score: The score will be displayed at the top of the screen. The score will increase each time the snake eats a piece of food. + +Game Over: When the game is over, a message will be displayed in the center of the screen. The player will be given the option to restart the game. + +## HTML Layout +```html + + + + + + Snake Game + + + +
Score: 0
+
+ +
+
Game Over
+ + +``` + +## CSS Styles (styles.css) +```css +body { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f0f0; +} + +.score { + font-size: 2em; + margin-bottom: 1em; +} + +.game-grid { + width: 400px; + height: 400px; + display: grid; + grid-template-columns: repeat(20, 1fr); + grid-template-rows: repeat(20, 1fr); + gap: 1px; + background-color: #222; + border: 1px solid #555; +} + +.snake-segment { + background-color: #00cc66; +} + +.food { + background-color: #cc3300; +} + +.control-panel { + display: flex; + justify-content: space-around; + width: 400px; + margin-top: 1em; +} + +.control-button { + padding: 1em; + font-size: 1em; + border: none; + background-color: #555; + color: #fff; + cursor: pointer; +} + +.game-over { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + font-size: 3em; + ''' + + html = ''' + + + + + + Snake Game + + + +
Score: 0
+
+ +
+
Game Over
+ + + ''' + assert ui_design_work.parse_css_code(context=llm_resp)==html + + +