예제 #1
0
    def test_private__deposit_group__method(self):
        obj = GrammarObject(label=None, keywords=[])
        mock_deposit = Mock()
        obj._deposit = mock_deposit

        obj._deposit_group(group=['a', 'b', 'c'], template=['a', 'b', 'c'])

        self.assertTrue(mock_deposit.call_count == 3)
예제 #2
0
    def test__deposit_group__raises_exception_if_arguments_do_not_have_the_same_length(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_deposit = Mock()
        obj._deposit = mock_deposit

        with self.assertRaisesRegex(Exception, 'length'):
            obj._deposit_group(group=['a', 'b'], template=['a'])

        self.assertTrue(mock_deposit.call_count == 0)
예제 #3
0
    def test__deposit_group__raises_exception_if_any_argument_is_not_a_list(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_deposit = Mock()
        obj._deposit = mock_deposit

        for group, template in [('a', ['a']), (['a'], 'a')]:
            with self.subTest(group=group, template=template):
                with self.assertRaisesRegex(Exception, 'list'):
                    obj._deposit_group(group=group, template=template)

                self.assertTrue(mock_deposit.call_count == 0)
예제 #4
0
    def test__deposit__does_not_invoke__deposit_group__if_expected_is_dict_and_key_is_optional_repeat_and_length_of_value_is_zero(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_comparable = Mock(return_value=True)
        mock_deposit_group = Mock()
        obj._is_comparable = mock_comparable
        obj._deposit_group = mock_deposit_group

        obj._deposit({'optional-repeat': []}, {'optional-repeat': []})

        self.assertTrue(mock_comparable.called)
        self.assertFalse(mock_deposit_group.called)
예제 #5
0
    def test__deposit__invokes__deposit_group__if_expected_is_dict_and_key_is_optional_and_value_length_is_greater_than_zero(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_comparable = Mock(return_value=True)
        mock_deposit_group = Mock()
        obj._is_comparable = mock_comparable
        obj._deposit_group = mock_deposit_group

        obj._deposit({'optional': ['a']}, {'optional': ['a']})

        self.assertTrue(mock_comparable.called)
        self.assertTrue(mock_deposit_group.called_with(['a'], ['a']))
예제 #6
0
    def test__deposit__invokes__deposit_group__if_expected_is_dict_and_key_is_group(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_comparable = Mock(return_value=True)
        mock_deposit_group = Mock()
        obj._is_comparable = mock_comparable
        obj._deposit_group = mock_deposit_group

        obj._deposit({'group': ['a', 'b', 'c']}, {'group': ['a', 'b', 'c']})

        self.assertTrue(mock_comparable.called)
        self.assertTrue(
            mock_deposit_group.called_with(['a', 'b', 'c'], ['a', 'b', 'c']))
예제 #7
0
    def test__deposit__invokes__deposit_group__for_each_group_if_expected_is_dict_and_key_is_optional_repeat_and_length_of_value_is_greater_than_zero(
            self):
        obj = GrammarObject(label=None, keywords=[])
        mock_comparable = Mock(return_value=True)
        mock_deposit_group = Mock()
        obj._is_comparable = mock_comparable
        obj._deposit_group = mock_deposit_group

        obj._deposit(
            {
                'optional-repeat': [['a', 'b', 'c'], ['a', 'b', 'c'],
                                    ['a', 'b', 'c']]
            }, {'optional-repeat': ['a', 'b', 'c']})

        self.assertTrue(mock_comparable.called)
        self.assertEqual(mock_deposit_group.call_count, 3)
        self.assertTrue(
            mock_deposit_group.called_with(['a', 'b', 'c'], ['a', 'b', 'c']))