Skip to content

Commit

Permalink
feat: update conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
topsworld committed Dec 16, 2024
1 parent 9d95379 commit d2e46e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 15 additions & 11 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from os import path, makedirs

TEST_ROOT_PATH: str = path.dirname(path.abspath(__file__))
TEST_FILES_PATH: str = path.join(TEST_ROOT_PATH, 'miot')
TEST_CACHE_PATH: str = path.join(TEST_ROOT_PATH, 'test_cache')
TEST_LANG: str = 'zh-Hans'
TEST_UID: str = '123456789'
Expand All @@ -26,36 +27,39 @@ def load_py_file():
'miot_network.py',
'miot_spec.py',
'miot_storage.py']
makedirs(path.join(TEST_ROOT_PATH, 'miot'), exist_ok=True)
makedirs(TEST_CACHE_PATH, exist_ok=True)
makedirs(TEST_FILES_PATH, exist_ok=True)
for file_name in file_list:
shutil.copyfile(
path.join(
TEST_ROOT_PATH, '../custom_components/xiaomi_home/miot',
file_name),
path.join(TEST_ROOT_PATH, 'miot', file_name))
print('loaded test py file, ', file_list)
path.join(TEST_FILES_PATH, file_name))
print('\nloaded test py files, ', 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'),
dst=path.join(TEST_FILES_PATH, 'specs'),
dirs_exist_ok=True)
print('loaded spec test folder, miot/specs')
print('loaded spec test folder, 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'),
dst=path.join(TEST_FILES_PATH, 'i18n'),
dirs_exist_ok=True)
print('loaded i18n test folder, miot/i18n')
print('loaded i18n test folder, i18n')

yield

shutil.rmtree(path.join(TEST_ROOT_PATH, 'miot'))
print('removed test file, ', file_list)
if path.exists(TEST_FILES_PATH):
shutil.rmtree(TEST_FILES_PATH)
print('\nremoved test files, ', TEST_FILES_PATH)

shutil.rmtree(TEST_CACHE_PATH)
print('removed test file, ', TEST_CACHE_PATH)
if path.exists(TEST_CACHE_PATH):
shutil.rmtree(TEST_CACHE_PATH)
print('removed test cache, ', TEST_CACHE_PATH)


@pytest.fixture(scope='session')
Expand Down
2 changes: 0 additions & 2 deletions test/test_mdns.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
"""Unit test for miot_mdns.py."""
import asyncio
import pytest

from zeroconf import IPVersion
from zeroconf.asyncio import AsyncZeroconf

Expand Down

0 comments on commit d2e46e0

Please sign in to comment.