Commit b8ddad90 authored by Danny Hindson's avatar Danny Hindson
Browse files

Activate unit test and update to use workspace helper

Add unit test to CMakeLists so it gets run by ctest
Switch test from using POLARIS file (that currently only exists
in SystemTest data sets) to a generic workspace created by
workspace test helper
parent 53f50166
......@@ -77,6 +77,7 @@ set(TEST_PY_FILES
SwapWidthsTest.py
TimeSliceTest.py
TOSCABankCorrectionTest.py
TotScatCalculateSelfScatteringTest.py
TransformToIqtTest.py
VesuvioDiffractionReductionTest.py
WANDPowderReductionTest.py)
......
......@@ -5,8 +5,13 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import unittest
from mantid.simpleapi import TotScatCalculateSelfScattering, Load
import os
import shutil
import tempfile
from mantid.simpleapi import TotScatCalculateSelfScattering
from mantid.api import mtd
from isis_powder import SampleDetails
from testhelpers import WorkspaceCreationHelper
class TotScatCalculateSelfScatteringTest(unittest.TestCase):
......@@ -29,15 +34,30 @@ class TotScatCalculateSelfScatteringTest(unittest.TestCase):
material_json["ScatteringXSection"] = material.scattering_cross_section
self.material = material_json
self.cal_file_path = "polaris_grouping_file.cal"
self.dirpath = tempfile.mkdtemp()
self.cal_file_path = os.path.join(self.dirpath, "tot_scat.cal")
file = open(self.cal_file_path, 'w')
file.write("%i\t%i\t%f\t%i\t%i\n" % (1, 1, 0.0, 1, 1))
file.write("%i\t%i\t%f\t%i\t%i\n" % (2, 2, 0.0, 1, 1))
file.write("%i\t%i\t%f\t%i\t%i\n" % (3, 3, 0.0, 1, 2))
file.write("%i\t%i\t%f\t%i\t%i\n" % (4, 4, 0.0, 1, 2))
file.close()
def tearDown(self):
try:
os.remove(self.cal_file_path)
shutil.rmtree(self.dirpath)
except shutil.Error:
pass
def test_TotScatCalculateSelfScattering_executes(self):
raw_ws = Load(Filename='POLARIS98533.nxs')
correction_ws = TotScatCalculateSelfScattering(InputWorkspace=raw_ws,
raw_ws = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(6, 100, True)
mtd.addOrReplace("tot_scat_test", raw_ws)
correction_ws = TotScatCalculateSelfScattering(InputWorkspace="tot_scat_test",
CalFileName=self.cal_file_path,
SampleGeometry=self.geometry,
SampleMaterial=self.material)
self.assertEqual(correction_ws.getNumberHistograms(), 5)
self.assertEqual(correction_ws.getNumberHistograms(), 2)
if __name__ == "__main__":
......
......@@ -60,7 +60,7 @@ BOOST_PYTHON_MODULE(_WorkspaceCreationHelper) {
def("create2DWorkspaceWithFullInstrument", reinterpret_cast<Signature1_2D>(&create2DWorkspaceWithFullInstrument),
create2DWorkspaceWithFullInstrument_overloads()[return_value_policy<AsType<Workspace_sptr>>()]);
def("create2DWorkspaceWithRectangularInstrument", (Signature2_2D)&create2DWorkspaceWithRectangularInstrument,
create2DWorkspaceWithRectangularInstrument_overloads());
create2DWorkspaceWithRectangularInstrument_overloads()[return_value_policy<AsType<Workspace_sptr>>()]);
def("create2DWorkspace123WithMaskedBin", reinterpret_cast<Signature3_2D>(&create2DWorkspace123WithMaskedBin));
......
Supports Markdown
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