Skip to content
Snippets Groups Projects
Commit 5a556a45 authored by Corné Lukken's avatar Corné Lukken
Browse files

L2SS-938: Device server code coverage testing

parent b4899b07
No related branches found
No related tags found
1 merge request!475Draft: L2SS-938: Device server code coverage testing
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
importlib-metadata<2.0.0,>=0.12;python_version<"3.8" importlib-metadata<2.0.0,>=0.12;python_version<"3.8"
lofar-station-client@git+https://git.astron.nl/lofar2.0/lofar-station-client@0.9.2 lofar-station-client@git+https://git.astron.nl/lofar2.0/lofar-station-client@0.9.2
coverage>=6.0.2 # Apache-2.0
numpy numpy
mock mock
asyncua >= 0.9.90 # LGPLv3 asyncua >= 0.9.90 # LGPLv3
......
from tangostationcontrol.common.baselines import nr_baselines from tangostationcontrol.common.baselines import nr_baselines
DEBUG = True
# number of FPGA processing nodes # number of FPGA processing nodes
N_pn = 16 N_pn = 16
......
...@@ -24,9 +24,9 @@ from tango import AttrWriteType, DevState, DebugIt, Attribute, DeviceProxy, Attr ...@@ -24,9 +24,9 @@ from tango import AttrWriteType, DevState, DebugIt, Attribute, DeviceProxy, Attr
# Additional import # Additional import
from tangostationcontrol import __version__ as version from tangostationcontrol import __version__ as version
from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper
from tangostationcontrol.common.lofar_logging import log_exceptions from tangostationcontrol.common.lofar_logging import log_exceptions
from tangostationcontrol.common.states import DEFAULT_COMMAND_STATES, INITIALISED_STATES from tangostationcontrol.common.states import DEFAULT_COMMAND_STATES, INITIALISED_STATES
from tangostationcontrol.common import constants
from tangostationcontrol.common.type_checking import sequence_not_str from tangostationcontrol.common.type_checking import sequence_not_str
from tangostationcontrol.devices.device_decorators import only_in_states, fault_on_error from tangostationcontrol.devices.device_decorators import only_in_states, fault_on_error
from tangostationcontrol.toolkit.archiver import Archiver from tangostationcontrol.toolkit.archiver import Archiver
...@@ -199,10 +199,39 @@ class lofar_device(Device, metaclass=DeviceMeta): ...@@ -199,10 +199,39 @@ class lofar_device(Device, metaclass=DeviceMeta):
elif not mask[idx]: elif not mask[idx]:
merge_values[idx] = current_values[idx] merge_values[idx] = current_values[idx]
def store_coverage(self):
try:
self.cov.stop()
self.cov.save()
logger.info("Stopped code coverage measurements")
except Exception:
pass
def start_coverage(self):
try:
import os
import atexit
import coverage
self.cov = coverage.Coverage(
data_file=os.getcwd() + "/tangostationcontrol/.coverage",
data_suffix=True,
branch=True,
source=os.getcwd() + "/tangostationcontrol/tangostationcontrol"
)
self.cov.start()
logger.info("Started code coverage measurements: %s", os.getcwd())
atexit.register(self.store_coverage)
except Exception as e:
logger.warning("Could not configure for code coverage: %s", e)
@log_exceptions() @log_exceptions()
def init_device(self): def init_device(self):
""" Instantiates the device in the OFF state. """ """ Instantiates the device in the OFF state. """
if constants.DEBUG:
self.start_coverage()
# NOTE: Will delete_device first, if necessary # NOTE: Will delete_device first, if necessary
Device.init_device(self) Device.init_device(self)
......
...@@ -16,6 +16,15 @@ import asynctest ...@@ -16,6 +16,15 @@ import asynctest
"""Setup logging for unit tests""" """Setup logging for unit tests"""
configure_logger(debug=True) configure_logger(debug=True)
import logging
logger = logging.getLogger()
# def tearDownModule():
# import pdb; pdb.set_trace()
# logger.fatal("HELLO TEARDOWN?")
#
# unittest.addModuleCleanup(tearDownModule)
class BaseTestCase(testscenarios.WithScenarios, unittest.TestCase): class BaseTestCase(testscenarios.WithScenarios, unittest.TestCase):
"""Test base class.""" """Test base class."""
......
...@@ -7,7 +7,6 @@ asynctest>=0.13.0 # Apache-2.0 ...@@ -7,7 +7,6 @@ asynctest>=0.13.0 # Apache-2.0
bandit>=1.6.0 # Apache-2.0 bandit>=1.6.0 # Apache-2.0
virtualenv>=20.16.0 # MIT virtualenv>=20.16.0 # MIT
build>=0.8.0 # MIT build>=0.8.0 # MIT
coverage>=5.2.0 # Apache-2.0
doc8>=0.8.0 # Apache-2.0 doc8>=0.8.0 # Apache-2.0
flake8>=3.8.0 # MIT flake8>=3.8.0 # MIT
flake8-bugbear>=22.1.11 # MIT flake8-bugbear>=22.1.11 # MIT
......
...@@ -42,6 +42,10 @@ envdir = {toxworkdir}/testenvpy39 ...@@ -42,6 +42,10 @@ envdir = {toxworkdir}/testenvpy39
[testenv:py310] [testenv:py310]
envdir = {toxworkdir}/testenvpy310 envdir = {toxworkdir}/testenvpy310
[testenv:debug]
basepython=python3.7
commands = {envpython} -m testtools.run {posargs}
[testenv:integration] [testenv:integration]
allowlist_externals = echo allowlist_externals = echo
passenv = TANGO_HOST passenv = TANGO_HOST
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment