test: add test case for miot spec

This commit is contained in:
topsworld
2024-12-13 21:07:43 +08:00
committed by Lucien Hsiao
parent bac1c7027b
commit ad7f9eb610
3 changed files with 113 additions and 27 deletions

View File

@ -5,6 +5,7 @@ import pytest
from os import path, makedirs
TEST_ROOT_PATH: str = path.dirname(path.abspath(__file__))
TEST_CACHE_PATH: str = path.join(TEST_ROOT_PATH, 'test_cache')
TEST_LANG: str = 'zh-Hans'
TEST_UID: str = '123456789'
TEST_CLOUD_SERVER: str = 'cn'
@ -32,28 +33,29 @@ def load_py_file():
TEST_ROOT_PATH, '../custom_components/xiaomi_home/miot',
file_name),
path.join(TEST_ROOT_PATH, 'miot', file_name))
print('\nloaded test py file, %s' % file_list)
print('loaded test py file, ', file_list)
# Copy spec files to test folder
shutil.copytree(
src=path.join(
TEST_ROOT_PATH, '../custom_components/xiaomi_home/miot/specs'),
dst=path.join(TEST_ROOT_PATH, 'miot/specs'),
dirs_exist_ok=True)
print('\nloaded spec test folder, miot/specs')
print('loaded spec test folder, miot/specs')
# Copy i18n files to test folder
shutil.copytree(
src=path.join(
TEST_ROOT_PATH, '../custom_components/xiaomi_home/miot/i18n'),
dst=path.join(TEST_ROOT_PATH, 'miot/i18n'),
dirs_exist_ok=True)
print('\nloaded i18n test folder, miot/i18n')
print('loaded i18n test folder, miot/i18n')
yield
# shutil.rmtree(path.join(TEST_ROOT_PATH, 'miot'))
# print('\nremoved test file, %s', file_list)
# shutil.rmtree(path.join(TEST_ROOT_PATH, 'miot/specs'))
# print('\nremoved test folder, %s', 'miot/specs')
# shutil.rmtree(path.join(TEST_ROOT_PATH, 'miot/i18n'))
# print('\nremoved test folder, %s', 'miot/i18n')
shutil.rmtree(path.join(TEST_ROOT_PATH, 'miot'))
print('removed test file, ', file_list)
shutil.rmtree(TEST_CACHE_PATH)
print('removed test file, ', TEST_CACHE_PATH)
@pytest.fixture(scope='session')
@ -63,9 +65,8 @@ def test_root_path() -> str:
@pytest.fixture(scope='session')
def test_cache_path() -> str:
cache_path: str = path.join(TEST_ROOT_PATH, 'test_cache')
makedirs(cache_path, exist_ok=True)
return cache_path
makedirs(TEST_CACHE_PATH, exist_ok=True)
return TEST_CACHE_PATH
@pytest.fixture(scope='session')