コード例 #1
0
 def setUp(self):
     self.hklcalc = Mock()
     self.hklcalc.constraints.report_constraints_lines.return_value = ['report1', 'report2']
     self.commands = YouHklCommands(self.hklcalc)
コード例 #2
0
class TestYouHklCommands:

    def setUp(self):
        self.hklcalc = Mock()
        self.hklcalc.constraints.report_constraints_lines.return_value = ['report1', 'report2']
        self.commands = YouHklCommands(self.hklcalc)

#    def test__str__(self):
#        self.hklcalc.__str__.return_value = 'abc'
#        eq_(self.commands.__str__(), 'abc')

    def test_con_with_1_constraint(self):
        self.commands.con('cona')
        self.hklcalc.constraints.constrain.assert_called_with('cona')

    def test_con_with_1_constraint_with_value(self):
        self.commands.con('cona', 123)
        self.hklcalc.constraints.constrain.assert_called_with('cona')
        self.hklcalc.constraints.set_constraint.assert_called_with('cona', 123)

    def test_con_with_3_constraints(self):
        self.commands.con('cona', 'conb', 'conc')
        self.hklcalc.constraints.clear_constraints.assert_called()
        calls = [call('cona'), call('conb'), call('conc')]
        self.hklcalc.constraints.constrain.assert_has_calls(calls)

    def test_con_with_3_constraints_first_val(self):
        self.commands.con('cona', 1, 'conb', 'conc')
        self.hklcalc.constraints.clear_constraints.assert_called()
        calls = [call('cona'), call('conb'), call('conc')]
        self.hklcalc.constraints.constrain.assert_has_calls(calls)
        self.hklcalc.constraints.set_constraint.assert_called_with('cona', 1)

    def test_con_with_3_constraints_second_val(self):
        self.commands.con('cona', 'conb', 2, 'conc')
        self.hklcalc.constraints.clear_constraints.assert_called()
        calls = [call('cona'), call('conb'), call('conc')]
        self.hklcalc.constraints.constrain.assert_has_calls(calls)
        self.hklcalc.constraints.set_constraint.assert_called_with('conb', 2)
        
    def test_con_with_3_constraints_third_val(self):
        self.commands.con('cona', 'conb', 'conc', 3)
        self.hklcalc.constraints.clear_constraints.assert_called()
        calls = [call('cona'), call('conb'), call('conc')]
        self.hklcalc.constraints.constrain.assert_has_calls(calls)
        self.hklcalc.constraints.set_constraint.assert_called_with('conc', 3)
        
    def test_con_with_3_constraints_all_vals(self):
        self.commands.con('cona', 1, 'conb', 2, 'conc', 3)
        self.hklcalc.constraints.clear_constraints.assert_called()
        calls = [call('cona'), call('conb'), call('conc')]
        self.hklcalc.constraints.constrain.assert_has_calls(calls)
        calls = [call('cona', 1), call('conb', 2), call('conc', 3)]
        self.hklcalc.constraints.set_constraint.assert_has_calls(calls)

        
    def test_con_messages_and_help_visually(self):
        self.commands.con()
        print "**"
        print self.commands.con.__doc__
        
    def test_con_message_display_whenn_selecting_an_unimplmented_mode(self):
        self.hklcalc.constraints.is_fully_constrained.return_value = True
        self.hklcalc.constraints.is_current_mode_implemented.return_value = False
        self.commands.con('phi', 'chi', 'eta')