Commit 9805e837 authored by Josef Brandt's avatar Josef Brandt

Run unitests in TestSuite

See runAllTests.py for details. Now the individual unittests can be run all together, which makes testing a lot faster..
parent 10cc7062
......@@ -30,3 +30,5 @@ instrumentcom/renishawtesting.py
*.jdx
instrumentcom/thermoFTIRCom.py
instrumentcom/thermoDDE.py
"""
Interface to run all tests (except the automated gepard test, which has to be started from a running GEPARD instance.
When new tests are added, they have to be imported here (strangely I have to add the path to gepard to make the
imports work..). Then they have to be added to the allTests-List direclty below.
"""
import unittest
import sys
sys.path.append(r'C:\Users\xbrjos\Desktop\Python')
from gepard.unittests.test_coordTransform import TestCoordinateTransform
from gepard.unittests.test_FTIRCom import TestFTIRCom
from gepard.unittests.test_getShortestPath import TestTSP
from gepard.unittests.test_simulatedStage import Test_FakeCamera, TestSimulatedStage
from gepard.unittests.test_specscan import TestSpecScan
from gepard.unittests.test_specscanui import TestSpecScanUI
from gepard.unittests.test_spectraHandler import TestSpecHandler
from gepard.unittests.test_workModes import TestWorkModes
allTests: list = [TestCoordinateTransform, TestFTIRCom, TestTSP, Test_FakeCamera, TestSimulatedStage,
TestSpecScan, TestSpecScanUI, TestSpecHandler, TestWorkModes]
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
for testCase in suite._tests:
runMethod = getattr(testCase, "runTest", None)
if not callable(runMethod):
testCase.runTest = passMethod
testSuite: unittest.TestSuite = unittest.TestSuite()
for test in allTests:
testSuite.addTest(test())
makeTestSuiteRunnable(testSuite)
unittest.TextTestRunner().run(testSuite)
# import unittest
# from unittest.mock import MagicMock
# import tempfile
# import numpy as np
# import logging
# import os
# import csv
# from instrumentcom.thermoFTIRCom import ThermoFTIRCom
# # from analysis.particleContainer import ParticleContainer
# # from analysis.particleAndMeasurement import Particle, Measurement
#
# class TestFTIRCom(unittest.TestCase):
# def setUp(self) -> None:
# logger = logging.getLogger('TestLogger')
# self.ftirCom = ThermoFTIRCom(logger)
#
# def test_export_spec_as_csv(self) -> None:
# testSpec: np.ndarray = np.zeros((10, 2))
# testSpec[:, 1] = np.arange(10)
# with tempfile.TemporaryDirectory() as tmpdir:
# fname: str = os.path.join(tmpdir, 'testSpec.csv')
# self.ftirCom._export_spec_to_csv(fname, testSpec)
# self.assertTrue(os.path.exists(fname))
# with open(fname, 'r') as csvfile:
# index: int = 0
# for index, row in enumerate(csv.reader(csvfile, delimiter=';')):
# self.assertEqual(len(row), 2)
# self.assertEqual(float(row[0]), testSpec[index, 0])
# self.assertEqual(float(row[1]), testSpec[index, 1])
# self.assertEqual(index, testSpec.shape[0]-1)
#
import unittest
import tempfile
import numpy as np
import logging
import os
import csv
from ..instrumentcom.FTIRCom import FTIRCom
class TestFTIRCom(unittest.TestCase):
def setUp(self) -> None:
logger = logging.getLogger('TestLogger')
FTIRCom.simulatedInterface = True
self.ftirCom = FTIRCom(logger)
def test_export_spec_as_csv(self) -> None:
testSpec: np.ndarray = np.zeros((10, 2))
testSpec[:, 1] = np.arange(10)
with tempfile.TemporaryDirectory() as tmpdir:
fname: str = os.path.join(tmpdir, 'testSpec.csv')
self.ftirCom._export_spec_to_csv(fname, testSpec)
self.assertTrue(os.path.exists(fname))
with open(fname, 'r') as csvfile:
index: int = 0
for index, row in enumerate(csv.reader(csvfile, delimiter=';')):
self.assertEqual(len(row), 2)
self.assertEqual(float(row[0]), testSpec[index, 0])
self.assertEqual(float(row[1]), testSpec[index, 1])
self.assertEqual(index, testSpec.shape[0]-1)
# # def test_evaluate_spectra(self) -> None:
# # mockSearch: MagicMock = MagicMock(name='search_library')
# # mockSearch.return_value = {75.0: 'PET',
......
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
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