def test_shift(self): state = policy.ParseState() with mock.patch.object(policy.ParseState, 'reduce') as mock_reduce: state.shift('token', 'value') self.assertEqual(state.tokens, ['token']) self.assertEqual(state.values, ['value']) mock_reduce.assert_called_once_with()
def test_extend_or_expr(self): state = policy.ParseState() mock_expr = mock.Mock() mock_expr.add_check.return_value = 'newcheck' result = state._extend_or_expr(mock_expr, 'or', 'check') self.assertEqual(result, [('or_expr', 'newcheck')]) mock_expr.add_check.assert_called_once_with('check')
def test_reduce_multi(self, mock_meth): state = policy.ParseState() state.tokens = ['tok1', 'tok2'] state.values = ['val1', 'val2'] state.reduce() self.assertEqual(state.tokens, ['tok3', 'tok4']) self.assertEqual(state.values, ['val3', 'val4']) mock_meth.assert_called_once_with('val1', 'val2')
def test_reduce_short(self, mock_meth): state = policy.ParseState() state.tokens = ['tok1'] state.values = ['val1'] state.reduce() self.assertEqual(state.tokens, ['tok1']) self.assertEqual(state.values, ['val1']) self.assertFalse(mock_meth.called)
def test_reduce_two(self, mock_meth2, mock_meth1): state = policy.ParseState() state.tokens = ['tok1', 'tok2', 'tok3'] state.values = ['val1', 'val2', 'val3'] state.reduce() self.assertEqual(state.tokens, ['tok5']) self.assertEqual(state.values, ['val5']) mock_meth1.assert_called_once_with('val2', 'val3') mock_meth2.assert_called_once_with('val1', 'val4')
def test_make_not_expr(self): state = policy.ParseState() result = state._make_not_expr('not', 'check') self.assertEqual(result, [('check', 'not check')])
def test_make_or_expr(self): state = policy.ParseState() result = state._make_or_expr('check1', 'or', 'check2') self.assertEqual(result, [('or_expr', ['check1', 'check2'])])
def test_wrap_check(self): state = policy.ParseState() result = state._wrap_check('(', 'the_check', ')') self.assertEqual(result, [('check', 'the_check')])
def test_result(self): state = policy.ParseState() state.tokens = ['token'] state.values = ['value'] self.assertEqual(state.result, 'value')
def test_result_unreduced(self): state = policy.ParseState() state.tokens = ['tok1', 'tok2'] state.values = ['val1', 'val2'] self.assertRaises(ValueError, lambda: state.result)
def test_result_empty(self): state = policy.ParseState() self.assertRaises(ValueError, lambda: state.result)
def test_init(self): state = policy.ParseState() self.assertEqual(state.tokens, []) self.assertEqual(state.values, [])