コード例 #1
0
def test_services():
    """Tests all services (except iSpeech) using a single word.

    Retrieving, processing, and playing of word "test" will be tested,
    using default (or first available) options. To expose a specific
    value of an option for testing purposes only, use test_default.
    """
    require_key = ['iSpeech']
    it_fails = ['Baidu Translate', 'Duden', 'NAVER Translate']

    with anki_running() as anki_app:

        from awesometts import addon

        def success_if_path_exists_and_plays(path):
            import os

            # play (and hope that we have no errors)
            addon.player.preview(path)

            # and after making sure that the path exists
            if os.path.exists(path):
                # claim success
                raise Success()

        callbacks = {
            'okay': success_if_path_exists_and_plays,
            'fail': re_raise
        }

        for svc_id, name, in addon.router.get_services():

            if name in require_key:
                warn(f'Skipping {name} (no API key)')
                continue

            if name in it_fails:
                warn(f'Skipping {name} - known to fail; if you can fix it, please open a PR')
                continue

            print(f'Testing {name}')

            options = get_default_options(addon, svc_id)

            with raises(Success):
                addon.router(
                    svc_id=svc_id,
                    text='test',
                    options=options,
                    callbacks=callbacks,
                    async_variable=False
                )
コード例 #2
0
def test_property_descriptor():
    with anki_running():
        from night_mode.internals import PropertyDescriptor

        class Test:
            @PropertyDescriptor
            def test(self):
                return 'x'

        t = Test()

        assert t.test == 'x'
        assert getattr(t, 'test') == 'x'
コード例 #3
0
def test_addon_initialization():
    with anki_running() as anki_app:
        import awesometts
        awesometts.browser_menus()     # mass generator and MP3 stripper
        awesometts.cache_control()     # automatically clear the media cache regularly
        awesometts.cards_button()      # on-the-fly templater helper in card view
        awesometts.config_menu()       # provides access to configuration dialog
        awesometts.editor_button()     # single audio clip generator button
        awesometts.reviewer_hooks()    # on-the-fly playback/shortcuts, context menus
        awesometts.sound_tag_delays()  # delayed playing of stored [sound]s in review
        awesometts.temp_files()        # remove temporary files upon session exit
        awesometts.update_checker()    # if enabled, runs the add-on update checker
        awesometts.window_shortcuts()  # enable/update shortcuts for add-on windows
コード例 #4
0
def test_property_descriptor():
    with anki_running():
        from night_mode.internals import PropertyDescriptor

        class Test:

            @PropertyDescriptor
            def test(self):
                return 'x'

        t = Test()

        assert t.test == 'x'
        assert getattr(t, 'test') == 'x'
コード例 #5
0
ファイル: test_styler.py プロジェクト: zjosua/Anki-Night-Mode
def test_appends():

    with anki_running():
        from night_mode.stylers import Styler
        from night_mode.internals import appends_in_night_mode

        class SomeElement:

            my_css = 'css'

        class SomeElementStyler(Styler):
            target = SomeElement

            @appends_in_night_mode
            def my_css(self):
                return ' and my injection!'

        element = SomeElement()
        assert SomeElementStyler.additions['my_css'].value(element) == ' and my injection!'
コード例 #6
0
def test_my_addon():
    with anki_running() as anki_app:
        print(f'got anki instance {anki_app}')
        assert True