Exemple #1
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)
Exemple #2
0
def test_assign_resources_request_for_low_eq():
    """
    Verify that two AssignResource request objects for the same sub-array and
    mccs allocation are considered equal.
    """
    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])
    request = AssignResourcesRequest(
        interface='https://schema.skatelescope.org/'
        'ska-low-tmc-assignresources/1.0',
        mccs=mccs_allocate,
        subarray_id=1)
    assert request == AssignResourcesRequest(
        interface='https://schema.skatelescope.org/'
        'ska-low-tmc-assignresources/1.0',
        mccs=mccs_allocate,
        subarray_id=1)
    assert request != AssignResourcesRequest(
        mccs=MCCSAllocate(list(zip(itertools.count(1, 1), 1 * [1])),
                          [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9]),
        interface=
        'https://schema.skatelescope.org/ska-low-tmc-assignresources/1.0',
        subarray_id=2)
    assert request != AssignResourcesRequest(
        mccs=MCCSAllocate(list(zip(itertools.count(1, 1), 1 * [2])), [3, 4, 5],
                          [1, 2, 3, 4, 5, 6]),
        subarray_id=2,
        interface=
        'https://schema.skatelescope.org/ska-low-tmc-assignresources/2.0',
    )
Exemple #3
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)
Exemple #4
0
def test_assign_resources_request_mccs_eq():
    """
    Verify that two AssignResource request objects for the same sub-array and
    mccs allocation are considered equal.
    """
    mccs = MCCSAllocate(subarray_beam_ids=[1],
                        station_ids=[(1, 2)],
                        channel_blocks=[3])
    request = AssignResourcesRequest(subarray_id=1, mccs=mccs)
    assert request == AssignResourcesRequest(subarray_id=1, mccs=mccs)
    assert request != AssignResourcesRequest(subarray_id=2, mccs=mccs)

    o = copy.deepcopy(mccs)
    o.subarray_beam_ids = [2]
    assert request != AssignResourcesRequest(subarray_id=1, mccs=o)
    def create_request(self, data, **_):  # pylint: disable=no-self-use
        """
        Convert parsed JSON back into an AssignResources request object.

        :param data: Marshmallow-provided dict containing parsed JSON values
        :param _: kwargs passed by Marshmallow
        :return: AssignResources object populated from data
        """
        interface = data.get("interface", None)
        subarray_id = data.get("subarray_id", None)
        subarray_id_mid = data.get("subarray_id_mid", None)
        dish_allocation = data.get("dish", None)
        sdp_config = data.get("sdp_config", None)
        mccs = data.get("mccs", None)

        is_low = subarray_id is not None and interface is not None

        if not is_low:
            subarray_id = subarray_id_mid

        return AssignResourcesRequest(interface=interface,
                                      subarray_id=subarray_id,
                                      dish_allocation=dish_allocation,
                                      sdp_config=sdp_config,
                                      mccs=mccs)
Exemple #6
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)
Exemple #7
0
def test_assign_resources_request_eq_mccs_with_other_objects():
    """
    Verify that an AssignResources request object is not considered equal to
    objects of other types.
    """
    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])
    request = AssignResourcesRequest(subarray_id=1, mccs=mccs_allocate)
    assert request != 1
    assert request != object()
Exemple #8
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)
Exemple #9
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()
Exemple #10
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)
Exemple #11
0
def test_assign_resources_request_from_mccs():
    """
    Verify that two AssignResource request objects for the same sub-array and
    mccs allocation are considered equal.
    """
    mccs_allocate = MCCSAllocate(list(zip(itertools.count(1, 1), 1 * [2])),
                                 [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6])
    request = AssignResourcesRequest.from_mccs(subarray_id=1,
                                               mccs=mccs_allocate)

    expected = AssignResourcesRequest(
        subarray_id=1,
        mccs=MCCSAllocate(list(zip(itertools.count(1, 1), 1 * [2])),
                          [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6]),
    )
    assert request == expected
Exemple #12
0
            parameters={},
            dependencies=[
                PbDependency("pb-mvp01-20200325-00003", ["calibration"])
            ])
    ])

VALID_MID_ASSIGNRESOURCESREQUEST_JSON = """
{
  "subarrayID": 1,
  "dish": {"receptorIDList": ["0001", "0002"]},
  "sdp": """ + VALID_SDP_JSON + """
}
"""

VALID_MID_ASSIGNRESOURCESREQUEST_OBJECT = AssignResourcesRequest(
    subarray_id=1,
    dish_allocation=DishAllocation(receptor_ids=["0001", "0002"]),
    sdp_config=VALID_SDP_OBJECT)

VALID_LOW_ASSIGNRESOURCESREQUEST_JSON = """
{
  "interface": "https://schema.skatelescope.org/ska-low-tmc-assignresources/1.0",
  "subarray_id": 1,
  "mccs": {
    "subarray_beam_ids": [1],
    "station_ids": [[1, 2]],
    "channel_blocks": [1, 2, 3, 4, 5]
  }
}
"""

VALID_LOW_ASSIGNRESOURCESREQUEST_OBJECT = AssignResourcesRequest(