def test_dish_allocation_eq():
    """
    Verify that two DishAllocations with the same allocated receptors are
    considered equal.
    """
    dish_allocation = DishAllocation(receptor_ids=['ac', 'b', 'aab'])
    assert dish_allocation == DishAllocation(receptor_ids=['ac', 'b', 'aab'])
    assert dish_allocation == DishAllocation(receptor_ids=['b', 'ac', 'aab'])
    assert dish_allocation != DishAllocation(receptor_ids=['ac'])
    assert dish_allocation != DishAllocation(
        receptor_ids=['ac', 'b', 'aab', 'd'])
示例#2
0
def test_assign_resources_response_eq():
    """
    Verify that two AssignResource response objects with the same successful
    dish allocation are considered equal.
    """
    dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])
    unequal_allocation = DishAllocation(receptor_ids=["b", "aab"])
    response = AssignResourcesResponse(dish_allocation=dish_allocation)

    assert response == AssignResourcesResponse(dish_allocation=dish_allocation)
    assert response != AssignResourcesResponse(
        dish_allocation=DishAllocation())
    assert response != AssignResourcesResponse(
        dish_allocation=unequal_allocation)
示例#3
0
def test_assign_resources_request_eq():
    """
    Verify that two AssignResource request objects for the same sub-array and
    dish allocation are considered equal.
    """
    channel = Channel(744, 0, 2, 0.35e9, 0.368e9,
                      [[0, 0], [200, 1], [744, 2], [944, 3]])
    scan_type = ScanType("science_A", "ICRS", "02:42:40.771", "-00:00:47.84",
                         [channel])
    sdp_workflow = SDPWorkflow(workflow_id="vis_receive",
                               workflow_type="realtime",
                               version="0.1.0")
    pb_config = ProcessingBlockConfiguration("pb-mvp01-20200325-00001",
                                             sdp_workflow, {})
    sdp_config = SDPConfiguration("sbi-mvp01-20200325-00001", 100.0,
                                  [scan_type], [pb_config])
    dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])
    request = AssignResourcesRequest(1,
                                     dish_allocation=dish_allocation,
                                     sdp_config=sdp_config)

    assert request == AssignResourcesRequest(1,
                                             dish_allocation=dish_allocation,
                                             sdp_config=sdp_config)

    assert request != AssignResourcesRequest(
        1, dish_allocation=dish_allocation, sdp_config=None)
    assert request != AssignResourcesRequest(
        1, dish_allocation=None, sdp_config=None)
    assert request != AssignResourcesRequest(
        1, dish_allocation=None, sdp_config=sdp_config)
def test_dish_allocation_repr():
    """
    Verify that the DishAllocation repr is formatted correctly.
    """
    dish_allocation = DishAllocation(receptor_ids=['ac', 'b', 'aab'])
    assert repr(
        dish_allocation) == "<DishAllocation(receptor_ids=['ac', 'b', 'aab'])>"
def test_dish_allocation_eq_with_other_objects():
    """
    Verify that a DishAllocation is considered unequal to objects of other
    types.
    """
    dish_allocation = DishAllocation(receptor_ids=['ac', 'b', 'aab'])
    assert dish_allocation != 1
    assert dish_allocation != object()
示例#6
0
def test_assign_resources_response_eq_with_other_objects():
    """
    Verify that an AssignResourcesRequest response object is not considered equal to
    objects of other types.
    """
    dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])
    response = AssignResourcesResponse(dish_allocation=dish_allocation)
    assert response != 1
    assert response != object()
def test_release_resources_request_eq():
    """
    Verify that two ReleaseResource requests for the same sub-array and
    dish allocation are considered equal.
    """
    dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])
    request = ReleaseResourcesRequest(subarray_id=1,
                                      dish_allocation=dish_allocation,
                                      release_all=False)

    assert request == ReleaseResourcesRequest(subarray_id=1,
                                              dish_allocation=dish_allocation)
    assert request != ReleaseResourcesRequest(subarray_id=1,
                                              dish_allocation=DishAllocation())
    assert request != ReleaseResourcesRequest(subarray_id=2,
                                              dish_allocation=dish_allocation)
    assert request != ReleaseResourcesRequest(
        subarray_id=1, dish_allocation=dish_allocation, release_all=True)
示例#8
0
    def create(self, data, **_):  # pylint: disable=no-self-use
        """
        Convert parsed JSON back into a DishAllocation object.

        :param data: Marshmallow-provided dict containing parsed JSON values
        :param _: kwargs passed by Marshmallow
        :return: DishAllocation object populated from data
        """
        receptor_ids = data["receptor_ids"]
        return DishAllocation(receptor_ids=receptor_ids)
def test_release_resources_request_eq_with_other_objects():
    """
    Verify that a ReleaseResources request object is not considered equal to
    objects of other types.
    """
    dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])
    request = ReleaseResourcesRequest(subarray_id=1,
                                      dish_allocation=dish_allocation)
    assert request != 1
    assert request != object()
示例#10
0
def test_assign_resources_request_from_dish():
    """
    Verify that two AssignResource request objects for the same sub-array and
    dish allocation are considered equal.
    """
    dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])
    request = AssignResourcesRequest.from_dish(1,
                                               dish_allocation=dish_allocation)
    assert request == AssignResourcesRequest(1,
                                             dish_allocation=dish_allocation)
示例#11
0
def test_assign_resources_request_eq_with_other_objects():
    """
    Verify that an AssignResources request object is not considered equal to
    objects of other types.
    """
    dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])
    request = AssignResourcesRequest(1,
                                     dish_allocation=dish_allocation,
                                     sdp_config=None)
    assert request != 1
    assert request != object()
示例#12
0
def test_assign_resources_request_dish_and_mccs_fail():
    """
    Verify that mccs & dish cannot be allocated together
    """
    mccs_allocate = MCCSAllocate(list(zip(itertools.count(1, 1), 1 * [2])),
                                 [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9])

    with pytest.raises(ValueError):
        dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])
        AssignResourcesRequest(dish_allocation=dish_allocation,
                               mccs=mccs_allocate)
示例#13
0
def test_codec_dumps():
    """
    Verify that the codec marshalls dish & sdp objects to JSON.
    """
    sdp_config = VALID_SDP_OBJECT
    expected = VALID_MID_ASSIGNRESOURCESREQUEST_JSON
    obj = AssignResourcesRequest(
        subarray_id=1,
        dish_allocation=DishAllocation(receptor_ids=["0001", "0002"]),
        sdp_config=sdp_config)

    marshalled = CODEC.dumps(obj)
    assert json_is_equal(marshalled, expected)
示例#14
0
def test_codec_loads():
    """
    Verify that the codec unmarshalls objects correctly.
    """
    sdp_config = VALID_SDP_OBJECT
    unmarshalled = CODEC.loads(AssignResourcesRequest,
                               VALID_MID_ASSIGNRESOURCESREQUEST_JSON)
    expected = AssignResourcesRequest.from_dish(
        1,
        DishAllocation(receptor_ids=["0001", "0002"]),
        sdp_config=sdp_config,
    )
    assert expected == unmarshalled
示例#15
0
def test_assign_resources_if_no_subarray_id_argument():
    """
    Verify that the boolean release_all_mid argument is required.
    """
    mccs = MCCSAllocate(list(zip(itertools.count(1, 1), 1 * [2])),
                        [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9])
    dish_allocation = DishAllocation(receptor_ids=["ac", "b", "aab"])

    with pytest.raises(ValueError):
        _ = AssignResourcesRequest(mccs=mccs)

    with pytest.raises(ValueError):
        _ = AssignResourcesRequest(dish_allocation=dish_allocation)
示例#16
0
    def create(self, data, **_):  # pylint: disable=no-self-use
        """
        Convert parsed JSON from an AssignResources response back into a
        DishAllocation object.

        This 'duplicate' schema is required as the DishAllocation is found
        under a different JSON key in the response as compared to the request.

        :param data: Marshmallow-provided dict containing parsed JSON values
        :param _: kwargs passed by Marshmallow
        :return: DishAllocation object populated from data
        """
        receptor_ids = data["receptor_ids"]
        return DishAllocation(receptor_ids=receptor_ids)
def test_deallocate_resources_enforces_boolean_release_all_argument():
    """
    Verify that the boolean release_all_mid argument is required.
    """
    with pytest.raises(ValueError):
        _ = ReleaseResourcesRequest(subarray_id=1, release_all=1)

    dish_allocation = DishAllocation(receptor_ids=["0001", "0002"])
    with pytest.raises(ValueError):
        _ = ReleaseResourcesRequest(subarray_id=1,
                                    release_all=1,
                                    dish_allocation=dish_allocation)

    # If release_all is not set as boolean for Low
    with pytest.raises(ValueError):
        _ = ReleaseResourcesRequest(subarray_id=1, release_all=1)
from ska_tmc_cdm.messages.central_node.common import DishAllocation
from ska_tmc_cdm.messages.central_node.release_resources import ReleaseResourcesRequest
from ska_tmc_cdm.schemas.central_node.release_resources import ReleaseResourcesRequestSchema
from .. import utils

VALID_MID_PARTIAL_RELEASE_JSON = """
{
     "subarrayID": 1,
     "dish": {"receptorIDList": ["0001", "0002"]}
}
"""

VALID_MID_PARTIAL_RELEASE_OBJECT = ReleaseResourcesRequest(
    subarray_id=1,
    dish_allocation=DishAllocation(receptor_ids=["0001", "0002"]))

VALID_MID_FULL_RELEASE_JSON = """
{
    "subarrayID": 1,
    "releaseALL": true
}
"""

VALID_MID_FULL_RELEASE_OBJECT = ReleaseResourcesRequest(subarray_id=1,
                                                        release_all=True)

# mixed partial / full request, used to test which params are ignored
VALID_MID_MIXED_ARGS_OBJECT = ReleaseResourcesRequest(
    subarray_id=1,
    release_all=True,