From bd221efd496484bcef68db878eada80c649cc3bd Mon Sep 17 00:00:00 2001 From: "Adam J. Jackson" <a.j.jackson@physics.org> Date: Wed, 15 Jan 2020 15:58:03 +0000 Subject: [PATCH] Abins Instrument: use NotImplementedError for method stubs Abins uses a base class for Instruments, which defines a couple of methods returning None. None is not the right response if these methods were not adapted to a child class; use NotImplementedError to mark these more clearly. --- .../AbinsModules/Instruments/Instrument.py | 6 ++--- scripts/test/Abins/AbinsInstrumentTest.py | 25 +++++++++++++++++++ scripts/test/Abins/CMakeLists.txt | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 scripts/test/Abins/AbinsInstrumentTest.py diff --git a/scripts/AbinsModules/Instruments/Instrument.py b/scripts/AbinsModules/Instruments/Instrument.py index 934dad3eaf9..9f8ef4ccce0 100644 --- a/scripts/AbinsModules/Instruments/Instrument.py +++ b/scripts/AbinsModules/Instruments/Instrument.py @@ -20,7 +20,7 @@ class Instrument(object): :param input_data: data from which Q2 should be calculated :returns: numpy array with Q2 data """ - return None + raise NotImplementedError() def convolve_with_resolution_function(self, frequencies=None, bins=None, s_dft=None, scheme='auto'): """ @@ -37,8 +37,8 @@ class Instrument(object): 'auto' should select something sensible. :type scheme: str - """ - return None + """ + raise NotImplementedError() def __str__(self): return self._name diff --git a/scripts/test/Abins/AbinsInstrumentTest.py b/scripts/test/Abins/AbinsInstrumentTest.py new file mode 100644 index 00000000000..d7fa7d2f2cb --- /dev/null +++ b/scripts/test/Abins/AbinsInstrumentTest.py @@ -0,0 +1,25 @@ +# Mantid Repository : https://github.com/mantidproject/mantid +# +# Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI, +# NScD Oak Ridge National Laboratory, European Spallation Source +# & Institut Laue - Langevin +# SPDX - License - Identifier: GPL - 3.0 + +from __future__ import (absolute_import, division, print_function) +import unittest + +from AbinsModules.Instruments.Instrument import Instrument + + +class AbinsInstrumentTest(unittest.TestCase): + def test_instrument_notimplemented(self): + instrument = Instrument() + + with self.assertRaises(NotImplementedError): + instrument.calculate_q_powder() + + with self.assertRaises(NotImplementedError): + instrument.convolve_with_resolution_function() + + +if __name__ == '__main__': + unittest.main() diff --git a/scripts/test/Abins/CMakeLists.txt b/scripts/test/Abins/CMakeLists.txt index b55939d572d..0b0e82fe5ea 100644 --- a/scripts/test/Abins/CMakeLists.txt +++ b/scripts/test/Abins/CMakeLists.txt @@ -9,6 +9,7 @@ set ( TEST_PY_FILES AbinsCalculateSPowderTest.py AbinsDWSingleCrystalDataTest.py AbinsFrequencyPowderGeneratorTest.py + AbinsInstrumentTest.py AbinsIOmoduleTest.py AbinsKpointsDataTest.py AbinsLoadCASTEPTest.py -- GitLab