From fa0d3dbadc2fbba6978e7af18b3898b83ed4820c Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 24 Jan 2023 11:52:29 +0100 Subject: [PATCH] [matter_yamltests] Ensure that the PICSChecker code does not throw if no file is used --- scripts/py_matter_yamltests/matter_yamltests/pics_checker.py | 5 +++-- scripts/py_matter_yamltests/test_pics_checker.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/pics_checker.py b/scripts/py_matter_yamltests/matter_yamltests/pics_checker.py index 580c83dfd696c6..5c1fca1101240d 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/pics_checker.py +++ b/scripts/py_matter_yamltests/matter_yamltests/pics_checker.py @@ -39,10 +39,11 @@ class InvalidPICSParsingError(Exception): class PICSChecker(): """Class to compute a PICS expression""" - __pics: None - __expression_index: 0 def __init__(self, pics_file: str): + self.__pics = {} + self.__expression_index = 0 + if pics_file is not None: self.__pics = self.__parse(pics_file) diff --git a/scripts/py_matter_yamltests/test_pics_checker.py b/scripts/py_matter_yamltests/test_pics_checker.py index df3364c0d21c4b..39f2dcd10b6806 100644 --- a/scripts/py_matter_yamltests/test_pics_checker.py +++ b/scripts/py_matter_yamltests/test_pics_checker.py @@ -67,6 +67,11 @@ class TestPICSChecker(unittest.TestCase): + def test_no_file(self): + pics_checker = PICSChecker(None) + self.assertIsInstance(pics_checker, PICSChecker) + self.assertFalse(pics_checker.check('A.A')) + @patch('builtins.open', mock_open(read_data=empty_config)) def test_empty_config(self): pics_checker = PICSChecker('')