Skip to content

Commit

Permalink
重构 efw_test.py 文件中的导入路径,新增 output.py 测试文件,覆盖多种文件格式的打印和验证功能,改进 ci_rele…
Browse files Browse the repository at this point in the history
…ase.py 脚本,添加类型注解和丰富的异常处理
  • Loading branch information
AstroAir committed Nov 23, 2024
1 parent 4b9ceff commit 36a865c
Show file tree
Hide file tree
Showing 13 changed files with 3,328 additions and 681 deletions.
450 changes: 376 additions & 74 deletions modules/lithium.pydevice/zwoasi/example/eaf_test.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/lithium.pydevice/zwoasi/example/efw_test.py
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


Expand Down
129 changes: 129 additions & 0 deletions modules/lithium.pytools/tests/output.py
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')
Loading

0 comments on commit 36a865c

Please sign in to comment.