mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-27 01:36:29 +02:00
update test_vision.py for mock
This commit is contained in:
parent
7f1584db9e
commit
66db86ae2a
2 changed files with 48 additions and 40 deletions
48
tests/metagpt/tools/functions/libs/test_vision.py
Normal file
48
tests/metagpt/tools/functions/libs/test_vision.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2024/01/15
|
||||
@Author : mannaandpoem
|
||||
@File : test_vision.py
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt import logs
|
||||
from metagpt.tools.functions.libs.vision import Vision
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_webpages():
|
||||
return """```html\n<html>\n<script src="scripts.js"></script>
|
||||
<link rel="stylesheet" href="styles.css(">\n</html>\n```\n
|
||||
```css\n.class { ... }\n```\n
|
||||
```javascript\nfunction() { ... }\n```\n"""
|
||||
|
||||
|
||||
def test_vision_generate_webpages(mocker, mock_webpages):
|
||||
mocker.patch(
|
||||
"metagpt.tools.functions.libs.vision.Vision.generate_web_pages",
|
||||
return_value=mock_webpages
|
||||
)
|
||||
image_path = "image.png"
|
||||
vision = Vision()
|
||||
rsp = vision.generate_web_pages(image_path=image_path)
|
||||
logs.logger.info(rsp)
|
||||
assert "html" in rsp
|
||||
assert "css" in rsp
|
||||
assert "javascript" in rsp
|
||||
|
||||
|
||||
def test_save_webpages(mocker, mock_webpages):
|
||||
mocker.patch(
|
||||
"metagpt.tools.functions.libs.vision.Vision.generate_web_pages",
|
||||
return_value=mock_webpages
|
||||
)
|
||||
image_path = "image.png"
|
||||
vision = Vision()
|
||||
webpages = vision.generate_web_pages(image_path)
|
||||
webpages_dir = vision.save_webpages(image_path=image_path, webpages=webpages)
|
||||
logs.logger.info(webpages_dir)
|
||||
assert webpages_dir.exists()
|
||||
|
||||
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2024/01/15
|
||||
@Author : mannaandpoem
|
||||
@File : test_vision.py
|
||||
"""
|
||||
import base64
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from pytest_mock import mocker
|
||||
|
||||
from metagpt import logs
|
||||
from metagpt.tools.functions.libs.vision import Vision
|
||||
|
||||
|
||||
def test_vision_generate_web_pages():
|
||||
image_path = "./image.png"
|
||||
vision = Vision()
|
||||
rsp = vision.generate_web_pages(image_path=image_path)
|
||||
logs.logger.info(rsp)
|
||||
assert "html" in rsp
|
||||
assert "css" in rsp
|
||||
assert "javascript" in rsp
|
||||
|
||||
|
||||
def test_save_webpages():
|
||||
image_path = "./image.png"
|
||||
vision = Vision()
|
||||
webpages = """```html: <html>\n<script src="scripts.js"></script>
|
||||
<link rel="stylesheet" href="styles.css(">\n</html>```
|
||||
"```css: .class { ... } ```\n ```javascript: function() { ... }```"""
|
||||
webpages_dir = vision.save_webpages(image_path=image_path, webpages=webpages)
|
||||
logs.logger.info(webpages_dir)
|
||||
assert webpages_dir.exists()
|
||||
assert (webpages_dir / "index.html").exists()
|
||||
assert (webpages_dir / "style.css").exists() or (webpages_dir / "styles.css").exists()
|
||||
assert (webpages_dir / "script.js").exists() or (webpages_dir / "scripts.js").exists()
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue