Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions python/src/etos_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""ETOS API module."""

import os
from importlib.metadata import PackageNotFoundError, version
from importlib.metadata import PackageNotFoundError, version as _version

from etos_lib.logging.logger import setup_logging
from opentelemetry import trace
Expand All @@ -42,17 +43,17 @@
os.environ["ETOS_ENABLE_SENDING_LOGS"] = "false"

try:
VERSION = version("etos_api")
version = _version("etos_api")
except PackageNotFoundError:
VERSION = "Unknown"
version = "Unknown"

DEV = os.getenv("DEV", "false").lower() == "true"

if os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT"):
OTEL_RESOURCE = Resource.create(
{
SERVICE_NAME: "etos-api",
SERVICE_VERSION: VERSION,
SERVICE_VERSION: version,
},
)

Expand All @@ -65,10 +66,10 @@
PROCESSOR = BatchSpanProcessor(EXPORTER)
PROVIDER.add_span_processor(PROCESSOR)
trace.set_tracer_provider(PROVIDER)
setup_logging("ETOS API", VERSION, otel_resource=OTEL_RESOURCE)
setup_logging("ETOS API", version, otel_resource=OTEL_RESOURCE)

FastAPIInstrumentor().instrument_app(APP, tracer_provider=PROVIDER, excluded_urls=".*/ping")
else:
setup_logging("ETOS API", VERSION)
setup_logging("ETOS API", version)

RegisterProviders()
5 changes: 4 additions & 1 deletion python/src/etos_api/library/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ async def validate(self, test_suite):
"""
for suite_json in test_suite:
test_runners = set()
suite = Suite(**suite_json)
try:
suite = Suite(**suite_json)
except ValidationError as exception:
raise AssertionError("Not a valid test suite was provided") from exception
assert suite

for recipe in suite.recipes:
Expand Down
29 changes: 15 additions & 14 deletions python/tests/library/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for the validator library."""

import logging
import sys
from unittest.mock import patch

import pytest

from etos_api.library.validator import SuiteValidator, ValidationError
from etos_api.library.validator import SuiteValidator

logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)

Expand Down Expand Up @@ -75,7 +76,7 @@ async def test_validate_proper_suite(self, digest_mock):
try:
await validator.validate(test_suite)
exception = False
except (AssertionError, ValidationError):
except (AssertionError, AssertionError):
exception = True
self.logger.info("STEP: Verify that no exceptions were raised.")
assert exception is False
Expand All @@ -88,7 +89,7 @@ async def test_validate_missing_constraints(self):

Test steps::
1. Validate a suite with a missing constraint.
2. Verify that the validator raises ValidationError.
2. Verify that the validator raises AssertionError.
"""
test_suite = [
{
Expand Down Expand Up @@ -118,9 +119,9 @@ async def test_validate_missing_constraints(self):
try:
await validator.validate(test_suite)
exception = False
except ValidationError:
except AssertionError:
exception = True
self.logger.info("STEP: Verify that the validator raises ValidationError.")
self.logger.info("STEP: Verify that the validator raises AssertionError.")
assert exception is True

async def test_validate_wrong_types(self):
Expand All @@ -132,7 +133,7 @@ async def test_validate_wrong_types(self):
Test steps::
1. For each constraint.
1. Validate constraint with wrong type.
2. Verify that the validator raises ValidationError.
2. Verify that the validator raises AssertionError.
"""
base_suite = {
"name": "TestValidator",
Expand Down Expand Up @@ -204,8 +205,8 @@ async def test_validate_wrong_types(self):
for constraint in constraints:
self.logger.info("STEP: Validate constraint with wrong type.")
base_suite["recipes"][0]["constraints"] = constraint
self.logger.info("STEP: Verify that the validator raises ValidationError.")
with pytest.raises(ValidationError):
self.logger.info("STEP: Verify that the validator raises AssertionError.")
with pytest.raises(AssertionError):
await validator.validate([base_suite])

async def test_validate_too_many_constraints(self):
Expand All @@ -216,7 +217,7 @@ async def test_validate_too_many_constraints(self):

Test steps::
1. Validate a suite with a constraint defined multiple times.
2. Verify that the validator raises ValidationError.
2. Verify that the validator raises AssertionError.
"""
test_suite = [
{
Expand Down Expand Up @@ -248,9 +249,9 @@ async def test_validate_too_many_constraints(self):
try:
await validator.validate(test_suite)
exception = False
except ValidationError:
except AssertionError:
exception = True
self.logger.info("STEP: Verify that the validator raises ValidationError.")
self.logger.info("STEP: Verify that the validator raises AssertionError.")
assert exception is True

async def test_validate_unknown_constraint(self):
Expand All @@ -261,7 +262,7 @@ async def test_validate_unknown_constraint(self):

Test steps::
1. Validate a suite with an unknown constraint.
2. Verify that the validator raises ValidationError.
2. Verify that the validator raises AssertionError.
"""
test_suite = [
{
Expand Down Expand Up @@ -295,7 +296,7 @@ async def test_validate_unknown_constraint(self):
exception = False
except TypeError:
exception = True
self.logger.info("STEP: Verify that the validator raises ValidationError.")
self.logger.info("STEP: Verify that the validator raises AssertionError.")
assert exception is True

async def test_validate_empty_constraints(self):
Expand Down Expand Up @@ -354,5 +355,5 @@ async def test_validate_empty_constraints(self):
for constraint in constraints:
base_suite["recipes"][0]["constraints"] = constraint
self.logger.info("STEP: Validate a suite without the required key.")
with pytest.raises(ValidationError):
with pytest.raises(AssertionError):
await validator.validate([base_suite])
4 changes: 2 additions & 2 deletions python/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ commands =
deps =
black
commands =
black --check --diff -l 100 .
black --check --diff -l 100 src tests

[testenv:pylint]
deps =
Expand All @@ -36,4 +36,4 @@ deps =
pydocstyle
tomli
commands =
pydocstyle .
pydocstyle src tests
Loading