Skip to content

Commit

Permalink
Fixed usage of add_note on builtin exceptions for older Python versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Jun 2, 2024
1 parent dd41085 commit 287b01c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 10 additions & 5 deletions pyEDAA/Reports/Unittesting/JUnit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from datetime import datetime, timedelta
from enum import Flag
from pathlib import Path
from sys import version_info
from time import perf_counter_ns
from typing import Optional as Nullable, Iterable, Dict, Any, Generator, Tuple, Union, TypeVar, Type, ClassVar

Expand Down Expand Up @@ -95,7 +96,8 @@ def __init__(self, name: str, parent: Nullable["Testsuite"] = None):
raise ValueError(f"Parameter 'name' is None.")
elif not isinstance(name, str):
ex = TypeError(f"Parameter 'name' is not of type 'str'.")
ex.add_note(f"Got type '{getFullyQualifiedName(name)}'.")
if version_info >= (3, 11): # pragma: no cover
ex.add_note(f"Got type '{getFullyQualifiedName(name)}'.")
raise ex

# TODO: check parameter parent
Expand Down Expand Up @@ -173,7 +175,8 @@ def __init__(
if parent is not None:
if not isinstance(parent, Testclass):
ex = TypeError(f"Parameter 'parent' is not of type 'Testclass'.")
ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
if version_info >= (3, 11): # pragma: no cover
ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
raise ex

parent._testcases[name] = self
Expand Down Expand Up @@ -442,7 +445,8 @@ def __init__(
if parent is not None:
if not isinstance(parent, TestsuiteSummary):
ex = TypeError(f"Parameter 'parent' is not of type 'TestsuiteSummary'.")
ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
if version_info >= (3, 11): # pragma: no cover
ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
raise ex

parent._testsuites[name] = self
Expand Down Expand Up @@ -858,8 +862,9 @@ def _Read(self, xmlSchemaFile: str) -> None:

self._xmlDocument = junitDocument
except XMLSyntaxError as ex:
for logEntry in junitParser.error_log:
ex.add_note(str(logEntry))
if version_info >= (3, 11): # pragma: no cover
for logEntry in junitParser.error_log:
ex.add_note(str(logEntry))
raise UnittestException(f"XML syntax or validation error for '{self._path}'.") from ex
except Exception as ex:
raise UnittestException(f"Couldn't open '{self._path}'.") from ex
Expand Down
10 changes: 7 additions & 3 deletions pyEDAA/Reports/Unittesting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from datetime import timedelta, datetime
from enum import Flag, IntEnum
from pathlib import Path
from sys import version_info
from typing import Optional as Nullable, Dict, Iterable, Any, Tuple, Generator, Union, List, Generic, TypeVar

from pyTooling.Common import getFullyQualifiedName
Expand Down Expand Up @@ -193,7 +194,8 @@ def __init__(
raise ValueError(f"Parameter 'name' is None.")
elif not isinstance(name, str):
ex = TypeError(f"Parameter 'name' is not of type 'str'.")
ex.add_note(f"Got type '{getFullyQualifiedName(name)}'.")
if version_info >= (3, 11): # pragma: no cover
ex.add_note(f"Got type '{getFullyQualifiedName(name)}'.")
raise ex

self._parent = parent
Expand Down Expand Up @@ -338,7 +340,8 @@ def __init__(
if parent is not None:
if not isinstance(parent, Testsuite):
ex = TypeError(f"Parameter 'parent' is not of type 'Testsuite'.")
ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
if version_info >= (3, 11): # pragma: no cover
ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
raise ex

parent._testcases[name] = self
Expand Down Expand Up @@ -483,7 +486,8 @@ def __init__(
if parent is not None:
if not isinstance(parent, TestsuiteBase):
ex = TypeError(f"Parameter 'parent' is not of type 'TestsuiteBase'.")
ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
if version_info >= (3, 11): # pragma: no cover
ex.add_note(f"Got type '{getFullyQualifiedName(parent)}'.")
raise ex

parent._testsuites[name] = self
Expand Down

0 comments on commit 287b01c

Please sign in to comment.