Esempio n. 1
0
    def test_choices(self) -> None:
        completer: utils.AutoCompleter[MockOption] = utils.AutoCompleter()

        option1 = MockOption(key='1', name='Testing 1')
        option2 = MockOption(key='2', name='Tester 2')

        completer.add(option1)
        completer.add(option2)

        assert completer.choices('') == [
            app_commands.Choice(name='Testing 1', value='1'),
            app_commands.Choice(name='Tester 2', value='2'),
        ]

        assert completer.choices(' Testing ') == [
            app_commands.Choice(name='Testing 1', value='1'),
        ]

        completer.update(
            map(
                lambda x: MockOption(name=f'Testing {x}', key=str(x)),
                range(50),
            ))

        choices = completer.choices(' Testing ')
        assert len(choices) == 25
Esempio n. 2
0
    def test_clear(self) -> None:
        completer: utils.AutoCompleter[MockOption] = utils.AutoCompleter()

        option1 = MockOption(key='1', name='Test 1')
        option2 = MockOption(key='2', name='Test 2')

        completer.update([option1, option2])

        completer.clear()

        assert completer.choices('') == []
Esempio n. 3
0
    def test_update(self) -> None:
        completer: utils.AutoCompleter[MockOption] = utils.AutoCompleter()

        option1 = MockOption(key='1', name='Test 1')
        option2 = MockOption(key='2', name='Test 2')

        completer.update([option1, option2])

        assert completer.choices('') == [
            app_commands.Choice(name='Test 1', value='1'),
            app_commands.Choice(name='Test 2', value='2'),
        ]
Esempio n. 4
0
    async def test_complete(self) -> None:
        completer: utils.AutoCompleter[MockOption] = utils.AutoCompleter()

        option1 = MockOption(key='1', name='Testing 1')
        option2 = MockOption(key='2', name='Tester 2')

        completer.add(option1)
        completer.add(option2)

        assert (await
                completer.complete(cast(Any, object()), ' Testing ')) == [
                    app_commands.Choice(name='Testing 1', value='1'),
                ]
Esempio n. 5
0
    def test_remove(self) -> None:
        completer: utils.AutoCompleter[MockOption] = utils.AutoCompleter()

        option1 = MockOption(key='1', name='Test 1')
        option2 = MockOption(key='2', name='Test 2')

        completer.update([option1, option2])

        completer.remove('1')

        with pytest.raises(KeyError):
            completer.remove('3')

        assert completer.choices('') == [
            app_commands.Choice(name='Test 2', value='2'),
        ]
Esempio n. 6
0
 def test_init(self) -> None:
     completer: utils.AutoCompleter[MockOption] = utils.AutoCompleter()
     assert completer is not None