def test_can_add_multiple_conditions_in_order(self): mock_cond1 = mock_condition() mock_cond2 = mock_condition() o = DataEndpoint() o.add_condition(mock_cond1) o.add_condition(mock_cond2) assert o._conditions == [mock_cond1, mock_cond2]
def test_can_open_and_close_object(self): obj = DataEndpoint(name='mock_obj') with testfixtures.LogCapture(level=logging.DEBUG) as l: obj.open() assert len(l.records) == 1 assert_record_is(l.records[0], 'INFO', "Opening DataEndpoint(name='mock_obj')") obj.close() assert len(l.records) == 2 assert_record_is(l.records[1], 'INFO', "Closing DataEndpoint(name='mock_obj')")
def test_all_conditions_are_updated_regardless_of_result(self): c1 = mock_condition(return_value=False, str='Condition(1)') c2 = mock_condition(str='Condition(2)') o = DataEndpoint() o.add_condition(c1) o.add_condition(c2) o._update_conditions(value=4) assert not c1.check.called assert not c2.check.called c1.update.assert_called_once_with(value=4) c2.update.assert_called_once_with(value=4)
def test_shortcut_checks_when_one_fails(self): c1 = mock_condition(return_value=False, str='Condition(1)') c2 = mock_condition(str='Condition(2)') o = DataEndpoint() o.add_condition(c1) o.add_condition(c2) result, reason = o._check_conditions(value=3) assert not result assert reason == 'Condition(1)' c1.check.assert_called_once_with(value=3) assert c2.check.call_count == 0 assert not c1.update.called assert not c2.update.called
def test_all_conditions_checked(self): c1 = mock_condition(str='Condition(1)') c2 = mock_condition(str='Condition(2)') o = DataEndpoint() o.add_condition(c1) o.add_condition(c2) result, reason = o._check_conditions(value=1) assert result assert not reason c1.check.assert_called_once_with(value=1) c2.check.assert_called_once_with(value=1) assert not c1.update.called assert not c2.update.called
def test_can_add_conditions(self): mock_cond = mock_condition() o = DataEndpoint() o.add_condition(mock_cond) assert o._conditions == [mock_cond]