Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for scada interface #877

Merged
merged 9 commits into from
Jan 14, 2022
67 changes: 67 additions & 0 deletions tests/test_scada.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
import pytz
import numpy as np
import straxen
import unittest
Expand All @@ -14,6 +16,71 @@ def setUp(self):
self.start += 10**6
self.end = self.start + 5*10**9

def test_wrong_querries(self):
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
parameters = {'SomeParameter': 'XE1T.CTPC.Board06.Chan011.VMon'}

with self.assertRaises(ValueError):
# Runid but no context
df = self.sc.get_scada_values(parameters,
run_id='1',
every_nth_value=1,
query_type_lab=False, )

with self.assertRaises(ValueError):
# No time range specified
df = self.sc.get_scada_values(parameters,
every_nth_value=1,
query_type_lab=False, )

with self.assertRaises(ValueError):
# Start larger end
df = self.sc.get_scada_values(parameters,
start=2,
end=1,
every_nth_value=1,
query_type_lab=False, )

with self.assertRaises(ValueError):
# Start and/or end not in ns unix time
df = self.sc.get_scada_values(parameters,
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
start=1,
end=2,
every_nth_value=1,
query_type_lab=False, )

def test_pmt_names(self):
"""
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
Tests different query options for pmt list.
"""
pmts_dict = self.sc.find_pmt_names(pmts=12, current=True)
assert 'PMT12_HV' in pmts_dict.keys()
assert 'PMT12_I' in pmts_dict.keys()
assert pmts_dict['PMT12_HV'] == 'XE1T.CTPC.BOARD04.CHAN003.VMON'

pmts_dict = self.sc.find_pmt_names(pmts=(12, 13))
assert 'PMT12_HV' in pmts_dict.keys()
assert 'PMT13_HV' in pmts_dict.keys()

with self.assertRaises(ValueError):
self.sc.find_pmt_names(pmts=12, current=False, hv=False)

def test_token_expires(self):
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
self.sc.token_expires_in()

def test_convert_timezone(self):
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
parameters = {'SomeParameter': 'XE1T.CTPC.Board06.Chan011.VMon'}
df = self.sc.get_scada_values(parameters,
start=self.start,
end=self.end,
every_nth_value=1,
query_type_lab=False, )

df_strax = straxen.convert_time_zone(df, tz='strax')
assert df_strax.index.dtype.type is np.int64

df_etc = straxen.convert_time_zone(df, tz='Etc/GMT+0')
assert df_etc.index.dtype.tz is pytz.timezone('Etc/GMT+0')

def test_query_sc_values(self):
"""
Unity test for the SCADAInterface. Query a fixed range and check if
Expand Down