Skip to content

Commit

Permalink
unit tests and rename subpackage services -> service
Browse files Browse the repository at this point in the history
  • Loading branch information
mdabrowski1990 committed Dec 8, 2024
1 parent 5006b9f commit 3b8fb14
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 3 deletions.
Empty file.
60 changes: 60 additions & 0 deletions tests/software_tests/database/service/test_abstract_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pytest
from mock import Mock


from uds.database.service.abstract_service import AbstractService


class TestAbstractService:
"""Unit tests for Abstract Service."""

def setup_method(self):
self.mock_abstract_service = Mock(spec=AbstractService)

# encode

@pytest.mark.parametrize("sid, request_sid, response_sid", [
(1, 1, 2),
(0x11, 0x11, 0x51),
])
@pytest.mark.parametrize("data_records_values", [
{},
{"a": 1, "b": 2, "c": 3, "xyz": None}
])
def test_encode__request(self, sid, request_sid, response_sid, data_records_values):
self.mock_abstract_service.request_sid = request_sid
self.mock_abstract_service.response_sid = response_sid
assert (AbstractService.encode(self=self.mock_abstract_service, sid=sid, **data_records_values)
== self.mock_abstract_service.encode_request.return_value)
self.mock_abstract_service.encode_request.assert_called_once_with(**data_records_values)

@pytest.mark.parametrize("sid, request_sid, response_sid", [
(2, 1, 2),
(0x51, 0x11, 0x51),
])
@pytest.mark.parametrize("data_records_values", [
{},
{"a": 1, "b": 2, "c": 3, "xyz": None}
])
def test_encode__response(self, sid, request_sid, response_sid, data_records_values):
self.mock_abstract_service.request_sid = request_sid
self.mock_abstract_service.response_sid = response_sid
assert (AbstractService.encode(self=self.mock_abstract_service, sid=sid, **data_records_values)
== self.mock_abstract_service.encode_response.return_value)
self.mock_abstract_service.encode_response.assert_called_once_with(**data_records_values)

@pytest.mark.parametrize("sid, request_sid, response_sid", [
(0, 1, 2),
(0x11, 0x10, 0x50),
])
@pytest.mark.parametrize("data_records_values", [
{},
{"a": 1, "b": 2, "c": 3, "xyz": None}
])
def test_encode__value_error(self, sid, request_sid, response_sid, data_records_values):
self.mock_abstract_service.request_sid = request_sid
self.mock_abstract_service.response_sid = response_sid
with pytest.raises(ValueError):
AbstractService.encode(self=self.mock_abstract_service, sid=sid, **data_records_values)
self.mock_abstract_service.encode_request.asseert_not_called()
self.mock_abstract_service.encode_response.asseert_not_called()
3 changes: 2 additions & 1 deletion tests/software_tests/database/test_abstract_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

SCRIPT_LOCATION = "uds.database.abstract_database"


class TestAbstractDatabase:

def setup_method(self):
Expand Down Expand Up @@ -48,7 +49,7 @@ def test_encode(self, sid, data_records_values):
self.mock_database.services = {sid: mock_service}
assert (AbstractDatabase.encode(self.mock_database, sid=sid, **data_records_values)
== mock_service.encode.return_value)
mock_service.encode.assert_called_once_with(**data_records_values)
mock_service.encode.assert_called_once_with(sid=sid, **data_records_values)

# decode

Expand Down
2 changes: 1 addition & 1 deletion uds/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

from .abstract_database import AbstractDatabase
from .data_record import AbstractDataRecord, DecodedDataRecord, RawDataRecord
from .services import AbstractService
from .service import AbstractService
2 changes: 1 addition & 1 deletion uds/database/abstract_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from uds.utilities import RawBytesListAlias

from .data_record import DataRecordValueAlias, DecodedDataRecord
from .services import AbstractService
from .service import AbstractService


class AbstractDatabase(ABC):
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 3b8fb14

Please sign in to comment.