From 75e66438bb788945210ef5fca634eb34130ab828 Mon Sep 17 00:00:00 2001 From: Sinisa Veseli Date: Wed, 29 Mar 2023 15:56:53 -0500 Subject: [PATCH 1/2] add tests for all CLIs --- test/testAdSimServerCli.py | 15 +++++++++++++++ test/testHpcCollectorCli.py | 4 +--- test/testHpcConsumerCli.py | 4 +--- test/testMirrorServerCli.py | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 test/testAdSimServerCli.py create mode 100644 test/testMirrorServerCli.py diff --git a/test/testAdSimServerCli.py b/test/testAdSimServerCli.py new file mode 100644 index 0000000..5f8c17a --- /dev/null +++ b/test/testAdSimServerCli.py @@ -0,0 +1,15 @@ +''' +Test AD Sim Server CLI. +''' +from unittest.mock import Mock +import sys +import pylint.lint + +from pvapy.cli import adSimServer + +def testLint(monkeypatch): + ''' Test for linting errors ''' + monkeypatch.setattr(sys, 'exit', Mock()) + pylint_opts = ['pvapy.cli.adSimServer', '--disable=all', '--enable=E,F', '--generated-members="pva.*"'] + pylint.lint.Run(pylint_opts) + sys.exit.assert_called_once_with(0) diff --git a/test/testHpcCollectorCli.py b/test/testHpcCollectorCli.py index bc88342..257c709 100644 --- a/test/testHpcCollectorCli.py +++ b/test/testHpcCollectorCli.py @@ -1,9 +1,7 @@ ''' - Test HPC Collector CLI. +Test HPC Collector CLI. ''' from unittest.mock import Mock -import tempfile -import os import sys import pylint.lint diff --git a/test/testHpcConsumerCli.py b/test/testHpcConsumerCli.py index dbc5c10..14ed8d1 100644 --- a/test/testHpcConsumerCli.py +++ b/test/testHpcConsumerCli.py @@ -1,9 +1,7 @@ ''' - Test HPC Consumer CLI. +Test HPC Consumer CLI. ''' from unittest.mock import Mock -import tempfile -import os import sys import pylint.lint diff --git a/test/testMirrorServerCli.py b/test/testMirrorServerCli.py new file mode 100644 index 0000000..ae4f244 --- /dev/null +++ b/test/testMirrorServerCli.py @@ -0,0 +1,15 @@ +''' +Test Mirror Server CLI. +''' +from unittest.mock import Mock +import sys +import pylint.lint + +from pvapy.cli import mirrorServer + +def testLint(monkeypatch): + ''' Test for linting errors ''' + monkeypatch.setattr(sys, 'exit', Mock()) + pylint_opts = ['pvapy.cli.mirrorServer', '--disable=all', '--enable=E,F', '--generated-members="pva.*"'] + pylint.lint.Run(pylint_opts) + sys.exit.assert_called_once_with(0) From 6c2779f5cf6e96d7a0943b1aa2f486df48d48b68 Mon Sep 17 00:00:00 2001 From: Sinisa Veseli Date: Wed, 29 Mar 2023 16:04:30 -0500 Subject: [PATCH 2/2] fix linting issues --- pvapy/cli/adSimServer.py | 3 ++- pvapy/cli/mirrorServer.py | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pvapy/cli/adSimServer.py b/pvapy/cli/adSimServer.py index 39c749d..d89a683 100755 --- a/pvapy/cli/adSimServer.py +++ b/pvapy/cli/adSimServer.py @@ -1,4 +1,5 @@ #!/usr/bin/env python + ''' Area Detector Simulation Server ''' @@ -178,7 +179,7 @@ def generateFrames(self): if self.maximum is not None: mx = float(min(dtinfo.max, self.maximum)) self.frames = np.random.uniform(mn, mx, size=(self.nf, self.ny, self.nx)) - if datatype == 'float32': + if self.datatype == 'float32': self.frames = np.float32(self.frames) print(f'Generated frame shape: {self.frames[0].shape}') diff --git a/pvapy/cli/mirrorServer.py b/pvapy/cli/mirrorServer.py index 2e06a60..01481a7 100755 --- a/pvapy/cli/mirrorServer.py +++ b/pvapy/cli/mirrorServer.py @@ -1,8 +1,12 @@ #!/usr/bin/env python +''' +PVA Mirror Server. +''' + +import sys import argparse import time -import numpy as np import pvaccess as pva __version__ = pva.__version__ @@ -17,11 +21,11 @@ def main(): args, unparsed = parser.parse_known_args() if len(unparsed) > 0: print(f'Unrecognized argument(s): {" ".join(unparsed)}') - exit(1) + sys.exit(1) if args.channel_map is None: print('Channel map is not specified.') - exit(1) + sys.exit(1) # Cleanup channel map entries # They are expected to be of the form @@ -39,8 +43,8 @@ def main(): channelList.append(me[0]) entryLength = len(me) if entryLength > 6: - print(f'Invalid channel map entry: {e}') - exit(1) + print(f'Invalid channel map entry: {e}') + sys.exit(1) if entryLength <= 2: # Add default source provider type me.append('pva') @@ -56,17 +60,17 @@ def main(): me[2] = providerTypeMap.get(me[2].lower()) if me[2] is None: print(f'Invalid source provider type specified for entry: {e}') - exit(1) + sys.exit(1) me[3] = int(me[3]) if me[3] < 0: print(f'Invalid source queue size specified for entry: {e}') - exit(1) + sys.exit(1) me[4] = int(me[4]) if me[4] < 1: print(f'Invalid number of source monitors specified for entry: {e}') - exit(1) + sys.exit(1) mapEntries.append(me) - + server = pva.PvaMirrorServer() server.start() startTime = time.time() @@ -91,7 +95,7 @@ def main(): for c in channelList: print(f'Channel {c} @ {now:.3f}: {server.getMirrorRecordCounters(c)}') time.sleep(sleepTime) - except KeyboardInterrupt as e: + except KeyboardInterrupt: print('Keyboard interrupt received, exiting.') break server.stop() @@ -99,6 +103,6 @@ def main(): now = time.time() for c in channelList: print(f'Channel {c} @ {now:.3f}: {server.getMirrorRecordCounters(c)}') - + if __name__ == '__main__': main()