mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
42075d5c75
- data_model/legacy/: moved old data model to this folder - data_model/generated/: contain the automatically generated data model - tools/data_model_gen: contains the script to generate the data model
124 lines
3.7 KiB
Python
124 lines
3.7 KiB
Python
# Copyright 2026 Espressif Systems (Shanghai) PTE LTD
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""Tests for utils/config.py — configuration, provisional mode, logger, file names."""
|
|
|
|
import unittest
|
|
import sys
|
|
import os
|
|
import logging
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
from utils.config import ( # noqa: E402
|
|
setup_provisional_mode,
|
|
allow_provisional,
|
|
set_esp_matter_path,
|
|
setup_logger,
|
|
FileNames,
|
|
SPECIFICATION_VERSIONS,
|
|
DEFAULT_CHIP_VERSION,
|
|
)
|
|
from utils.exceptions import ConfigurationError # noqa: E402
|
|
|
|
|
|
class TestProvisionalMode(unittest.TestCase):
|
|
"""Test provisional mode control."""
|
|
|
|
def tearDown(self):
|
|
setup_provisional_mode(False)
|
|
|
|
def test_default_not_provisional(self):
|
|
setup_provisional_mode(False)
|
|
self.assertFalse(allow_provisional())
|
|
|
|
def test_enable_provisional(self):
|
|
setup_provisional_mode(True)
|
|
self.assertTrue(allow_provisional())
|
|
|
|
def test_disable_provisional(self):
|
|
setup_provisional_mode(True)
|
|
setup_provisional_mode(False)
|
|
self.assertFalse(allow_provisional())
|
|
|
|
|
|
class TestSetEspMatterPath(unittest.TestCase):
|
|
"""Test set_esp_matter_path() — path validation."""
|
|
|
|
def test_empty_path_raises(self):
|
|
with self.assertRaises(ConfigurationError):
|
|
set_esp_matter_path("")
|
|
|
|
def test_whitespace_path_raises(self):
|
|
with self.assertRaises(ConfigurationError):
|
|
set_esp_matter_path(" ")
|
|
|
|
def test_none_path_raises(self):
|
|
with self.assertRaises(ConfigurationError):
|
|
set_esp_matter_path(None)
|
|
|
|
def test_nonexistent_path_raises(self):
|
|
with self.assertRaises(ConfigurationError):
|
|
set_esp_matter_path("/nonexistent/path/that/does/not/exist")
|
|
|
|
def test_valid_path(self):
|
|
import tempfile
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
set_esp_matter_path(tmpdir)
|
|
|
|
|
|
class TestSetupLogger(unittest.TestCase):
|
|
"""Test setup_logger() — logger configuration."""
|
|
|
|
def test_setup_default(self):
|
|
setup_logger("INFO", False)
|
|
root = logging.getLogger()
|
|
self.assertTrue(root.hasHandlers())
|
|
|
|
def test_setup_colored(self):
|
|
setup_logger("DEBUG", True)
|
|
root = logging.getLogger()
|
|
self.assertTrue(root.hasHandlers())
|
|
|
|
|
|
class TestFileNames(unittest.TestCase):
|
|
"""Test FileNames enum values."""
|
|
|
|
def test_cluster_json(self):
|
|
self.assertEqual(FileNames.CLUSTER_JSON.value, "clusters.json")
|
|
|
|
def test_device_json(self):
|
|
self.assertEqual(FileNames.DEVICE_JSON.value, "device_types.json")
|
|
|
|
def test_all_values_are_json(self):
|
|
for fn in FileNames:
|
|
self.assertTrue(
|
|
fn.value.endswith(".json"), f"{fn.name} should end with .json"
|
|
)
|
|
|
|
|
|
class TestSpecificationVersions(unittest.TestCase):
|
|
"""Test specification version constants."""
|
|
|
|
def test_versions_list(self):
|
|
self.assertIn("1.4", SPECIFICATION_VERSIONS)
|
|
self.assertIn("1.5", SPECIFICATION_VERSIONS)
|
|
|
|
def test_default_version(self):
|
|
self.assertIn(DEFAULT_CHIP_VERSION, SPECIFICATION_VERSIONS)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|