Commit 0004787f authored by Jorrit Schaap's avatar Jorrit Schaap

TMSS-153: initial test and adapater from subtask to parset. (not complete yet)

parent 01f4b4f5
lofar_package(TMSS 0.1 DEPENDS PyCommon)
lofar_package(TMSS 0.1 DEPENDS PyCommon pyparameterset)
add_subdirectory(src)
add_subdirectory(bin)
......
......@@ -17,3 +17,4 @@ add_subdirectory(migrations)
add_subdirectory(models)
add_subdirectory(serializers)
add_subdirectory(viewsets)
add_subdirectory(adapters)
include(PythonInstall)
set(_py_files
parset.py
)
python_install(${_py_files}
DESTINATION lofar/sas/tmss/tmss/tmssapp/adapters)
\ No newline at end of file
#!/usr/bin/python3
# Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
from lofar.sas.tmss.test.tmss_test_environment_unittest_setup import *
from lofar.sas.tmss.tmss.tmssapp.models.scheduling import Subtask
from lofar.parameterset import parameterset
from lofar.common.datetimeutils import formatDatetime
def convert_to_parset(subtask: Subtask) -> parameterset:
print(subtask.specifications_doc)
parset = dict() # parameterset has no proper assignment operators, so take detour via dict...
parset["Observation.startTime"] = formatDatetime(subtask.start_time)
parset["Observation.stopTime"] = formatDatetime(subtask.stop_time)
parset["Observation.antennaSet"] = subtask.specifications_doc["stations"]["antenna_set"]
parset["Observation.VirtualInstrument.stationList"] = subtask.specifications_doc["stations"]["station_list"]
parset["Observation.bandFilter"] = subtask.specifications_doc["stations"]["filter"]
parset["Observation.sampleClock"] = 200
parset["Observation.nrBitsPerSample"] = 8
# convert dict to real parameterset, and return it
parset = parameterset(parset)
print(parset)
return parset
#!/usr/bin/env python3
# Copyright (C) 2018 ASTRON (Netherlands Institute for Radio Astronomy)
# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
# $Id: $
import os
import unittest
import requests
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
# Do Mandatory setup step:
# use setup/teardown magic for tmss test database, ldap server and django server
# (ignore pycharm unused import statement, python unittests does use at RunTime the tmss_test_environment_unittest_setup module)
from lofar.sas.tmss.test.tmss_test_environment_unittest_setup import *
from lofar.sas.tmss.test.tmss_test_data_django_models import *
# import and setup rest test data creator
from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator
rest_data_creator = TMSSRESTTestDataCreator(BASE_URL, AUTH)
from lofar.sas.tmss.tmss.tmssapp import models
from lofar.sas.tmss.tmss.tmssapp.adapters.parset import convert_to_parset
from lofar.common.json_utils import get_default_json_object_for_schema
class ParsetAdapterTest(unittest.TestCase):
def test_01(self):
subtask_template = models.SubtaskTemplate.objects.get(name='obscontrol schema')
specifications_doc = get_default_json_object_for_schema(subtask_template.schema)
subtask_data = Subtask_test_data(subtask_template, specifications_doc)
subtask = models.Subtask.objects.create(**subtask_data)
parset = convert_to_parset(subtask)
if __name__ == "__main__":
os.environ['TZ'] = 'UTC'
unittest.main()
#!/bin/bash
# Run the unit test
source python-coverage.sh
python_coverage_test "*tmss*" t_parset_adapter.py
#!/bin/sh
./runctest.sh t_parset_adapter
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment