class TestConstraintManagerWithFourCircles:

    def setUp(self):
        self.cm = YouConstraintManager(None, {NUNAME: 0, 'mu': 0})    

    def test_init(self):
        eq_(self.cm.all, {NUNAME: 0, 'mu': 0})
        eq_(self.cm.detector, {NUNAME: 0})
        eq_(self.cm.reference, {})
        eq_(self.cm.sample, {'mu': 0})
        eq_(self.cm.naz, {})

    def test_build_initial_display_table_with_fixed_detector(self):
        self.cm = YouConstraintManager(None, {NUNAME: 0})
        print self.cm.build_display_table_lines()
        eq_(self.cm.build_display_table_lines(),
            ['    REF        SAMP',
             '    ======     ======',
             '    a_eq_b     mu',
             '    alpha      eta',
             '    beta       chi',
             '    psi        phi'])
        
    def test_build_initial_display_table_with_fixed_sample(self):
        self.cm = YouConstraintManager(None, {'mu': 0})
        print self.cm.build_display_table_lines()
        eq_(self.cm.build_display_table_lines(),
            ['    DET        REF        SAMP',
             '    ======     ======     ======',
             '    delta      a_eq_b     eta',
             '    %s     alpha      chi' % NUNAME.ljust(6),
             '    qaz        beta       phi',
             '    naz        psi'])
        
    def test_build_initial_display_table_for_four_circle(self):
        self.cm = YouConstraintManager(None, {'mu': 0, NUNAME: 0})
        print self.cm.build_display_table_lines()
        eq_(self.cm.build_display_table_lines(),
            ['    REF        SAMP',
             '    ======     ======',
             '    a_eq_b     eta',
             '    alpha      chi',
             '    beta       phi',
             '    psi'])
        
    def test_constrain_fixed_detector_angle(self):
        assert_raises(DiffcalcException, self.cm.constrain, 'delta')
        assert_raises(DiffcalcException, self.cm.constrain, NUNAME)
        assert_raises(DiffcalcException, self.cm.constrain, 'naz')
        assert_raises(DiffcalcException, self.cm.constrain, 'qaz')

    def test_unconstrain_fixed_detector_angle(self):
        assert_raises(DiffcalcException, self.cm.unconstrain, 'delta')
        assert_raises(DiffcalcException, self.cm.unconstrain, NUNAME)
        assert_raises(DiffcalcException, self.cm.unconstrain, 'naz')
        assert_raises(DiffcalcException, self.cm.unconstrain, 'qaz')
        
    def test_set_constrain_fixed_detector_angle(self):
        assert_raises(DiffcalcException, self.cm.set_constraint, 'delta', 0)
        assert_raises(DiffcalcException, self.cm.set_constraint, NUNAME, 0)
        assert_raises(DiffcalcException, self.cm.set_constraint, 'naz', 0)
        assert_raises(DiffcalcException, self.cm.set_constraint, 'qaz', 0)
    
    @raises(DiffcalcException)
    def test_constrain_fixed_sample_angle(self):
        self.cm.constrain('mu')

    @raises(DiffcalcException)
    def test_unconstrain_fixed_sample_angle(self):
        self.cm.unconstrain('mu')

    @raises(DiffcalcException)
    def test_set_constrain_fixed_sample_angle(self):
        self.cm.set_constraint('mu', 0)
Exemplo n.º 2
0
class TestConstraintManagerWithFourCircles:
    def setup_method(self):
        self.cm = YouConstraintManager(None, {NUNAME: 0, 'mu': 0})

    def test_init(self):
        eq_(self.cm.all, {NUNAME: 0, 'mu': 0})
        eq_(self.cm.detector, {NUNAME: 0})
        eq_(self.cm.reference, {})
        eq_(self.cm.sample, {'mu': 0})
        eq_(self.cm.naz, {})

    def test_build_initial_display_table_with_fixed_detector(self):
        self.cm = YouConstraintManager(None, {NUNAME: 0})
        print self.cm.build_display_table_lines()
        eq_(self.cm.build_display_table_lines(), [
            '    REF        SAMP', '    ------     ------',
            '    a_eq_b     mu', '    alpha      eta', '    beta       chi',
            '    psi        phi'
        ])

    def test_build_initial_display_table_with_fixed_sample(self):
        self.cm = YouConstraintManager(None, {'mu': 0})
        print self.cm.build_display_table_lines()
        eq_(self.cm.build_display_table_lines(), [
            '    DET        REF        SAMP',
            '    ------     ------     ------',
            '    delta      a_eq_b     eta',
            '    %s     alpha      chi' % NUNAME.ljust(6),
            '    qaz        beta       phi', '    naz        psi'
        ])

    def test_build_initial_display_table_for_four_circle(self):
        self.cm = YouConstraintManager(None, {'mu': 0, NUNAME: 0})
        print self.cm.build_display_table_lines()
        eq_(self.cm.build_display_table_lines(), [
            '    REF        SAMP', '    ------     ------',
            '    a_eq_b     eta', '    alpha      chi', '    beta       phi',
            '    psi'
        ])

    def test_constrain_fixed_detector_angle(self):
        assert_raises(DiffcalcException, self.cm.constrain, 'delta')
        assert_raises(DiffcalcException, self.cm.constrain, NUNAME)
        assert_raises(DiffcalcException, self.cm.constrain, 'naz')
        assert_raises(DiffcalcException, self.cm.constrain, 'qaz')

    def test_unconstrain_fixed_detector_angle(self):
        assert_raises(DiffcalcException, self.cm.unconstrain, 'delta')
        assert_raises(DiffcalcException, self.cm.unconstrain, NUNAME)
        assert_raises(DiffcalcException, self.cm.unconstrain, 'naz')
        assert_raises(DiffcalcException, self.cm.unconstrain, 'qaz')

    def test_set_constrain_fixed_detector_angle(self):
        assert_raises(DiffcalcException, self.cm.set_constraint, 'delta', 0)
        assert_raises(DiffcalcException, self.cm.set_constraint, NUNAME, 0)
        assert_raises(DiffcalcException, self.cm.set_constraint, 'naz', 0)
        assert_raises(DiffcalcException, self.cm.set_constraint, 'qaz', 0)

    @raises(DiffcalcException)
    def test_constrain_fixed_sample_angle(self):
        self.cm.constrain('mu')

    @raises(DiffcalcException)
    def test_unconstrain_fixed_sample_angle(self):
        self.cm.unconstrain('mu')

    @raises(DiffcalcException)
    def test_set_constrain_fixed_sample_angle(self):
        self.cm.set_constraint('mu', 0)
class TestConstraintManager:

    def setUp(self):
        self.hardware_monitor = Mock()
        self.hardware_monitor.get_position.return_value = (1.,) * 6
        self.hardware_monitor.get_axes_names.return_value = [
                                      'mu', 'delta', NUNAME, 'eta', 'chi', 'phi']
        self.cm = YouConstraintManager(self.hardware_monitor)

    def test_init(self):
        eq_(self.cm.all, {})
        eq_(self.cm.detector, {})
        eq_(self.cm.reference, {})
        eq_(self.cm.sample, {})
        eq_(self.cm.naz, {})

    def test_build_display_table(self):
        self.cm.constrain('qaz')
        self.cm.constrain('alpha')
        self.cm.constrain('eta')
        self.cm.set_constraint('qaz', 1.234)
        self.cm.set_constraint('eta', 99.)
        print self.cm.build_display_table_lines()
        eq_(self.cm.build_display_table_lines(),
            ['    DET        REF        SAMP',
             '    ======     ======     ======',
             '    delta      a_eq_b     mu',
             '    %s o-> alpha  --> eta' % NUNAME.ljust(6),
             '--> qaz        beta       chi',
             '    naz        psi        phi',
             '                          mu_is_%s' % NUNAME])


#"""
#    DET        REF        SAMP                  Available:
#    ======     ======     ======
#    delta      a_eq_b     mu                    3x samp:         80 of 80
#    nu     o-> alpha  --> eta                   2x samp and ref: chi & phi
#--> qaz        beta       chi                                    mu & eta
#    naz        psi        phi                                    chi=90 & mu=0
#                          mu_is_nu              2x samp and det: 0 of 6
#                                                3x samp:         0 of 4
#"""[1:-1]

    def test_unconstrain_okay(self):
        eq_(self.cm.all, {})
        self.cm.constrain('delta')
        self.cm.constrain('mu')
        eq_(self.cm.all, {'delta': None, 'mu': None})
        eq_(self.cm.unconstrain('delta'), None)
        eq_(self.cm.all, {'mu': None})
        
    def test_clear_constraints(self):
        self.cm.constrain('delta')
        self.cm.constrain('mu')
        self.cm.clear_constraints()
        eq_(self.cm.all, {})

    def test_unconstrain_bad(self):
        eq_(self.cm.all, {})
        eq_(self.cm.unconstrain('delta'), "Delta was not already constrained.")

    def test_constrain_det(self, pre={}):
        eq_(self.cm.all, pre)
        eq_(self.cm.constrain('delta'), None)
        eq_(self.cm.all, joined({'delta': None}, pre))
        eq_(self.cm.constrain('delta'), 'Delta is already constrained.')
        eq_(self.cm.all, joined({'delta': None}, pre))
        eq_(self.cm.constrain('naz'), 'Delta constraint replaced.')
        eq_(self.cm.all, joined({'naz': None}, pre))
        eq_(self.cm.constrain('delta'), 'Naz constraint replaced.')
        eq_(self.cm.all, joined({'delta': None}, pre))

    def test_constrain_det_one_preexisting_ref(self):
        self.cm.constrain('alpha')
        self.test_constrain_det({'alpha': None})

    def test_constrain_det_one_preexisting_samp(self):
        self.cm.constrain('phi')
        self.test_constrain_det({'phi': None})

    def test_constrain_det_one_preexisting_samp_and_ref(self):
        self.cm.constrain('alpha')
        self.cm.constrain('phi')
        self.test_constrain_det({'alpha': None, 'phi': None})

    def test_constrain_det_two_preexisting_samp(self):
        self.cm.constrain('chi')
        self.cm.constrain('phi')
        self.test_constrain_det({'chi': None, 'phi': None})

    def test_constrain_det_three_preexisting_other(self):
        self.cm.constrain('alpha')
        self.cm.constrain('phi')
        self.cm.constrain('chi')
        try:
            self.cm.constrain('delta')
            assert False
        except DiffcalcException, e:
            eq_(e.args[0], (
                "Delta could not be constrained. First un-constrain one of the"
                "\nangles alpha, chi or phi (with 'uncon')"))
Exemplo n.º 4
0
class TestConstraintManager:
    def setup_method(self):
        diffcalc.util.COLOURISE_TERMINAL_OUTPUT = False
        self.hardware_monitor = Mock()
        self.hardware_monitor.get_position.return_value = (1., ) * 6
        self.hardware_monitor.get_axes_names.return_value = [
            'mu', 'delta', NUNAME, 'eta', 'chi', 'phi'
        ]
        self.cm = YouConstraintManager(self.hardware_monitor)

    def test_init(self):
        eq_(self.cm.all, {})
        eq_(self.cm.detector, {})
        eq_(self.cm.reference, {})
        eq_(self.cm.sample, {})
        eq_(self.cm.naz, {})

    def test_build_display_table(self):
        self.cm.constrain('qaz')
        self.cm.constrain('alpha')
        self.cm.constrain('eta')
        self.cm.set_constraint('qaz', 1.234)
        self.cm.set_constraint('eta', 99.)
        print '\n'.join(self.cm.build_display_table_lines())
        eq_(self.cm.build_display_table_lines(), [
            '    DET        REF        SAMP',
            '    ------     ------     ------', '    delta      a_eq_b     mu',
            '    %s o-> alpha  --> eta' % NUNAME.ljust(6),
            '--> qaz        beta       chi', '    naz        psi        phi',
            '                          mu_is_%s' % NUNAME
        ])

#"""
#    DET        REF        SAMP                  Available:
#    ======     ======     ======
#    delta      a_eq_b     mu                    3x samp:         80 of 80
#    nu     o-> alpha  --> eta                   2x samp and ref: chi & phi
#--> qaz        beta       chi                                    mu & eta
#    naz        psi        phi                                    chi=90 & mu=0
#                          mu_is_nu              2x samp and det: 0 of 6
#                                                3x samp:         0 of 4
#"""[1:-1]

    def test_unconstrain_okay(self):
        eq_(self.cm.all, {})
        self.cm.constrain('delta')
        self.cm.constrain('mu')
        eq_(self.cm.all, {'delta': None, 'mu': None})
        eq_(self.cm.unconstrain('delta'), None)
        eq_(self.cm.all, {'mu': None})

    def test_clear_constraints(self):
        self.cm.constrain('delta')
        self.cm.constrain('mu')
        self.cm.clear_constraints()
        eq_(self.cm.all, {})

    def test_unconstrain_bad(self):
        eq_(self.cm.all, {})
        eq_(self.cm.unconstrain('delta'), "Delta was not already constrained.")

    def test_constrain_det(self, pre={}):
        eq_(self.cm.all, pre)
        eq_(self.cm.constrain('delta'), None)
        eq_(self.cm.all, joined({'delta': None}, pre))
        eq_(self.cm.constrain('delta'), 'Delta is already constrained.')
        eq_(self.cm.all, joined({'delta': None}, pre))
        eq_(self.cm.constrain('naz'), 'Delta constraint replaced.')
        eq_(self.cm.all, joined({'naz': None}, pre))
        eq_(self.cm.constrain('delta'), 'Naz constraint replaced.')
        eq_(self.cm.all, joined({'delta': None}, pre))

    def test_constrain_det_one_preexisting_ref(self):
        self.cm.constrain('alpha')
        self.test_constrain_det({'alpha': None})

    def test_constrain_det_one_preexisting_samp(self):
        self.cm.constrain('phi')
        self.test_constrain_det({'phi': None})

    def test_constrain_det_one_preexisting_samp_and_ref(self):
        self.cm.constrain('alpha')
        self.cm.constrain('phi')
        self.test_constrain_det({'alpha': None, 'phi': None})

    def test_constrain_det_two_preexisting_samp(self):
        self.cm.constrain('chi')
        self.cm.constrain('phi')
        self.test_constrain_det({'chi': None, 'phi': None})

    def test_constrain_det_three_preexisting_other(self):
        self.cm.constrain('alpha')
        self.cm.constrain('phi')
        self.cm.constrain('chi')
        try:
            self.cm.constrain('delta')
            assert False
        except DiffcalcException, e:
            eq_(e.args[0], (
                "Delta could not be constrained. First un-constrain one of the"
                "\nangles alpha, chi or phi (with 'uncon')"))