This commit is contained in:
2019-03-20 13:52:00 +01:00
parent 3084fe0510
commit 5db0f78aee
910 changed files with 191152 additions and 322 deletions

View File

@@ -0,0 +1,138 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
import unittest
import diffcalc.gdasupport.minigda.command
from diffcalc.gdasupport.minigda.command import Pos, Scan, ScanDataPrinter
from diffcalc.gdasupport.minigda.scannable import \
MultiInputExtraFieldsDummyScannable, SingleFieldDummyScannable
class BadSingleFieldDummyScannable(SingleFieldDummyScannable):
def getPosition(self):
raise Exception("Problem")
class NoneReturningSingleFieldDummyScannable(SingleFieldDummyScannable):
def getPosition(self):
return None
class TestPos(object):
def setup_method(self):
self.dummyMainNamespace = namespace = {}
namespace['notAScannable'] = 3.124
namespace['scnA'] = SingleFieldDummyScannable('scnA')
namespace['scnB'] = SingleFieldDummyScannable('scnB')
namespace['scnC'] = SingleFieldDummyScannable('scnC')
namespace['scnD'] = SingleFieldDummyScannable('scnD')
namespace['scnNone'] = \
NoneReturningSingleFieldDummyScannable('scnNone')
namespace['scnBad'] = BadSingleFieldDummyScannable('scnBad')
diffcalc.gdasupport.minigda.command.ROOT_NAMESPACE_DICT = \
self.dummyMainNamespace
self.pos = Pos()
def testPosReturningReportWithRead(self):
scnA = self.dummyMainNamespace['scnA']
assert self.pos.posReturningReport(scnA) == 'scnA: 0.0000'
def testPosReturningReportWithMove(self):
scnA = self.dummyMainNamespace['scnA']
assert self.pos.posReturningReport(scnA, 1.123) == 'scnA: 1.1230'
def test__call__(self):
scnA = self.dummyMainNamespace['scnA']
self.pos.__call__(scnA)
self.pos.__call__(scnA, 4.321)
print "*"
self.pos.__call__()
print "*"
def testPosReturningReportWithMultiFieldScannables(self):
scn = MultiInputExtraFieldsDummyScannable('mie', ['i1', 'i2'], ['e1'])
assert (self.pos.posReturningReport(scn)
== 'mie: i1: 0.0000 i2: 0.0000 e1: 100.0000 ')
def testPosReturningReportWithBadScannable(self):
scnBad = self.dummyMainNamespace['scnBad']
assert self.pos.posReturningReport(scnBad) == "scnBad: Error: Problem"
assert (self.pos.posReturningReport(scnBad, 4.321)
== "scnBad: Error: Problem")
def testPosReturningReportWithNoneReturningScannable(self):
scnNone = self.dummyMainNamespace['scnNone']
assert self.pos.posReturningReport(scnNone) == "scnNone: ---"
assert self.pos.posReturningReport(scnNone, 4.321) == "scnNone: ---"
class TestScan(object):
def setup_method(self):
self.scan = Scan([ScanDataPrinter()])
def test__parseScanArgsIntoScannableArgGroups(self):
scnA = SingleFieldDummyScannable('scnA')
scnB = SingleFieldDummyScannable('scnB')
scnC = SingleFieldDummyScannable('scnC')
scnD = SingleFieldDummyScannable('scnD')
scanargs = (scnA, 1, 2, 3, scnB, [4, 5, 6], scnC, scnD, 1.123456)
r = self.scan._parseScanArgsIntoScannableArgGroups(scanargs)
result = [r[0].scannable, r[0].args, r[1].scannable, r[1].args,
r[2].scannable, r[2].args, r[3].scannable, r[3].args]
desired = [scnA, [1, 2, 3], scnB, [[4, 5, 6], ], scnC, list(), scnD,
[1.123456]]
assert result == desired
def test__reorderGroupsAccordingToLevel(self):
scn4 = SingleFieldDummyScannable('scn4')
scn4.setLevel(4)
scn5a = SingleFieldDummyScannable('scn5a')
scn5a.setLevel(5)
scn5b = SingleFieldDummyScannable('scn5b')
scn5b.setLevel(5)
scn6 = SingleFieldDummyScannable('scn6')
scn6.setLevel(6)
def t(scanargs):
groups = self.scan._parseScanArgsIntoScannableArgGroups(scanargs)
r = self.scan._reorderInnerGroupsAccordingToLevel(groups)
return [r[0].scannable, r[1].scannable, r[2].scannable,
r[3].scannable]
assert (t((scn5a, 1, 2, 3, scn6, 1, scn5b, scn4))
== [scn5a, scn4, scn5b, scn6])
assert (t((scn5a, 1, 3, scn6, 1, scn5b, scn4))
== [scn4, scn5a, scn5b, scn6])
def test__Frange(self):
assert self.scan._frange(1, 1.3, .1) == [1.0, 1.1, 1.2, 1.3]
def test__Call__(self):
scn4 = SingleFieldDummyScannable('scn4')
scn4.setLevel(4)
scn5a = SingleFieldDummyScannable('scn5a')
scn5a.setLevel(5)
scn5b = SingleFieldDummyScannable('scn5b')
scn5b.setLevel(5)
scn6 = SingleFieldDummyScannable('scn6')
scn6.setLevel(6)
self.scan.__call__(scn5a, 1, 3, 1, scn6, 1, scn5b, scn4)

View File

@@ -0,0 +1,83 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
import unittest
try:
from gdascripts.pd.dummy_pds import DummyPD # @UnusedImport
except ImportError:
from diffcalc.gdasupport.minigda.scannable import DummyPD
from diffcalc.gdasupport.scannable.mock import MockMotor
from diffcalc.gdasupport.minigda.scannable import \
SingleFieldDummyScannable
from diffcalc.gdasupport.minigda.scannable import Scannable
from diffcalc.gdasupport.scannable.base import ScannableGroup
class TestScannable(object):
def setup_method(self):
self.scannable = Scannable()
def testSomethingUnrelated(self):
a = SingleFieldDummyScannable('a')
print isinstance(a, Scannable)
def createDummyAxes(names):
result = []
for name in names:
result.append(DummyPD(name))
return result
class TestScannableGroup(object):
def setup_method(self):
self.a = MockMotor('a')
self.b = MockMotor('bbb')
self.c = MockMotor('c')
self.sg = ScannableGroup('abc', (self.a, self.b, self.c))
def testInit(self):
assert list(self.sg.getInputNames()) == ['a', 'bbb', 'c']
assert self.sg.getPosition() == [0.0, 0.0, 0.0]
def testAsynchronousMoveTo(self):
self.sg.asynchronousMoveTo([1, 2.0, 3])
assert self.sg.getPosition() == [1.0, 2.0, 3.0]
def testAsynchronousMoveToWithNones(self):
self.sg.asynchronousMoveTo([1.0, 2.0, 3.0])
self.sg.asynchronousMoveTo([None, None, 3.2])
assert self.sg.getPosition() == [1.0, 2.0, 3.2]
def testGetPosition(self):
# implicitely tested above
pass
def testIsBusy(self):
assert not self.sg.isBusy()
self.sg.asynchronousMoveTo([1.0, 2.0, 3.0])
assert self.sg.isBusy()
self.b.makeNotBusy()
assert self.sg.isBusy()
self.a.makeNotBusy()
self.c.makeNotBusy()
assert not self.sg.isBusy()

View File

@@ -0,0 +1,55 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
class MockParameterManager:
def __init__(self):
self.params = {}
def set_constraint(self, name, value):
self.params[name] = value
def get_constraint(self, name):
return self.params[name]
class MockDiffcalc:
def __init__(self, numberAngles):
self.numberAngles = numberAngles
self.parameter_manager = MockParameterManager()
def hkl_to_angles(self, h, k, l):
params = {}
params['theta'] = 1.
params['2theta'] = 12.
params['Bin'] = 123.
params['Bout'] = 1234.
params['azimuth'] = 12345.
return ([h] * self.numberAngles, params)
def angles_to_hkl(self, pos):
if len(pos) != self.numberAngles: raise ValueError
params = {}
params['theta'] = 1.
params['2theta'] = 12.
params['Bin'] = 123.
params['Bout'] = 1234.
params['azimuth'] = 12345.
return ([pos[0]] * 3, params)

View File

@@ -0,0 +1,169 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
import unittest
from mock import Mock
from diffcalc.gdasupport.scannable.slave_driver import SlaveScannableDriver
from diffcalc.gdasupport.scannable.diffractometer import \
DiffractometerScannableGroup
from diffcalc.gdasupport.scannable.mock import MockMotor
from test.diffcalc.gdasupport.scannable.mockdiffcalc import MockDiffcalc
try:
from gdascripts.pd.dummy_pds import DummyPD # @UnusedImport
except ImportError:
from diffcalc.gdasupport.minigda.scannable import DummyPD
try:
from gda.device.scannable.scannablegroup import ScannableGroup
except ImportError:
from diffcalc.gdasupport.minigda.scannable import ScannableGroup
def createDummyAxes(names):
result = []
for name in names:
result.append(DummyPD(name))
return result
class MockSlaveScannableDriver(object):
def __init__(self):
self.busy = False
self.lastPosition = None
def isBusy(self):
return self.busy
def triggerAsynchronousMove(self, position):
self.lastPosition = position
def getPositions(self):
return 90, 91
class TestDiffractometerScannableGroup(object):
def setup_method(self):
self.a = MockMotor()
self.b = MockMotor()
self.c = MockMotor()
self.d = MockMotor()
self.e = MockMotor()
self.f = MockMotor()
self.grp = ScannableGroup(
'grp', [self.a, self.b, self.c, self.d, self.e, self.f])
self.grp.configure()
self.sg = DiffractometerScannableGroup(
'sixc', MockDiffcalc(6), self.grp)
def testInit(self):
assert list(self.sg.getPosition()) == [0., 0., 0., 0., 0., 0.]
def testAsynchronousMoveTo(self):
self.sg.asynchronousMoveTo([1, 2.0, 3, 4, 5, 6])
assert list(self.sg.getPosition()) == [1., 2., 3., 4., 5., 6.]
def testAsynchronousMoveToWithNones(self):
self.sg.asynchronousMoveTo([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
self.sg.asynchronousMoveTo([None, None, 3.2, None, 5.2, None])
assert list(self.sg.getPosition()) == [1., 2., 3.2, 4., 5.2, 6.]
def testGetPosition(self):
#implicitely tested above
pass
def testWhereMoveTo(self):
# just check for exceptions
print self.sg.simulateMoveTo((1.23, 2, 3, 4, 5, 6))
def testIsBusy(self):
assert not self.sg.isBusy()
self.sg.asynchronousMoveTo([1.0, 2.0, 3.0, 4, 5, 6])
assert self.sg.isBusy()
self.b.makeNotBusy()
assert self.sg.isBusy()
self.a.makeNotBusy()
self.c.makeNotBusy()
self.d.makeNotBusy()
self.e.makeNotBusy()
self.f.makeNotBusy()
assert not self.sg.isBusy()
def testRepr(self):
print self.sg.__repr__()
class TestDiffractometerScannableGroupWithSlave(
TestDiffractometerScannableGroup):
def setup_method(self):
TestDiffractometerScannableGroup.setup_method(self)
self.mock_driver = Mock(spec=SlaveScannableDriver)
self.mock_driver.getPositions.return_value = 90, 91
self.mock_driver.isBusy.return_value = False
self.mock_driver.getScannableNames.return_value = 'a', 'b'
self.sg.slave_driver = self.mock_driver
def test__init__(self):
sg = DiffractometerScannableGroup(
'sixc', MockDiffcalc(6), self.grp, self.mock_driver)
assert sg.slave_driver == self.mock_driver
def testAsynchronousMoveToWithNones(self):
self.sg.asynchronousMoveTo([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
self.sg.asynchronousMoveTo([None, None, 3.2, None, 5.2, None])
assert list(self.sg.getPosition()) == [1., 2., 3.2, 4., 5.2, 6., 90, 91]
self.mock_driver.triggerAsynchronousMove.assert_called_with(
[None, None, 3.2, None, 5.2, None])
def testIsBusyWithSlave(self):
self.mock_driver.isBusy.return_value = True
assert self.sg.isBusy()
### overridden
def testInit(self):
assert list(self.sg.getPosition()) == [0., 0., 0., 0., 0., 0., 90, 91]
def testAsynchronousMoveTo(self):
self.sg.asynchronousMoveTo([1, 2.0, 3, 4, 5, 6])
assert list(self.sg.getPosition()) == [1., 2., 3., 4., 5., 6., 90, 91]
class TestDiffractometerScannableGroupWithFailingAngleCalculator(object):
def setup_method(self):
class BadMockAngleCalculator:
def angles_to_hkl(self, pos):
raise Exception("Problem")
dummy = createDummyAxes(['alpha', 'delta', 'gamma', 'omega', 'chi',
'phi'])
self.group = ScannableGroup('grp', dummy)
self.group.configure()
self.sg = DiffractometerScannableGroup(
'sixc', BadMockAngleCalculator(), self.group)
def testGetPosition(self):
self.sg.getPosition()
def testSimulateMoveTo(self):
assert (self.sg.simulateMoveTo([1., 2., 3., 4., 5., 6.])
== "Error: Problem")

View File

@@ -0,0 +1,222 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
import mock
import nose
import unittest
from diffcalc.gdasupport.scannable.diffractometer import \
DiffractometerScannableGroup
from diffcalc.gdasupport.scannable.hkl import Hkl
from test.diffcalc.gdasupport.scannable.mockdiffcalc import MockDiffcalc
import pytest
try:
from gda.device.scannable.scannablegroup import ScannableGroup
except ImportError:
from diffcalc.gdasupport.minigda.scannable import ScannableGroup
try:
from gdascripts.pd.dummy_pds import DummyPD # @UnusedImport
except ImportError:
from diffcalc.gdasupport.minigda.scannable import DummyPD
def createDummyAxes(names):
result = []
for name in names:
result.append(DummyPD(name))
return result
PARAM_DICT = {'theta': 1, '2theta': 12., 'Bin': 123., 'Bout': 1234.,
'azimuth': 12345}
class Popper:
def __init__(self, *items):
self.items = list(items)
def __call__(self, *args):
return self.items.pop(0)
class TestHkl(object):
def setup_method(self):
self.mock_dc_module = mock.Mock()
self.mockSixc = mock.Mock(spec=DiffractometerScannableGroup)
self.hkl = Hkl('hkl', self.mockSixc, self.mock_dc_module)
def testInit(self):
self.mock_dc_module.angles_to_hkl.return_value = ([1, 2, 3], PARAM_DICT)
assert self.hkl.getPosition() == [1, 2, 3]
def testAsynchronousMoveTo(self):
self.mock_dc_module.hkl_to_angles.return_value = ([6, 5, 4, 3, 2, 1],
None)
self.hkl.asynchronousMoveTo([1, 0, 1])
self.mock_dc_module.hkl_to_angles.assert_called_with(1, 0, 1)
self.mockSixc.asynchronousMoveTo.assert_called_with([6, 5, 4, 3, 2, 1])
def testGetPosition(self):
self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
assert self.hkl.getPosition() == [1, 0, 1]
self.mock_dc_module.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
def testAsynchronousMoveToWithNonesOutsideScan(self):
self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1],
PARAM_DICT)
self.mock_dc_module.hkl_to_angles.return_value = ([12, 5, 4, 3, 2, 1],
PARAM_DICT) # <- 2,0,1
self.hkl.asynchronousMoveTo([2, 0, None])
self.mock_dc_module.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
self.mock_dc_module.hkl_to_angles.assert_called_with(2, 0, 1)
self.mockSixc.asynchronousMoveTo.assert_called_with(
[12, 5, 4, 3, 2, 1])
def testAsynchronousMoveToWithNonesInScan(self):
self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
self.hkl.atScanStart()
# should not be used:
self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
self.mock_dc_module.hkl_to_angles.return_value = ([12, 5, 4, 3, 2, 1],
PARAM_DICT)
self.hkl.asynchronousMoveTo([2, 0, None])
# atScanStart:
self.mock_dc_module.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
self.mock_dc_module.hkl_to_angles.assert_called_with(2, 0, 1)
self.mockSixc.asynchronousMoveTo.assert_called_with(
[12, 5, 4, 3, 2, 1])
def testAsynchronousMoveToWithNonesInScanAfterCommandFailure(self):
# should be forgotten:
self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
self.hkl.atScanStart()
self.hkl.atCommandFailure()
self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
self.mock_dc_module.hkl_to_angles.return_value = (
[12.1, 5.1, 4.1, 3.1, 2.1, 1.1], PARAM_DICT)
self.hkl.asynchronousMoveTo([2, 0, None])
self.mock_dc_module.angles_to_hkl.assert_called_with(
[6.1, 5.1, 4.1, 3.1, 2.1, 1.1])
self.mock_dc_module.hkl_to_angles.assert_called_with(2, 0, 1)
self.mockSixc.asynchronousMoveTo.assert_called_with(
[12.1, 5.1, 4.1, 3.1, 2.1, 1.1])
def testAsynchronousMoveToWithNonesInScanAfterAtScanEnd(self):
self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
self.hkl.atScanStart()
self.hkl.atScanEnd()
self.mockSixc.getPosition.return_value = [6.1, 5.1, 4.1, 3.1, 2.1, 1.1]
self.mock_dc_module.hkl_to_angles.return_value = (
[12.1, 5.1, 4.1, 3.1, 2.1, 1.1], PARAM_DICT)
self.hkl.asynchronousMoveTo([2, 0, None])
self.mock_dc_module.angles_to_hkl.assert_called_with(
[6.1, 5.1, 4.1, 3.1, 2.1, 1.1])
self.mock_dc_module.hkl_to_angles.assert_called_with(2, 0, 1)
self.mockSixc.asynchronousMoveTo.assert_called_with(
[12.1, 5.1, 4.1, 3.1, 2.1, 1.1])
def testIsBusy(self):
self.mockSixc.isBusy.return_value = False
assert not self.hkl.isBusy()
self.mockSixc.isBusy.assert_called()
def testWaitWhileBusy(self):
self.hkl.waitWhileBusy()
self.mockSixc.waitWhileBusy.assert_called()
def testWhereMoveTo(self):
# just check for exceptions
self.mock_dc_module.hkl_to_angles.return_value = ([6, 5, 4, 3, 2, 1],
PARAM_DICT)
self.mockSixc.getName.return_value = 'sixc'
self.mockSixc.getInputNames.return_value = ['alpha', 'delta', 'gamma',
'omega', 'chi', 'phi']
print self.hkl.simulateMoveTo((1.23, 0, 0))
def testDisp(self):
print self.hkl.__repr__()
class TestHklReturningVirtualangles(TestHkl):
def setup_method(self):
TestHkl.setup_method(self)
self.hkl = Hkl('hkl', self.mockSixc, self.mock_dc_module,
['theta', '2theta', 'Bin', 'Bout', 'azimuth'])
def testInit(self):
self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
assert self.hkl.getPosition() == [1, 0, 1, 1, 12, 123, 1234, 12345]
def testGetPosition(self):
self.mockSixc.getPosition.return_value = [6, 5, 4, 3, 2, 1]
self.mock_dc_module.angles_to_hkl.return_value = ([1, 0, 1], PARAM_DICT)
assert self.hkl.getPosition() == [1, 0, 1, 1, 12, 123, 1234, 12345]
self.mock_dc_module.angles_to_hkl.assert_called_with([6, 5, 4, 3, 2, 1])
class TestHklWithFailingAngleCalculator(object):
def setup_method(self):
class BadMockAngleCalculator:
def angles_to_hkl(self, pos):
raise Exception("Problem in angles_to_hkl")
dummy = createDummyAxes(['alpha', 'delta', 'gamma', 'omega', 'chi',
'phi'])
self.group = ScannableGroup('grp', dummy)
self.SixCircleGammaOnArmGeometry = DiffractometerScannableGroup(
'SixCircleGammaOnArmGeometry', MockDiffcalc(6), self.group)
self.hkl = Hkl('hkl', self.SixCircleGammaOnArmGeometry,
BadMockAngleCalculator())
def testGetPosition(self):
with pytest.raises(Exception):
self.hkl.getPosition(None)
def test__repr__(self):
assert self.hkl.__repr__() == "<hkl: Problem in angles_to_hkl>"
def test__str__(self):
assert self.hkl.__str__() == "<hkl: Problem in angles_to_hkl>"
def testComponentGetPosition(self):
with pytest.raises(Exception):
self.hkl.h.getPosition(None)
def testComponent__repr__(self):
raise nose.SkipTest()
assert self.hkl.h.__repr__() == "<h: Problem in angles_to_hkl>"
def testComponent__str__(self):
raise nose.SkipTest()
assert self.hkl.h.__str__() == "<h: Problem in angles_to_hkl>"

View File

@@ -0,0 +1,38 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
import unittest
from diffcalc.gdasupport.scannable.parameter import \
DiffractionCalculatorParameter
from test.diffcalc.gdasupport.scannable.mockdiffcalc import \
MockParameterManager
class TestDiffractionCalculatorParameter(object):
def setup_method(self):
self.dcp = DiffractionCalculatorParameter('dcp', 'betain',
MockParameterManager())
def testAsynchronousMoveToAndGetPosition(self):
self.dcp.asynchronousMoveTo(12.3)
assert self.dcp.getPosition() == 12.3
def testIsBusy(self):
assert not self.dcp.isBusy()

View File

@@ -0,0 +1,102 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
from math import pi
import unittest
from pytest import approx
try:
from numpy import matrix
except ImportError:
from numjy import matrix
from diffcalc.gdasupport.scannable.simulation import SimulatedCrystalCounter, \
Gaussian
from diffcalc.hkl.vlieg.geometry import Fourc
from diffcalc.util import nearlyEqual
from test.tools import mneq_
class MockScannable(object):
def __init__(self):
self.pos = None
def getPosition(self):
return self.pos
class MockEquation(object):
def __call__(self, dh, dk, dl):
self.dHkl = dh, dk, dl
return 1
class TestSimulatedCrystalCounter(object):
def setup_method(self):
self.diff = MockScannable()
self.wl = MockScannable()
self.wl.pos = 1.
self.eq = MockEquation()
self.scc = SimulatedCrystalCounter('det', self.diff, Fourc(), self.wl,
self.eq)
def testInit(self):
assert list(self.scc.getInputNames()) == ['det_count']
assert list(self.scc.getExtraNames()) == []
assert self.scc.chiMissmount == 0.
assert self.scc.phiMissmount == 0.
def testCalcUB(self):
UB = matrix([[2 * pi, 0, 0], [0, 2 * pi, 0], [0, 0, 2 * pi]])
mneq_(self.scc.UB, UB)
def testGetHkl(self):
self.diff.pos = [60, 30, 0, 0]
hkl = self.scc.getHkl()
assert hkl == approx((1, 0, 0))
self.diff.pos = [60, 31, 0, 0]
hkl = self.scc.getHkl()
assert hkl == approx((0.999847695156391, 0.017452406437283574, 0))
def testGetPosition(self):
self.diff.pos = [60, 30, 0, 0]
self.scc.asynchronousMoveTo(2)
count = self.scc.getPosition()
assert self.eq.dHkl == approx((0, 0, 0))
assert count == 2
self.diff.pos = [60, 31, 0, 0]
count = self.scc.getPosition()
dHkl = (0.999847695156391 - 1, .017452406437283574, 0)
assert self.eq.dHkl == approx(dHkl)
assert count == 2
def test__repr__(self):
self.diff.pos = [60, 30, 0, 0]
print self.scc.__repr__()
class TestGaussianEquation(object):
def setup_method(self):
self.eq = Gaussian(1.)
def test__call__(self):
assert self.eq(0, 0, 0) == 0.3989422804014327

View File

@@ -0,0 +1,40 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
import unittest
from diffcalc.gdasupport.scannable.wavelength import Wavelength
try:
from gdascripts.pd.dummy_pds import DummyPD
except ImportError:
from diffcalc.gdasupport.minigda.scannable import DummyPD
class TestWavelength(object):
def setup_method(self):
self.en = DummyPD('en')
self.wl = Wavelength('wl', self.en)
def testIt(self):
self.en.asynchronousMoveTo(12.39842)
assert self.wl.getPosition() == 1
self.wl.asynchronousMoveTo(1.)
assert self.wl.getPosition() == 1.
assert self.en.getPosition() == 12.39842

View File

@@ -0,0 +1,180 @@
###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc. If not, see <http://www.gnu.org/licenses/>.
###
from math import pi
from nose.tools import eq_, raises # @UnresolvedImport
from nose.plugins.skip import Skip, SkipTest # @UnresolvedImport
from diffcalc.hardware import ScannableHardwareAdapter
from diffcalc.gdasupport.minigda.scannable import SingleFieldDummyScannable,\
ScannableGroup
from diffcalc.hkl.you.geometry import SixCircle
from diffcalc.ub.persistence import UbCalculationNonPersister
import diffcalc.util # @UnusedImport
try:
from numpy import matrix
except ImportError:
from numjy import matrix
import diffcalc.gdasupport.minigda.command
from test.tools import mneq_
from diffcalc import settings
import diffcalc.hkl.you.calc
diffcalc.gdasupport.minigda.command.ROOT_NAMESPACE_DICT = globals()
pos = diffcalc.gdasupport.minigda.command.Pos()
en = SingleFieldDummyScannable('en') # keV
mu = SingleFieldDummyScannable('mu')
delta = SingleFieldDummyScannable('delta')
gam = SingleFieldDummyScannable('gam')
eta = SingleFieldDummyScannable('eta')
chi = SingleFieldDummyScannable('chi')
phi = SingleFieldDummyScannable('phi')
sixc_group = ScannableGroup('sixc', (mu, delta, gam, eta, chi, phi))
ubcalc_no = 1
you = None
def setup_module():
global you
settings.hardware = ScannableHardwareAdapter(sixc_group, en)
settings.geometry = SixCircle()
settings.ubcalc_persister = UbCalculationNonPersister()
settings.axes_scannable_group = sixc_group
settings.energy_scannable = en
settings.ubcalc_strategy = diffcalc.hkl.you.calc.YouUbCalcStrategy()
settings.angles_to_hkl_function = diffcalc.hkl.you.calc.youAnglesToHkl
from diffcalc.gdasupport import you
reload(you)
"""
All the components used here are well tested. This integration test is
mainly to get output for the manual, to help when tweaking the user
interface, and to make sure it all works together.
"""
#
# PRINT_WITH_USER_SYNTAX = True
# for name, obj in self.objects.iteritems():
# if inspect.ismethod(obj):
# globals()[name] = wrap_command_to_print_calls(
# obj, PRINT_WITH_USER_SYNTAX)
# else:
# globals()[name] = obj
# pos = wrap_command_to_print_calls(Pos(globals()), PRINT_WITH_USER_SYNTAX)
def call_scannable(scn):
print '\n>>> %s' % scn.name
print scn.__str__()
def test_help_visually():
print "\n>>> help ub"
help(you.ub)
print "\n>>> help hkl"
help(you.hkl)
print "\n>>> help newub"
help(you.newub)
def test_axes():
call_scannable(you.sixc) # @UndefinedVariable
call_scannable(phi)
def test_with_no_ubcalc():
you.ub()
you.showref()
call_scannable(you.hkl)
def _orient():
global ubcalc_no
pos(you.wl, 1)
call_scannable(en) # like typing en (or en())
you.newub('test' + str(ubcalc_no))
ubcalc_no += 1
you.setlat('cubic', 1, 1, 1, 90, 90, 90)
you.c2th([1, 0, 0])
pos(you.sixc, [0, 60, 0, 30, 0, 0]) # @UndefinedVariable
you.addref([1, 0, 0], 'ref1')
you.c2th([0, 1, 0])
pos(phi, 90)
you.addref([0, 1, 0], 'ref2')
def test__orientation_phase():
_orient()
you.ub()
you.checkub()
you.showref()
U = matrix('1 0 0; 0 1 0; 0 0 1')
UB = U * 2 * pi
mneq_(you.ubcalc.U, U)
mneq_(you.ubcalc.UB, UB)
def test_hkl_read():
_orient()
call_scannable(you.hkl)
def test_help_con():
help(you.con)
def test_constraint_mgmt():
diffcalc.util.DEBUG = True
you.con() # TODO: show constrained values underneath
def test_hkl_move_no_constraints():
raise SkipTest()
_orient()
pos(you.hkl, [1, 0, 0])
def test_hkl_move_no_values():
raise SkipTest()
_orient()
you.con(mu)
you.con(gam)
you.con('a_eq_b')
you.con('a_eq_b')
pos(you.hkl, [1, 0, 0])
def test_hkl_move_okay():
_orient()
you.ub()
you.con(mu)
you.con(gam)
you.con('a_eq_b')
pos(you.mu_con, 0)
pos(you.gam_con, 0) # TODO: Fails with qaz=90
pos(you.hkl, [1, 1, 0]) # TODO: prints DEGENERATE. necessary?
call_scannable(you.sixc) # @UndefinedVariable
@raises(TypeError)
def test_usage_error_signature():
you.c2th('wrong arg', 'wrong arg')
@raises(TypeError)
def test_usage_error_inside():
you.setlat('wrong arg', 'wrong arg')