Skip to content
Snippets Groups Projects
Commit 0e85a890 authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

L2SS-404: add unittests for archiving util functions

parent bd8dea28
No related branches found
No related tags found
1 merge request!253Resolve L2SS-404 "Archiving setup development"
# -*- coding: utf-8 -*-
#
# This file is part of the LOFAR 2.0 Station Software
#
#
#
# Distributed under the terms of the APACHE license.
# See LICENSE.txt for more info.
from tangostationcontrol.test import base
from tangostationcontrol.toolkit.archiver_util import device_fqdn, attribute_fqdn, get_parameters_from_attribute
import json
import pkg_resources
class TestArchiverUtil(base.TestCase):
device_name = 'STAT/RECV/1'
attribute_name = 'ant_mask_rw'
suffixes = ["_error_R","_good_R","_mask_RW","_version_R"]
config_dict = json.load(pkg_resources.resource_stream('tangostationcontrol.toolkit', f'archiver_config/lofar2.json'))
def test_device_fqdn(self):
"""Test if a device name is correctly converted in a Tango FQDN"""
self.assertEqual(f"tango://databaseds:10000/{self.device_name}".lower(), device_fqdn(self.device_name))
def test_attribute_fqdn(self):
"""Test if an attribute name is correctly converted in a Tango FQDN"""
self.assertEqual(f"tango://databaseds:10000/{self.device_name}/{self.attribute_name}".lower(),
attribute_fqdn(f"{self.device_name}/{self.attribute_name}"))
self.assertRaises(ValueError, lambda: attribute_fqdn(self.attribute_name))
def test_get_parameters_from_attribute(self):
"""Test if the attribute archiving parameters are correctly retrieved from the JSON config file"""
self.assertIsNotNone(self.config_dict)
suffixes = self.config_dict.get('_global_suffixes')
archive_period, event_period, abs_change, rel_change = get_parameters_from_attribute(self.device_name, self.attribute_name,
suffixes, self.config_dict)
self.assertEqual(archive_period,int(suffixes[2].get('archive_period')))
self.assertEqual(event_period,int(suffixes[2].get('event_period')))
self.assertEqual(abs_change,int(suffixes[2].get('abs_change')))
self.assertEqual(rel_change,suffixes[2].get('rel_change'))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment