-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重构 efw_test.py 文件中的导入路径,新增 output.py 测试文件,覆盖多种文件格式的打印和验证功能,改进 ci_rele…
…ase.py 脚本,添加类型注解和丰富的异常处理
- Loading branch information
Showing
13 changed files
with
3,328 additions
and
681 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import ctypes | ||
from asi_efw import * | ||
from libs.efw import * | ||
from loguru import logger | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import pytest | ||
from unittest.mock import patch, mock_open | ||
from pathlib import Path | ||
|
||
from output import ( | ||
pretty_print_json, pretty_print_yaml, pretty_print_toml, | ||
pretty_print_xml, pretty_print_csv, pretty_print_ini, | ||
validate_file, display_file | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def json_data(): | ||
return '{"key": "value"}' | ||
|
||
|
||
@pytest.fixture | ||
def yaml_data(): | ||
return 'key: value' | ||
|
||
|
||
@pytest.fixture | ||
def toml_data(): | ||
return 'key = "value"' | ||
|
||
|
||
@pytest.fixture | ||
def xml_data(): | ||
return '<root><key>value</key></root>' | ||
|
||
|
||
@pytest.fixture | ||
def csv_data(): | ||
return 'key,value\nfoo,bar' | ||
|
||
|
||
@pytest.fixture | ||
def ini_data(): | ||
return '[section]\nkey=value' | ||
|
||
|
||
def test_pretty_print_json(json_data): | ||
with patch('builtins.open', mock_open(read_data=json_data)): | ||
pretty_print_json(json_data) | ||
|
||
|
||
def test_pretty_print_yaml(yaml_data): | ||
with patch('builtins.open', mock_open(read_data=yaml_data)): | ||
pretty_print_yaml(yaml_data) | ||
|
||
|
||
def test_pretty_print_toml(toml_data): | ||
with patch('builtins.open', mock_open(read_data=toml_data)): | ||
pretty_print_toml(toml_data) | ||
|
||
|
||
def test_pretty_print_xml(xml_data): | ||
with patch('builtins.open', mock_open(read_data=xml_data)): | ||
pretty_print_xml(xml_data) | ||
|
||
|
||
def test_pretty_print_csv(csv_data): | ||
with patch('builtins.open', mock_open(read_data=csv_data)): | ||
pretty_print_csv(csv_data) | ||
|
||
|
||
def test_pretty_print_ini(ini_data): | ||
with patch('builtins.open', mock_open(read_data=ini_data)): | ||
pretty_print_ini(ini_data) | ||
|
||
|
||
def test_validate_json(json_data): | ||
with patch('pathlib.Path.read_text', return_value=json_data): | ||
assert validate_file(Path('example.json'), 'json') | ||
|
||
|
||
def test_validate_yaml(yaml_data): | ||
with patch('pathlib.Path.read_text', return_value=yaml_data): | ||
assert validate_file(Path('example.yaml'), 'yaml') | ||
|
||
|
||
def test_validate_toml(toml_data): | ||
with patch('pathlib.Path.read_text', return_value=toml_data): | ||
assert validate_file(Path('example.toml'), 'toml') | ||
|
||
|
||
def test_validate_xml(xml_data): | ||
with patch('pathlib.Path.read_text', return_value=xml_data): | ||
assert validate_file(Path('example.xml'), 'xml') | ||
|
||
|
||
def test_validate_csv(csv_data): | ||
with patch('pathlib.Path.read_text', return_value=csv_data): | ||
assert validate_file(Path('example.csv'), 'csv') | ||
|
||
|
||
def test_validate_ini(ini_data): | ||
with patch('pathlib.Path.read_text', return_value=ini_data): | ||
assert validate_file(Path('example.ini'), 'ini') | ||
|
||
|
||
def test_display_file_json(json_data): | ||
with patch('pathlib.Path.read_text', return_value=json_data): | ||
display_file(Path('example.json'), 'json') | ||
|
||
|
||
def test_display_file_yaml(yaml_data): | ||
with patch('pathlib.Path.read_text', return_value=yaml_data): | ||
display_file(Path('example.yaml'), 'yaml') | ||
|
||
|
||
def test_display_file_toml(toml_data): | ||
with patch('pathlib.Path.read_text', return_value=toml_data): | ||
display_file(Path('example.toml'), 'toml') | ||
|
||
|
||
def test_display_file_xml(xml_data): | ||
with patch('pathlib.Path.read_text', return_value=xml_data): | ||
display_file(Path('example.xml'), 'xml') | ||
|
||
|
||
def test_display_file_csv(csv_data): | ||
with patch('pathlib.Path.read_text', return_value=csv_data): | ||
display_file(Path('example.csv'), 'csv') | ||
|
||
|
||
def test_display_file_ini(ini_data): | ||
with patch('pathlib.Path.read_text', return_value=ini_data): | ||
display_file(Path('example.ini'), 'ini') |
Oops, something went wrong.