Skip to content

Commit

Permalink
[chiptool runner] Rename TestParserHooks methods (#28371)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccruzagralopes authored Aug 16, 2023
1 parent 76848fe commit f37238d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
13 changes: 6 additions & 7 deletions scripts/py_matter_yamltests/matter_yamltests/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .errors import TestStepError
from .parser import TestStep


class TestParserHooks():
__test__ = False

def start(self, count: int):
def parsing_start(self, count: int):
"""
This method is called when the parser starts parsing a set of files.
Expand All @@ -31,7 +30,7 @@ def start(self, count: int):
"""
pass

def stop(self, duration: int):
def parsing_stop(self, duration: int):
"""
This method is called when the parser is done parsing a set of files.
Expand All @@ -42,7 +41,7 @@ def stop(self, duration: int):
"""
pass

def test_start(self, name: str):
def test_parsing_start(self, name: str):
"""
This method is called when the parser starts parsing a single file.
Expand All @@ -53,20 +52,20 @@ def test_start(self, name: str):
"""
pass

def test_failure(self, exception: TestStepError, duration: int):
def test_parsing_failure(self, exception: Exception, duration: int):
"""
This method is called when parsing a single file fails.
Parameters
----------
exception: TestStepError
exception: Exception
An exception describing why parsing the file has failed.
duration: int
How long it took to parse the file, in milliseconds.
"""
pass

def test_success(self, duration: int):
def test_parsing_success(self, duration: int):
"""
This method is called when parsing a single file succeeds.
Expand Down
10 changes: 5 additions & 5 deletions scripts/py_matter_yamltests/matter_yamltests/parser_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def __init__(self, config: TestParserBuilderConfig = TestParserBuilderConfig()):
self.done = False

def __iter__(self):
self.__config.hooks.start(len(self.__tests))
self.__config.hooks.parsing_start(len(self.__tests))
return self

def __next__(self):
if len(self.__tests):
return self.__get_test_parser(self.__tests.pop(0))

if not self.done:
self.__config.hooks.stop(round(self.__duration))
self.__config.hooks.parsing_stop(round(self.__duration))
self.done = True

raise StopIteration
Expand All @@ -89,18 +89,18 @@ def __get_test_parser(self, test_file: str) -> TestParser:
parser = None
exception = None
try:
self.__config.hooks.test_start(test_file)
self.__config.hooks.test_parsing_start(test_file)
parser = TestParser(test_file, self.__config.parser_config)
except Exception as e:
exception = e

duration = round((time.time() - start) * 1000, 0)
self.__duration += duration
if exception:
self.__config.hooks.test_failure(exception, duration)
self.__config.hooks.test_parsing_failure(exception, duration)
if self.__config.options.stop_on_error:
raise StopIteration
return None

self.__config.hooks.test_success(duration)
self.__config.hooks.test_parsing_success(duration)
return parser
10 changes: 5 additions & 5 deletions scripts/py_matter_yamltests/test_parser_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ def __init__(self):
self.test_failure_count = 0
self.test_success_count = 0

def start(self, count):
def parsing_start(self, count):
self.start_count += 1

def stop(self, duration):
def parsing_stop(self, duration):
self.stop_count += 1

def test_start(self, name):
def test_parsing_start(self, name):
self.test_start_count += 1

def test_success(self, duration):
def test_parsing_success(self, duration):
self.test_success_count += 1

def test_failure(self, exception, duration):
def test_parsing_failure(self, exception, duration):
self.test_failure_count += 1


Expand Down
10 changes: 5 additions & 5 deletions scripts/tests/yaml/tests_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ def __init__(self):
self.__errors = 0
self.__strings = ParserStrings()

def start(self, count: int):
def parsing_start(self, count: int):
print(self.__strings.start.format(count=count))

def stop(self, duration: int):
def parsing_stop(self, duration: int):
state = _FAILURE if self.__errors else _SUCCESS
success = click.style(self.__success, bold=True)
errors = click.style(self.__errors, bold=True)
print(self.__strings.stop.format(state=state, successes=success, errors=errors, duration=duration))

def test_start(self, name: str):
def test_parsing_start(self, name: str):
print(self.__strings.test_start.format(name=name), end='')

def test_failure(self, exception: Exception, duration: int):
def test_parsing_failure(self, exception: Exception, duration: int):
print(self.__strings.test_result.format(state=_FAILURE, duration=duration))

try:
Expand All @@ -91,7 +91,7 @@ def test_failure(self, exception: Exception, duration: int):

self.__errors += 1

def test_success(self, duration: int):
def test_parsing_success(self, duration: int):
print(self.__strings.test_result.format(state=_SUCCESS, duration=duration))
self.__success += 1

Expand Down

0 comments on commit f37238d

Please sign in to comment.