Ejemplo n.º 1
0
    def test__deposit__raises_exception_if_result_of__is_comparable__is_false(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_comparable = Mock(return_value=False)
        mock_syntax_error = Mock(side_effect=Exception)
        obj._is_comparable = mock_comparable
        obj._syntax_error = mock_syntax_error

        with self.assertRaises(Exception):
            obj._deposit(MockToken(1), MockToken(1))

        self.assertTrue(mock_comparable.called)
        self.assertTrue(mock_syntax_error.called)
Ejemplo n.º 2
0
    def test__deposit__does_not_raise_exception_if_expected_is_dict_and_key_is_any_and_given_object_matches(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_comparable = Mock(return_value=True)
        mock_syntax_error = Mock(side_effect=Exception)
        obj._is_comparable = mock_comparable
        obj._syntax_error = mock_syntax_error

        obj._deposit(
            1, {'any': [1, 2, 3, {
                'group': [MockToken(1), MockToken(5)]
            }]})

        self.assertTrue(mock_comparable.called)
        self.assertEqual(obj.children[0], 1)
        self.assertFalse(mock_syntax_error.called)
Ejemplo n.º 3
0
    def test__deposit__raises_exception_if_expected_is_dict_and_key_is_any_and_given_object_does_not_match(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_comparable = Mock(return_value=True)
        mock_syntax_error = Mock(side_effect=Exception)
        obj._is_comparable = mock_comparable
        obj._syntax_error = mock_syntax_error

        with self.assertRaises(Exception):
            obj._deposit(
                MockToken('a'), {
                    'any': [
                        MockToken(1), {
                            'group': [MockToken(2), MockToken(5)]
                        }, 'hello'
                    ]
                })

        self.assertTrue(mock_comparable.called)
        self.assertEqual(len(obj.children), 0)
        self.assertTrue(mock_syntax_error.called)