From 9faf6df17e0721b62423179fd21d16c9a26b0fbf Mon Sep 17 00:00:00 2001 From: Josef Brandt Date: Wed, 14 Oct 2020 16:07:46 +0200 Subject: [PATCH] Critical fix in unittests Fixes, that the actual tests were not run when using the runAllTests.py... --- sampleview.py | 15 ++++++++------- specScan.py | 1 - unittests/runAllTests.py | 12 +++++++++--- unittests/test_specscanui.py | 12 ++---------- unittests/test_workModes.py | 6 ++++++ 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/sampleview.py b/sampleview.py index 8d66bdc..5302f98 100644 --- a/sampleview.py +++ b/sampleview.py @@ -206,13 +206,14 @@ class SampleView(QtWidgets.QGraphicsView): Adds a new handler to the logger to create a log also in the dataset directory :return: """ - logPath = os.path.join(self.dataset.path, 'gepardLog.txt') - self.logger.info(f'creating new log handler to path: {logPath}') - self.logger.addHandler( - logging.handlers.RotatingFileHandler( - logPath, maxBytes=5 * (1 << 20), backupCount=10) - ) - setDefaultLoggingConfig(self.logger) + if self.dataset.path != '': + logPath = os.path.join(self.dataset.path, 'gepardLog.txt') + self.logger.info(f'creating new log handler to path: {logPath}') + self.logger.addHandler( + logging.handlers.RotatingFileHandler( + logPath, maxBytes=5 * (1 << 20), backupCount=10) + ) + setDefaultLoggingConfig(self.logger) def setupParticleEditor(self): """ diff --git a/specScan.py b/specScan.py index 792cc7e..d8bcf78 100644 --- a/specScan.py +++ b/specScan.py @@ -100,7 +100,6 @@ def getShortestPath(_points: np.ndarray) -> List[int]: :param _points: (N, 2) shape array of x, y coordinates :returns: list of indices of shortest path to visit all points """ - print('SHORTEST PATH HERE') numPoints: int = _points.shape[0] shortestPath: List[int] = list(np.arange(numPoints, dtype=np.int)) if numPoints >= 4: # the tsp needs at least four points (swap of two pairs of points concurrently) diff --git a/unittests/runAllTests.py b/unittests/runAllTests.py index da71052..c44b316 100644 --- a/unittests/runAllTests.py +++ b/unittests/runAllTests.py @@ -6,6 +6,7 @@ imports work..). Then they have to be added to the allTests-List direclty below. import unittest import sys +import inspect import os scriptFolder = os.path.realpath(__file__) gepardParentFolder = os.path.dirname(os.path.dirname(os.path.dirname(scriptFolder))) # three levels up.. @@ -25,13 +26,18 @@ allTests: list = [TestCoordinateTransform, TestTSP, Test_FakeCamera, TestSimulat def makeTestSuiteRunnable(suite: unittest.TestSuite): """The unittests need a runTest-Method when called this way. Let's just create a fake one here on the fly..""" - def passMethod(): - pass + def makeRunTestLambda(_testCase: unittest.TestCase): + return lambda: runTestStartWith_test_(_testCase) + + def runTestStartWith_test_(_testCase: unittest.TestCase): + for methodName, method in inspect.getmembers(_testCase, predicate=inspect.ismethod): + if methodName.startswith("test_"): + method() for testCase in suite._tests: runMethod = getattr(testCase, "runTest", None) if not callable(runMethod): - testCase.runTest = passMethod + testCase.runTest = makeRunTestLambda(testCase) testSuite: unittest.TestSuite = unittest.TestSuite() diff --git a/unittests/test_specscanui.py b/unittests/test_specscanui.py index 846e043..457a8cc 100644 --- a/unittests/test_specscanui.py +++ b/unittests/test_specscanui.py @@ -1,20 +1,12 @@ import unittest -import sys -from PyQt5 import QtWidgets from .testhelpers import getDefaultSampleview from ..gui.specscanui import SpecScanUI -app: QtWidgets.QApplication = QtWidgets.QApplication(sys.argv) - class TestSpecScanUI(unittest.TestCase): def setUp(self) -> None: self.specScanUI: SpecScanUI = SpecScanUI(getDefaultSampleview()) self.specScanUI.view.imparent.hide() - def testLayout(self) -> None: - self.specScanUI.show() - app.exec_() - - def tearDown(self) -> None: - app.closeAllWindows() \ No newline at end of file + def test_layout(self) -> None: + self.specScanUI.show() \ No newline at end of file diff --git a/unittests/test_workModes.py b/unittests/test_workModes.py index bf0a4eb..369093c 100644 --- a/unittests/test_workModes.py +++ b/unittests/test_workModes.py @@ -44,6 +44,12 @@ class TestWorkModes(unittest.TestCase): def setImageCenter(self, center=None): pass + def show(self): + pass + + def hide(self): + pass + sampleview = self.gepard.view sampleview.moveStageToPosition = MagicMock() self.modeHandler.detectMode.widget = FakeDetectViewWidget() -- GitLab