Skip to content

Commit

Permalink
feat: add spec data sort
Browse files Browse the repository at this point in the history
  • Loading branch information
topsworld committed Dec 20, 2024
1 parent 66a16be commit 1fd5b96
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
34 changes: 29 additions & 5 deletions test/check_rule_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def load_json_file(file_path: str) -> Optional[dict]:
return None


def save_json_file(file_path: str, data: dict) -> None:
with open(file_path, 'w', encoding='utf-8') as file:
json.dump(data, file, ensure_ascii=False, indent=4)


def load_yaml_file(file_path: str) -> Optional[dict]:
try:
with open(file_path, 'r', encoding='utf-8') as file:
Expand Down Expand Up @@ -253,17 +258,36 @@ def test_miot_data_sort():
from miot.const import INTEGRATION_LANGUAGES
sort_langs: dict = dict(sorted(INTEGRATION_LANGUAGES.items()))
assert list(INTEGRATION_LANGUAGES.keys()) == list(sort_langs.keys()), (
'INTEGRATION_LANGUAGES not sorted, correct order'
f'\r\n{list(sort_langs.keys())}')
'INTEGRATION_LANGUAGES not sorted, correct order\r\n'
f'{list(sort_langs.keys())}')
assert json.dumps(
load_json_file(file_path=SPEC_BOOL_TRANS_FILE)) == json.dumps(
sort_bool_trans(file_path=SPEC_BOOL_TRANS_FILE)), (
f'{SPEC_BOOL_TRANS_FILE} not sorted')
f'{SPEC_BOOL_TRANS_FILE} not sorted, goto project root path'
' and run the following command sorting, ',
'pytest -s -v -m update ./test/check_rule_format.py')
assert json.dumps(
load_json_file(file_path=SPEC_MULTI_LANG_FILE)) == json.dumps(
sort_multi_lang(file_path=SPEC_MULTI_LANG_FILE)), (
f'{SPEC_MULTI_LANG_FILE} not sorted')
f'{SPEC_MULTI_LANG_FILE} not sorted, goto project root path'
' and run the following command sorting, ',
'pytest -s -v -m update ./test/check_rule_format.py')
assert json.dumps(
load_json_file(file_path=SPEC_FILTER_FILE)) == json.dumps(
sort_spec_filter(file_path=SPEC_FILTER_FILE)), (
f'{SPEC_FILTER_FILE} not sorted')
f'{SPEC_FILTER_FILE} not sorted, goto project root path'
' and run the following command sorting, ',
'pytest -s -v -m update ./test/check_rule_format.py')


@pytest.mark.update
def test_sort_spec_data():
sort_data: dict = sort_bool_trans(file_path=SPEC_BOOL_TRANS_FILE)
save_json_file(file_path=SPEC_BOOL_TRANS_FILE, data=sort_data)
print(SPEC_BOOL_TRANS_FILE, 'formatted.')
sort_data = sort_multi_lang(file_path=SPEC_MULTI_LANG_FILE)
save_json_file(file_path=SPEC_MULTI_LANG_FILE, data=sort_data)
print(SPEC_MULTI_LANG_FILE, 'formatted.')
sort_data = sort_spec_filter(file_path=SPEC_FILTER_FILE)
save_json_file(file_path=SPEC_FILTER_FILE, data=sort_data)
print(SPEC_FILTER_FILE, 'formatted.')
3 changes: 2 additions & 1 deletion test/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[pytest]
markers:
github: tests for github actions
github: tests for github actions
update: update or re-sort config file

0 comments on commit 1fd5b96

Please sign in to comment.