Skip to content

Commit

Permalink
Merge branch 'unit-test-marker' of https://github.com/bonicim/volttron
Browse files Browse the repository at this point in the history
…into bonicim-unit-test-marker
  • Loading branch information
craig8 committed Sep 26, 2020
2 parents 0479f0b + 0b94031 commit 764b15f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 154 deletions.
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ markers =
dbutils: test all the level one integrations tests for dbfuncts classes
mongoutils: level one integration tests for mongoutils
sqlitefuncts: level one integration tests for sqlitefuncts
unit: Run all unit/level one integration tests
14 changes: 1 addition & 13 deletions services/core/ActuatorAgent/tests/test_actuator_pubsub_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from volttrontesting.utils.utils import AgentMock
from volttron.platform.vip.agent import Agent

pytestmark = [pytest.mark.actuator_unit, pytest.mark.unit]

PEER = "peer-1"
SENDER = "sender-1"
Expand All @@ -65,7 +66,6 @@
ActuatorAgent.__bases__ = (AgentMock.imitate(Agent, Agent()),)


@pytest.mark.actuator_unit
def test_handle_get_should_succeed():
with get_actuator_agent() as actuator_agent:
actuator_agent.handle_get(PEER, SENDER, BUS, GET_TOPIC, HEADERS, MESSAGE)
Expand All @@ -74,7 +74,6 @@ def test_handle_get_should_succeed():
actuator_agent.vip.pubsub.publish.assert_called_once()


@pytest.mark.actuator_unit
def test_handle_get_should_handle_standard_error(caplog):
with get_actuator_agent(vip_identity=None) as actuator_agent:
actuator_agent.handle_get(PEER, SENDER, BUS, GET_TOPIC, HEADERS, MESSAGE)
Expand All @@ -88,7 +87,6 @@ def test_handle_get_should_handle_standard_error(caplog):
)


@pytest.mark.actuator_unit
@pytest.mark.parametrize(
"sender, device_state",
[
Expand All @@ -111,7 +109,6 @@ def test_handle_set_should_succeed(sender, device_state):
actuator_agent.vip.pubsub.publish.assert_called()


@pytest.mark.actuator_unit
def test_handle_set_should_return_none_on_none_message(caplog):
with get_actuator_agent(vip_identity=None) as actuator_agent:
result = actuator_agent.handle_set(PEER, SENDER, BUS, SET_TOPIC, HEADERS, None)
Expand All @@ -125,7 +122,6 @@ def test_handle_set_should_return_none_on_none_message(caplog):
)


@pytest.mark.actuator_unit
def test_handle_set_should_handle_type_error_on_invalid_sender(caplog):
with get_actuator_agent(vip_identity=None) as actuator_agent:
actuator_agent.handle_set(PEER, None, BUS, SET_TOPIC, HEADERS, MESSAGE)
Expand All @@ -138,7 +134,6 @@ def test_handle_set_should_handle_type_error_on_invalid_sender(caplog):
)


@pytest.mark.actuator_unit
def test_handle_set_should_handle_lock_error(caplog):
with get_actuator_agent(vip_identity=None) as actuator_agent:
actuator_agent.handle_set(PEER, SENDER, BUS, SET_TOPIC, HEADERS, MESSAGE)
Expand All @@ -151,7 +146,6 @@ def test_handle_set_should_handle_lock_error(caplog):
)


@pytest.mark.actuator_unit
def test_handle_revert_point_should_succeed():
device_state = {
"actuators/revert/point/somedevicepath": DeviceState(
Expand All @@ -168,7 +162,6 @@ def test_handle_revert_point_should_succeed():
actuator_agent.vip.pubsub.publish.assert_called_once()


@pytest.mark.actuator_unit
def test_handle_revert_point_should_handle_lock_error(caplog):
with get_actuator_agent(vip_identity=None) as actuator_agent:
actuator_agent.handle_revert_point(
Expand All @@ -183,7 +176,6 @@ def test_handle_revert_point_should_handle_lock_error(caplog):
)


@pytest.mark.actuator_unit
def test_handle_revert_device_should_succeed():
device_state = {
"somedevicepath": DeviceState("sender-1", "task-id-1", "anytime")
Expand All @@ -199,7 +191,6 @@ def test_handle_revert_device_should_succeed():
actuator_agent.vip.pubsub.publish.assert_called_once()


@pytest.mark.actuator_unit
def test_handle_revert_device_should_handle_lock_error(caplog):
with get_actuator_agent(vip_identity=None) as actuator_agent:
actuator_agent.handle_revert_device(
Expand All @@ -214,7 +205,6 @@ def test_handle_revert_device_should_handle_lock_error(caplog):
)


@pytest.mark.actuator_unit
@pytest.mark.parametrize(
"priority, success",
[
Expand Down Expand Up @@ -244,7 +234,6 @@ def test_handle_schedule_request_should_succeed_on_new_schedule_request_type(
actuator_agent.vip.pubsub.publish.assert_called()


@pytest.mark.actuator_unit
@pytest.mark.parametrize("success", [True, False])
def test_handle_schedule_request_should_succeed_on_cancel_schedule_request_type(success):
headers = {"type": "CANCEL_SCHEDULE", "requesterID": "id-123", "taskID": "12345"}
Expand All @@ -257,7 +246,6 @@ def test_handle_schedule_request_should_succeed_on_cancel_schedule_request_type(
actuator_agent.vip.pubsub.publish.assert_called()


@pytest.mark.actuator_unit
@pytest.mark.parametrize("invalid_request_type", ["bad request type", None])
def test_handle_schedule_request_should_log_invalid_request_type(
invalid_request_type, caplog
Expand Down
24 changes: 1 addition & 23 deletions services/core/ActuatorAgent/tests/test_actuator_rpc_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from volttrontesting.utils.utils import AgentMock
from volttron.platform.vip.agent import Agent

pytestmark = [pytest.mark.actuator_unit, pytest.mark.unit]

PRIORITY_LOW = "LOW"
SUCCESS = "SUCCESS"
Expand All @@ -66,7 +67,6 @@
ActuatorAgent.__bases__ = (AgentMock.imitate(Agent, Agent()),)


@pytest.mark.actuator_unit
@pytest.mark.parametrize("topic, point", [("path/topic", None), ("another/path/to/topic", 42)])
def test_get_point_should_succeed(topic, point):
with get_actuator_agent(vip_rpc_call_res=MockedAsyncResult(10.0)) as actuator_agent:
Expand All @@ -76,7 +76,6 @@ def test_get_point_should_succeed(topic, point):
assert result is not None


@pytest.mark.actuator_unit
@pytest.mark.parametrize(
"point, device_state",
[
Expand All @@ -101,7 +100,6 @@ def test_set_point_should_succeed(point, device_state):
assert result is not None


@pytest.mark.actuator_unit
@pytest.mark.parametrize("rpc_peer", [None, 42, []])
def test_set_point_should_raise_type_error(rpc_peer):
with pytest.raises(TypeError, match="Agent id must be a nonempty string"):
Expand All @@ -114,7 +112,6 @@ def test_set_point_should_raise_type_error(rpc_peer):
actuator_agent.set_point(requester_id, topic, value, point=point)


@pytest.mark.actuator_unit
def test_set_point_should_raise_lock_error_on_non_matching_device():
with pytest.raises(LockError):
requester_id = "requester-id-1"
Expand All @@ -125,7 +122,6 @@ def test_set_point_should_raise_lock_error_on_non_matching_device():
actuator_agent.set_point(requester_id, topic, value)


@pytest.mark.actuator_unit
def test_scrape_all_should_succeed():
with get_actuator_agent(vip_rpc_call_res=MockedAsyncResult({})) as actuator_agent:
topic = "whan/that/aprille"
Expand All @@ -136,7 +132,6 @@ def test_scrape_all_should_succeed():



@pytest.mark.actuator_unit
@pytest.mark.parametrize(
"topics",
[
Expand All @@ -156,7 +151,6 @@ def test_get_multiple_points_should_succeed(topics):
assert len(errors) == 0


@pytest.mark.actuator_unit
@pytest.mark.parametrize("invalid_topics", [[(123,)], [(None)], [[123]], [[None]]])
def test_get_multiple_points_should_return_errors(invalid_topics):
with get_actuator_agent() as actuator_agent:
Expand All @@ -168,7 +162,6 @@ def test_get_multiple_points_should_return_errors(invalid_topics):
assert len(errors) == 1


@pytest.mark.actuator_unit
@pytest.mark.parametrize(
"topic_values, device_state",
[
Expand All @@ -186,7 +179,6 @@ def test_get_multiple_points_should_return_errors(invalid_topics):
),
],
)
@pytest.mark.actuator_unit
def test_set_multiple_points_should_succeed(topic_values, device_state):
requester_id = "requester-id-1"
mocked_rpc_call_res = MockedAsyncResult(({}))
Expand All @@ -197,7 +189,6 @@ def test_set_multiple_points_should_succeed(topic_values, device_state):
assert result == {}


@pytest.mark.actuator_unit
@pytest.mark.parametrize("invalid_topic_values", [[(None,)], [(1234,)]])
def test_set_multiple_points_should_raise_value_error(invalid_topic_values):
with pytest.raises(ValueError):
Expand All @@ -207,7 +198,6 @@ def test_set_multiple_points_should_raise_value_error(invalid_topic_values):
actuator_agent.set_multiple_points("request-id-1", invalid_topic_values)


@pytest.mark.actuator_unit
def test_set_multiple_points_should_raise_lock_error_on_empty_devices():
with pytest.raises(LockError):
requester_id = "requester-id-1"
Expand All @@ -217,7 +207,6 @@ def test_set_multiple_points_should_raise_lock_error_on_empty_devices():
actuator_agent.set_multiple_points("request-id-1", topic_values)


@pytest.mark.actuator_unit
def test_set_multiple_points_should_raise_lock_error_on_non_matching_requester():
with pytest.raises(LockError):
requester_id = "wrong-requester"
Expand All @@ -231,7 +220,6 @@ def test_set_multiple_points_should_raise_lock_error_on_non_matching_requester()
actuator_agent.set_multiple_points("request-id-1", topic_values)


@pytest.mark.actuator_unit
@pytest.mark.parametrize("point", [None, "foobarpoint"])
def test_revert_point_should_raise_lock_error_on_empty_devices(point):
with pytest.raises(LockError):
Expand All @@ -242,7 +230,6 @@ def test_revert_point_should_raise_lock_error_on_empty_devices(point):
actuator_agent.revert_point(requester_id, topic, point=point)


@pytest.mark.actuator_unit
@pytest.mark.parametrize("point", [None, "foobarpoint"])
def test_revert_point_should_raise_lock_error_on_non_matching_requester(point):
with pytest.raises(LockError):
Expand All @@ -257,7 +244,6 @@ def test_revert_point_should_raise_lock_error_on_non_matching_requester(point):
actuator_agent.revert_point(requester_id, topic, point=point)


@pytest.mark.actuator_unit
def test_revert_device_should_raise_lock_error_on_empty_devices():
with pytest.raises(LockError):
requester_id = "request-id-1"
Expand All @@ -267,7 +253,6 @@ def test_revert_device_should_raise_lock_error_on_empty_devices():
actuator_agent.revert_device(requester_id, topic)


@pytest.mark.actuator_unit
def test_revert_device_should_raise_lock_error_on_non_matching_requester():
with pytest.raises(LockError):
device_state = {
Expand All @@ -281,7 +266,6 @@ def test_revert_device_should_raise_lock_error_on_non_matching_requester():
actuator_agent.revert_device(requester_id, topic)


@pytest.mark.actuator_unit
def test_request_new_schedule_should_succeed():
with get_actuator_agent() as actuator_agent:
result = actuator_agent.request_new_schedule(REQUESTER_ID, TASK_ID,
Expand All @@ -290,7 +274,6 @@ def test_request_new_schedule_should_succeed():
assert result["result"] == SUCCESS


@pytest.mark.actuator_unit
def test_request_new_schedule_should_succeed_when_stop_start_times_overlap():
start = str(datetime.now())
end = str(datetime.now() + timedelta(seconds=1))
Expand All @@ -304,7 +287,6 @@ def test_request_new_schedule_should_succeed_when_stop_start_times_overlap():
assert result["result"] == SUCCESS


@pytest.mark.actuator_unit
@pytest.mark.parametrize(
"task_id, expected_info",
[
Expand All @@ -325,7 +307,6 @@ def test_request_new_schedule_should_fail_on_invalid_taskid(task_id, expected_in
assert result["info"] == expected_info


@pytest.mark.actuator_unit
@pytest.mark.parametrize(
"invalid_priority, expected_info",
[("LOW2", "INVALID_PRIORITY"), (None, "MISSING_PRIORITY")],
Expand All @@ -341,7 +322,6 @@ def test_request_new_schedule_should_fail_on_invalid_priority(invalid_priority,
assert result["info"] == expected_info


@pytest.mark.actuator_unit
@pytest.mark.parametrize(
"time_slot_request, expected_info",
[
Expand Down Expand Up @@ -372,7 +352,6 @@ def test_request_new_schedule_should_fail_invalid_time_slot_requests(time_slot_r
assert result["info"] == expected_info


@pytest.mark.actuator_unit
def test_request_cancel_schedule_should_succeed_happy_path():
true_request_result = RequestResult(
True, {}, ""
Expand All @@ -384,7 +363,6 @@ def test_request_cancel_schedule_should_succeed_happy_path():
assert result["result"] == SUCCESS


@pytest.mark.actuator_unit
def test_request_cancel_schedule_should_fail_on_invalid_task_id():
false_request_result = RequestResult(
False, {}, "TASK_ID_DOES_NOT_EXIST"
Expand Down
Loading

0 comments on commit 764b15f

Please sign in to comment.