Commit 9faf6df1 authored by Josef Brandt's avatar Josef Brandt

Critical fix in unittests

Fixes, that the actual tests were not run when using the runAllTests.py...
parent 8020cfd2
...@@ -206,13 +206,14 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -206,13 +206,14 @@ class SampleView(QtWidgets.QGraphicsView):
Adds a new handler to the logger to create a log also in the dataset directory Adds a new handler to the logger to create a log also in the dataset directory
:return: :return:
""" """
logPath = os.path.join(self.dataset.path, 'gepardLog.txt') if self.dataset.path != '':
self.logger.info(f'creating new log handler to path: {logPath}') logPath = os.path.join(self.dataset.path, 'gepardLog.txt')
self.logger.addHandler( self.logger.info(f'creating new log handler to path: {logPath}')
logging.handlers.RotatingFileHandler( self.logger.addHandler(
logPath, maxBytes=5 * (1 << 20), backupCount=10) logging.handlers.RotatingFileHandler(
) logPath, maxBytes=5 * (1 << 20), backupCount=10)
setDefaultLoggingConfig(self.logger) )
setDefaultLoggingConfig(self.logger)
def setupParticleEditor(self): def setupParticleEditor(self):
""" """
......
...@@ -100,7 +100,6 @@ def getShortestPath(_points: np.ndarray) -> List[int]: ...@@ -100,7 +100,6 @@ def getShortestPath(_points: np.ndarray) -> List[int]:
:param _points: (N, 2) shape array of x, y coordinates :param _points: (N, 2) shape array of x, y coordinates
:returns: list of indices of shortest path to visit all points :returns: list of indices of shortest path to visit all points
""" """
print('SHORTEST PATH HERE')
numPoints: int = _points.shape[0] numPoints: int = _points.shape[0]
shortestPath: List[int] = list(np.arange(numPoints, dtype=np.int)) 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) if numPoints >= 4: # the tsp needs at least four points (swap of two pairs of points concurrently)
......
...@@ -6,6 +6,7 @@ imports work..). Then they have to be added to the allTests-List direclty below. ...@@ -6,6 +6,7 @@ imports work..). Then they have to be added to the allTests-List direclty below.
import unittest import unittest
import sys import sys
import inspect
import os import os
scriptFolder = os.path.realpath(__file__) scriptFolder = os.path.realpath(__file__)
gepardParentFolder = os.path.dirname(os.path.dirname(os.path.dirname(scriptFolder))) # three levels up.. 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 ...@@ -25,13 +26,18 @@ allTests: list = [TestCoordinateTransform, TestTSP, Test_FakeCamera, TestSimulat
def makeTestSuiteRunnable(suite: unittest.TestSuite): def makeTestSuiteRunnable(suite: unittest.TestSuite):
"""The unittests need a runTest-Method when called this way. """The unittests need a runTest-Method when called this way.
Let's just create a fake one here on the fly..""" Let's just create a fake one here on the fly.."""
def passMethod(): def makeRunTestLambda(_testCase: unittest.TestCase):
pass 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: for testCase in suite._tests:
runMethod = getattr(testCase, "runTest", None) runMethod = getattr(testCase, "runTest", None)
if not callable(runMethod): if not callable(runMethod):
testCase.runTest = passMethod testCase.runTest = makeRunTestLambda(testCase)
testSuite: unittest.TestSuite = unittest.TestSuite() testSuite: unittest.TestSuite = unittest.TestSuite()
......
import unittest import unittest
import sys
from PyQt5 import QtWidgets
from .testhelpers import getDefaultSampleview from .testhelpers import getDefaultSampleview
from ..gui.specscanui import SpecScanUI from ..gui.specscanui import SpecScanUI
app: QtWidgets.QApplication = QtWidgets.QApplication(sys.argv)
class TestSpecScanUI(unittest.TestCase): class TestSpecScanUI(unittest.TestCase):
def setUp(self) -> None: def setUp(self) -> None:
self.specScanUI: SpecScanUI = SpecScanUI(getDefaultSampleview()) self.specScanUI: SpecScanUI = SpecScanUI(getDefaultSampleview())
self.specScanUI.view.imparent.hide() self.specScanUI.view.imparent.hide()
def testLayout(self) -> None: def test_layout(self) -> None:
self.specScanUI.show() self.specScanUI.show()
app.exec_() \ No newline at end of file
def tearDown(self) -> None:
app.closeAllWindows()
\ No newline at end of file
...@@ -44,6 +44,12 @@ class TestWorkModes(unittest.TestCase): ...@@ -44,6 +44,12 @@ class TestWorkModes(unittest.TestCase):
def setImageCenter(self, center=None): def setImageCenter(self, center=None):
pass pass
def show(self):
pass
def hide(self):
pass
sampleview = self.gepard.view sampleview = self.gepard.view
sampleview.moveStageToPosition = MagicMock() sampleview.moveStageToPosition = MagicMock()
self.modeHandler.detectMode.widget = FakeDetectViewWidget() self.modeHandler.detectMode.widget = FakeDetectViewWidget()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment