コード例 #1
0
def with_melani_system(monkeypatch, request):
    class Melani:
        KEYS = (
            '#',
            'S-',
            'P-',
            'C-',
            'T-',
            'H-',
            'V-',
            'R-',
            'I-',
            'A-',
            '-E',
            '-O',
            '-c',
            '-s',
            '-t',
            '-h',
            '-p',
            '-r',
            '*',
            '-i',
            '-e',
            '-a',
            '-o',
        )
        IMPLICIT_HYPHEN_KEYS = KEYS
        SUFFIX_KEYS = ()
        NUMBER_KEY = '#'
        NUMBERS = {
            'S-': '1-',
            'P-': '2-',
            'T-': '3-',
            'V-': '4-',
            'I-': '5-',
            '-O': '0-',
            '-c': '-6',
            '-t': '-7',
            '-p': '-8',
            '-i': '-9',
        }
        UNDO_STROKE_STENO = '*'
        ORTHOGRAPHY_RULES = []
        ORTHOGRAPHY_RULES_ALIASES = {}
        ORTHOGRAPHY_WORDLIST = None
        KEYMAPS = {}
        DICTIONARIES_ROOT = None
        DEFAULT_DICTIONARIES = ()

    registry = Registry()
    registry.register_plugin('system', 'Melani', Melani)
    old_system_name = system.NAME
    with monkeypatch.context() as mp:
        mp.setattr('plover.system.registry', registry)
        system.setup('Melani')
        yield
    system.setup(old_system_name)
コード例 #2
0
    def test_valid_macro_3(self, monkeypatch):
        r'''
        "TEFT": "=macro",

        TEFT   ""
        '''
        def macro(translator, stroke, cmdline):
            assert cmdline == ''
        registry = Registry()
        registry.register_plugin('macro', 'macro', macro)
        monkeypatch.setattr('plover.translation.registry', registry)
コード例 #3
0
    def test_valid_macro_2(self, monkeypatch):
        r'''
        "TEFT": "=macro: params with spaces   ",

        TEFT   ""
        '''
        def macro(translator, stroke, cmdline):
            assert cmdline == ' params with spaces   '
        registry = Registry()
        registry.register_plugin('macro', 'macro', macro)
        monkeypatch.setattr('plover.translation.registry', registry)
コード例 #4
0
def test_config(original_contents, original_config, config_update,
                validated_config_update, resulting_contents, monkeypatch,
                tmpdir):
    registry = Registry()
    registry.register_plugin('machine', 'Keyboard', Keyboard)
    registry.register_plugin('machine', 'Faky faky', FakeMachine)
    registry.register_plugin('system', 'English Stenotype', english_stenotype)
    registry.register_plugin('system', 'Faux système', FakeSystem)
    monkeypatch.setattr('plover.config.registry', registry)
    config_file = tmpdir / 'config.cfg'
    # Check initial contents.
    config_file.write_text(original_contents, encoding='utf-8')
    cfg = config.Config(config_file.strpath)
    if inspect.isclass(original_config):
        with pytest.raises(original_config):
            cfg.load()
        original_config = dict(DEFAULTS)
        cfg.clear()
    else:
        cfg.load()
    cfg_dict = cfg.as_dict()
    for name, value in original_config.items():
        assert cfg[name] == value
        assert cfg_dict[name] == value
    # Check updated contents.
    with ExitStack() as stack:
        if inspect.isclass(validated_config_update):
            stack.enter_context(pytest.raises(validated_config_update))
            validated_config_update = None
        elif validated_config_update is None:
            validated_config_update = config_update
        if isinstance(config_update, dict):
            cfg.update(**config_update)
        else:
            key, value = config_update
            cfg[key] = value
        if validated_config_update is not None:
            if isinstance(validated_config_update, dict):
                cfg_dict.update(validated_config_update)
            else:
                key, value = validated_config_update
                cfg_dict[key] = value
        assert cfg.as_dict() == cfg_dict
    config_file.write_text('', encoding='utf-8')
    cfg.save()
    if resulting_contents is None:
        resulting_contents = original_contents
    assert config_file.read_text(
        encoding='utf-8').strip() == dedent_strip(resulting_contents)
コード例 #5
0
ファイル: test_config.py プロジェクト: DanLanglois/plover
def test_config(original_contents, original_config,
                config_update, validated_config_update,
                resulting_contents, monkeypatch):
    registry = Registry()
    registry.register_plugin('machine', 'Keyboard', Keyboard)
    registry.register_plugin('machine', 'Faky faky', FakeMachine)
    registry.register_plugin('system', 'English Stenotype', english_stenotype)
    registry.register_plugin('system', 'Faux système', FakeSystem)
    monkeypatch.setattr('plover.config.registry', registry)
    # Check initial contents.
    f = make_config(original_contents)
    cfg = config.Config()
    if inspect.isclass(original_config):
        with pytest.raises(original_config):
            cfg.load(f)
        original_config = dict(DEFAULTS)
        cfg.clear()
    else:
        cfg.load(f)
    cfg_dict = cfg.as_dict()
    for name, value in original_config.items():
        assert cfg[name] == value
        assert cfg_dict[name] == value
    # Check updated contents.
    with ExitStack() as stack:
        if inspect.isclass(validated_config_update):
            stack.enter_context(pytest.raises(validated_config_update))
            validated_config_update = None
        elif validated_config_update is None:
            validated_config_update = config_update
        if isinstance(config_update, dict):
            cfg.update(**config_update)
        else:
            key, value = config_update
            cfg[key] = value
        if validated_config_update is not None:
            if isinstance(validated_config_update, dict):
                cfg_dict.update(validated_config_update)
            else:
                key, value = validated_config_update
                cfg_dict[key] = value
        assert cfg.as_dict() == cfg_dict
    f = make_config()
    cfg.save(f)
    if resulting_contents is None:
        resulting_contents = original_contents
    assert config_contents(f) == dedent_strip(resulting_contents)
コード例 #6
0
 def _setup(self, **kwargs):
     FakeMachine.instance = None
     self.reg = Registry()
     self.reg.register_plugin('machine', 'Fake', FakeMachine)
     self.kbd = FakeKeyboardEmulation()
     self.cfg = FakeConfig(**kwargs)
     self.events = []
     self.engine = FakeEngine(self.cfg, self.kbd)
     def hook_callback(hook, *args, **kwargs):
         self.events.append((hook, args, kwargs))
     for hook in self.engine.HOOKS:
         self.engine.hook_connect(hook, partial(hook_callback, hook))
     try:
         with mock.patch('plover.engine.registry', self.reg):
             yield
     finally:
         del self.reg
         del self.cfg
         del self.engine
         del self.events
コード例 #7
0
def with_korean_system(monkeypatch, request):
    class KoreanCAS:
        KEYS = (
            '1-', '2-', '3-', '4-', '5-',
            'ㅎ-', 'ㅁ-', 'ㄱ-', 'ㅈ-', 'ㄴ-',
            'ㄷ-', 'ㅇ-', 'ㅅ-', 'ㅂ-', 'ㄹ-',
            'ㅗ-', 'ㅏ-', 'ㅜ-',
            '-*', '-ㅓ', '-ㅣ',
            '-6', '-7', '-8', '-9', '-0',
            '-ㅎ', '-ㅇ', '-ㄹ', '-ㄱ', '-ㄷ',
            '-ㅂ', '-ㄴ', '-ㅅ', '-ㅈ', '-ㅁ',
        )
        IMPLICIT_HYPHEN_KEYS = (
            'ㅗ-', 'ㅏ-', 'ㅜ-',
            '-*', '-ㅓ', '-ㅣ',
        )
        SUFFIX_KEYS = ()
        NUMBER_KEY = None
        NUMBERS = {}
        UNDO_STROKE_STENO = '-ㅂㄴ'
        ORTHOGRAPHY_RULES = []
        ORTHOGRAPHY_RULES_ALIASES = {}
        ORTHOGRAPHY_WORDLIST = None
        KEYMAPS = {}
        DICTIONARIES_ROOT = None
        DEFAULT_DICTIONARIES = ()
    registry = Registry()
    registry.register_plugin('system', 'English Stenotype', english_stenotype)
    registry.register_plugin('system', 'Korean Modern C', KoreanCAS)
    old_system_name = system.NAME
    with monkeypatch.context() as mp:
        mp.setattr('plover.system.registry', registry)
        yield
    system.setup(old_system_name)
コード例 #8
0
ファイル: test_config.py プロジェクト: sunflowerpirate/plover
def test_config(original_contents, original_config,
                config_update, validated_config_update,
                resulting_contents, monkeypatch):
    registry = Registry()
    registry.register_plugin('machine', 'Keyboard', Keyboard)
    registry.register_plugin('machine', 'Faky faky', FakeMachine)
    registry.register_plugin('system', 'English Stenotype', english_stenotype)
    registry.register_plugin('system', 'Faux système', FakeSystem)
    monkeypatch.setattr('plover.config.registry', registry)
    # Check initial contents.
    f = make_config(original_contents)
    cfg = config.Config()
    if inspect.isclass(original_config):
        with pytest.raises(original_config):
            cfg.load(f)
        original_config = dict(DEFAULTS)
        cfg.clear()
    else:
        cfg.load(f)
    cfg_dict = cfg.as_dict()
    for name, value in original_config.items():
        assert cfg[name] == value
        assert cfg_dict[name] == value
    # Check updated contents.
    if inspect.isclass(validated_config_update):
        with pytest.raises(validated_config_update):
            cfg.update(**config_update)
        assert cfg.as_dict() == cfg_dict
    else:
        if validated_config_update is None:
            validated_config_update = config_update
        cfg.update(**config_update)
        cfg_dict.update(validated_config_update)
        assert cfg.as_dict() == cfg_dict
    f = make_config()
    cfg.save(f)
    if resulting_contents is None:
        resulting_contents = original_contents
    assert config_contents(f) == dedent_strip(resulting_contents)
コード例 #9
0
def engine(monkeypatch):
    FakeMachine.instance = None
    registry = Registry()
    registry.update()
    registry.register_plugin('machine', 'Fake', FakeMachine)
    monkeypatch.setattr('plover.config.registry', registry)
    monkeypatch.setattr('plover.engine.registry', registry)
    kbd = FakeKeyboardEmulation()
    cfg_file = tempfile.NamedTemporaryFile(prefix='plover',
                                           suffix='config',
                                           delete=False)
    try:
        cfg_file.close()
        cfg = Config(cfg_file.name)
        cfg['dictionaries'] = []
        cfg['machine_type'] = 'Fake'
        cfg['system_keymap'] = [(k, k) for k in system.KEYS]
        cfg.save()
        yield FakeEngine(cfg, kbd)
    finally:
        os.unlink(cfg_file.name)
コード例 #10
0
ファイル: test_config.py プロジェクト: p2edwards/plover
    def test_machine_specific_options(self):
        defaults = {k: v[0] for k, v in FakeMachine.get_option_info().items()}

        machine_name = 'machine foo'
        registry = Registry()
        registry.register_plugin('machine', machine_name, FakeMachine)
        with patch('plover.config.registry', registry):
            c = config.Config()
            
            # Check default value.
            actual = c.get_machine_specific_options(machine_name)
            self.assertEqual(actual, defaults)

            # Make sure setting a value is reflecting in the getter.
            options = {
                'stroption1': 'something',
                'intoption1': 5,
                'floatoption1': 5.9,
                'booloption1': False,
            }
            c.set_machine_specific_options(options, machine_name)
            actual = c.get_machine_specific_options(machine_name)
            expected = dict(list(defaults.items()) + list(options.items()))
            self.assertEqual(actual, expected)
            
            # Test loading a file. Unknown option is ignored.
            s = '\n'.join(('[machine foo]', 'stroption1 = foo', 
                           'intoption1 = 3', 'booloption1 = True', 
                           'booloption2 = False', 'unknown = True'))
            f = make_config(s)
            c.load(f)
            expected = {
                'stroption1': 'foo',
                'intoption1': 3,
                'booloption1': True,
                'booloption2': False,
            }
            expected = dict(list(defaults.items()) + list(expected.items()))
            actual = c.get_machine_specific_options(machine_name)
            self.assertEqual(actual, expected)
            
            # Test saving a file.
            f = make_config()
            c.save(f)
            self.assertEqual(f.getvalue().decode('utf-8'), s + '\n\n')
            
            # Test reading invalid values.
            s = '\n'.join(['[machine foo]', 'floatoption1 = None', 
                           'booloption2 = True'])
            f = make_config(s)
            c.load(f)
            expected = {
                'floatoption1': 1,
                'booloption2': True,
            }
            expected = dict(list(defaults.items()) + list(expected.items()))
            actual = c.get_machine_specific_options(machine_name)
            self.assertEqual(actual, expected)
            # Check we can get/set the current machine options.
            c.set_machine_type(machine_name)
            self.assertEqual(c.get_machine_specific_options(), expected)
            expected['stroption1'] = 'foobar'
            expected['booloption2'] = False
            expected['floatoption1'] = 42.0
            c.set_machine_specific_options(expected)
            self.assertEqual(c.get_machine_specific_options(), expected)
コード例 #11
0
class EngineTestCase(unittest.TestCase):
    @contextmanager
    def _setup(self, **kwargs):
        FakeMachine.instance = None
        self.reg = Registry()
        self.reg.register_plugin('machine', 'Fake', FakeMachine)
        self.kbd = FakeKeyboardEmulation()
        self.cfg = FakeConfig(**kwargs)
        self.events = []
        self.engine = FakeEngine(self.cfg, self.kbd)

        def hook_callback(hook, *args, **kwargs):
            self.events.append((hook, args, kwargs))

        for hook in self.engine.HOOKS:
            self.engine.hook_connect(hook, partial(hook_callback, hook))
        try:
            with mock.patch('plover.engine.registry', self.reg):
                yield
        finally:
            del self.reg
            del self.cfg
            del self.engine
            del self.events

    def test_engine(self):
        with self._setup():
            # Config load.
            self.assertEqual(self.engine.load_config(), True)
            self.assertEqual(self.events, [])
            # Startup.
            self.engine.start()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'initializing'), {}),
                ('machine_state_changed', ('Fake', 'connected'), {}),
                ('config_changed', (self.cfg.as_dict(), ), {}),
            ])
            self.assertIsNotNone(FakeMachine.instance)
            self.assertFalse(FakeMachine.instance.is_suppressed)
            # Output enabled.
            self.events = []
            self.engine.output = True
            self.assertEqual(self.events, [
                ('output_changed', (True, ), {}),
            ])
            self.assertTrue(FakeMachine.instance.is_suppressed)
            # Machine reconnection.
            self.events = []
            self.engine.reset_machine()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'stopped'), {}),
                ('machine_state_changed', ('Fake', 'initializing'), {}),
                ('machine_state_changed', ('Fake', 'connected'), {}),
            ])
            self.assertIsNotNone(FakeMachine.instance)
            self.assertTrue(FakeMachine.instance.is_suppressed)
            # No machine reset on keymap change.
            self.events = []
            new_keymap = list(zip(system.KEYS, reversed(system.KEYS)))
            config_update = {'system_keymap': new_keymap}
            self.assertNotEqual(FakeMachine.instance.keymap, new_keymap)
            self.engine.config = config_update
            self.assertEqual(self.events, [
                ('config_changed', (config_update, ), {}),
            ])
            self.assertEqual(FakeMachine.instance.keymap, new_keymap)
            # Output disabled
            self.events = []
            self.engine.output = False
            self.assertEqual(self.events, [
                ('output_changed', (False, ), {}),
            ])
            self.assertFalse(FakeMachine.instance.is_suppressed)
            # Stopped.
            self.events = []
            self.engine.quit(42)
            self.assertEqual(self.engine.join(), 42)
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'stopped'), {}),
                ('quit', (), {}),
            ])
            self.assertIsNone(FakeMachine.instance)

    def test_loading_dictionaries(self):
        def check_loaded_events(actual_events, expected_events):
            self.assertEqual(len(actual_events),
                             len(expected_events),
                             msg='events: %r' % self.events)
            for n, event in enumerate(actual_events):
                event_type, event_args, event_kwargs = event
                msg = 'event %u: %r' % (n, event)
                self.assertEqual(event_type, 'dictionaries_loaded', msg=msg)
                self.assertEqual(event_kwargs, {}, msg=msg)
                self.assertEqual(len(event_args), 1, msg=msg)
                self.assertIsInstance(event_args[0],
                                      StenoDictionaryCollection,
                                      msg=msg)
                self.assertEqual(
                    [(d.path, d.enabled, isinstance(d, ErroredDictionary))
                     for d in event_args[0].dicts],
                    expected_events[n],
                    msg=msg)
        with \
                make_dict(b'{}', 'json', 'valid1') as valid_dict_1, \
                make_dict(b'{}', 'json', 'valid2') as valid_dict_2, \
                make_dict(b'', 'json', 'invalid1') as invalid_dict_1, \
                make_dict(b'', 'json', 'invalid2') as invalid_dict_2, \
                self._setup():
            self.engine.start()
            for test in (
                    # Load one valid dictionary.
                [
                    [
                        # path, enabled
                        (valid_dict_1, True),
                    ],
                    [
                        # path, enabled, errored
                        (valid_dict_1, True, False),
                    ]
                ],
                    # Load another invalid dictionary.
                [[
                    (valid_dict_1, True),
                    (invalid_dict_1, True),
                ], [
                    (valid_dict_1, True, False),
                    (invalid_dict_1, True, True),
                ]],
                    # Disable first dictionary.
                [[
                    (valid_dict_1, False),
                    (invalid_dict_1, True),
                ],
                 [
                     (valid_dict_1, False, False),
                     (invalid_dict_1, True, True),
                 ]],
                    # Replace invalid dictonary with another invalid one.
                [[
                    (valid_dict_1, False),
                    (invalid_dict_2, True),
                ], [
                    (valid_dict_1, False, False),
                ],
                 [
                     (valid_dict_1, False, False),
                     (invalid_dict_2, True, True),
                 ]]):
                config_dictionaries = [
                    DictionaryConfig(path, enabled)
                    for path, enabled in test[0]
                ]
                self.events = []
                config_update = {
                    'dictionaries': list(config_dictionaries),
                }
                self.engine.config = dict(config_update)
                self.assertEqual(self.events[0],
                                 ('config_changed', (config_update, ), {}))
                check_loaded_events(self.events[1:], test[1:])
            # Simulate an outdated dictionary.
            self.events = []
            self.engine.dictionaries[valid_dict_1].timestamp -= 1
            self.engine.config = {}
            check_loaded_events(self.events, [[
                (invalid_dict_2, True, True),
            ], [
                (valid_dict_1, False, False),
                (invalid_dict_2, True, True),
            ]])
コード例 #12
0
ファイル: test_engine.py プロジェクト: MartyGentillon/plover
class EngineTestCase(unittest.TestCase):

    @contextmanager
    def _setup(self, **kwargs):
        FakeMachine.instance = None
        self.reg = Registry()
        self.reg.register_plugin('machine', 'Fake', FakeMachine)
        self.kbd = FakeKeyboardEmulation()
        self.cfg = FakeConfig(**kwargs)
        self.events = []
        self.engine = FakeEngine(self.cfg, self.kbd)
        def hook_callback(hook, *args, **kwargs):
            self.events.append((hook, args, kwargs))
        for hook in self.engine.HOOKS:
            self.engine.hook_connect(hook, partial(hook_callback, hook))
        try:
            with mock.patch('plover.engine.registry', self.reg):
                yield
        finally:
            del self.reg
            del self.cfg
            del self.engine
            del self.events

    def test_engine(self):
        with self._setup():
            # Config load.
            self.assertEqual(self.engine.load_config(), True)
            self.assertEqual(self.events, [])
            # Startup.
            self.engine.start()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'initializing'), {}),
                ('machine_state_changed', ('Fake', 'connected'), {}),
                ('config_changed', (self.cfg.as_dict(),), {}),
            ])
            self.assertIsNotNone(FakeMachine.instance)
            self.assertFalse(FakeMachine.instance.is_suppressed)
            # Output enabled.
            self.events = []
            self.engine.output = True
            self.assertEqual(self.events, [
                ('output_changed', (True,), {}),
            ])
            self.assertTrue(FakeMachine.instance.is_suppressed)
            # Machine reconnection.
            self.events = []
            self.engine.reset_machine()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'stopped'), {}),
                ('machine_state_changed', ('Fake', 'initializing'), {}),
                ('machine_state_changed', ('Fake', 'connected'), {}),
            ])
            self.assertIsNotNone(FakeMachine.instance)
            self.assertTrue(FakeMachine.instance.is_suppressed)
            # No machine reset on keymap change.
            self.events = []
            new_keymap = list(zip(system.KEYS, reversed(system.KEYS)))
            config_update = { 'system_keymap': new_keymap }
            self.assertNotEqual(FakeMachine.instance.keymap, new_keymap)
            self.engine.config = config_update
            self.assertEqual(self.events, [
                ('config_changed', (config_update,), {}),
            ])
            self.assertEqual(FakeMachine.instance.keymap, new_keymap)
            # Output disabled
            self.events = []
            self.engine.output = False
            self.assertEqual(self.events, [
                ('output_changed', (False,), {}),
            ])
            self.assertFalse(FakeMachine.instance.is_suppressed)
            # Stopped.
            self.events = []
            self.engine.quit()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'stopped'), {}),
            ])
            self.assertIsNone(FakeMachine.instance)

    def test_loading_dictionaries(self):
        def check_loaded_events(actual_events, expected_events):
            self.assertEqual(len(actual_events), len(expected_events), msg='events: %r' % self.events)
            for n, event in enumerate(actual_events):
                event_type, event_args, event_kwargs = event
                msg = 'event %u: %r' % (n, event)
                self.assertEqual(event_type, 'dictionaries_loaded', msg=msg)
                self.assertEqual(event_kwargs, {}, msg=msg)
                self.assertEqual(len(event_args), 1, msg=msg)
                self.assertIsInstance(event_args[0], StenoDictionaryCollection, msg=msg)
                self.assertEqual([
                    (d.path, d.enabled, isinstance(d, ErroredDictionary))
                    for d in event_args[0].dicts
                ], expected_events[n], msg=msg)
        with \
                make_dict(b'{}', 'json', 'valid1') as valid_dict_1, \
                make_dict(b'{}', 'json', 'valid2') as valid_dict_2, \
                make_dict(b'', 'json', 'invalid1') as invalid_dict_1, \
                make_dict(b'', 'json', 'invalid2') as invalid_dict_2, \
                self._setup():
            self.engine.start()
            for test in (
                # Load one valid dictionary.
                [[
                    # path, enabled
                    (valid_dict_1, True),
                ], [
                    # path, enabled, errored
                    (valid_dict_1, True, False),
                ]],
                # Load another invalid dictionary.
                [[
                    (valid_dict_1, True),
                    (invalid_dict_1, True),
                ], [
                    (valid_dict_1, True, False),
                    (invalid_dict_1, True, True),
                ]],
                # Disable first dictionary.
                [[
                    (valid_dict_1, False),
                    (invalid_dict_1, True),
                ], [
                    (valid_dict_1, False, False),
                    (invalid_dict_1, True, True),
                ]],
                # Replace invalid dictonary with another invalid one.
                [[
                    (valid_dict_1, False),
                    (invalid_dict_2, True),
                ], [
                    (valid_dict_1, False, False),
                ], [
                    (valid_dict_1, False, False),
                    (invalid_dict_2, True, True),
                ]]
            ):
                config_dictionaries = [
                    DictionaryConfig(path, enabled)
                    for path, enabled in test[0]
                ]
                self.events = []
                config_update = { 'dictionaries': list(config_dictionaries), }
                self.engine.config = dict(config_update)
                self.assertEqual(self.events[0], ('config_changed', (config_update,), {}))
                check_loaded_events(self.events[1:], test[1:])
            # Simulate an outdated dictionary.
            self.events = []
            self.engine.dictionaries[valid_dict_1].timestamp -= 1
            self.engine.config = {}
            check_loaded_events(self.events, [[
                (invalid_dict_2, True, True),
            ], [
                (valid_dict_1, False, False),
                (invalid_dict_2, True, True),
            ]])
コード例 #13
0
ファイル: test_engine.py プロジェクト: yonglehou/plover
class EngineTestCase(unittest.TestCase):
    @contextmanager
    def _setup(self, **kwargs):
        FakeMachine.instance = None
        self.reg = Registry()
        self.reg.register_plugin(
            'machine', EntryPoint.parse('Fake = test.test_engine:FakeMachine'))
        self.kbd = FakeKeyboardEmulation()
        self.cfg = FakeConfig(**kwargs)
        self.events = []
        self.engine = FakeEngine(self.cfg, self.kbd)

        def hook_callback(hook, *args, **kwargs):
            self.events.append((hook, args, kwargs))

        for hook in self.engine.HOOKS:
            self.engine.hook_connect(hook, partial(hook_callback, hook))
        try:
            with mock.patch('plover.engine.registry', self.reg):
                yield
        finally:
            del self.reg
            del self.cfg
            del self.engine
            del self.events

    def test_engine(self):
        with self._setup():
            # Config load.
            self.assertEqual(self.engine.load_config(), True)
            self.assertEqual(self.events, [])
            # Startup.
            self.engine.start()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'initializing'), {}),
                ('machine_state_changed', ('Fake', 'connected'), {}),
                ('config_changed', (self.cfg.as_dict(), ), {}),
            ])
            self.assertIsNotNone(FakeMachine.instance)
            self.assertFalse(FakeMachine.instance.is_suppressed)
            # Output enabled.
            self.events = []
            self.engine.output = True
            self.assertEqual(self.events, [
                ('output_changed', (True, ), {}),
            ])
            self.assertTrue(FakeMachine.instance.is_suppressed)
            # Machine reconnection.
            self.events = []
            self.engine.reset_machine()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'stopped'), {}),
                ('machine_state_changed', ('Fake', 'initializing'), {}),
                ('machine_state_changed', ('Fake', 'connected'), {}),
            ])
            self.assertIsNotNone(FakeMachine.instance)
            self.assertTrue(FakeMachine.instance.is_suppressed)
            # Output disabled
            self.events = []
            self.engine.output = False
            self.assertEqual(self.events, [
                ('output_changed', (False, ), {}),
            ])
            self.assertFalse(FakeMachine.instance.is_suppressed)
            # Stopped.
            self.events = []
            self.engine.quit()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'stopped'), {}),
            ])
            self.assertIsNone(FakeMachine.instance)
コード例 #14
0
def sorted_requirements(requirements):
    return sorted(requirements, key=lambda r: str(r).lower())


# Find all available distributions.
all_requirements = [
    dist.as_requirement() for dist in pkg_resources.working_set
]

# Find Plover requirements.
plover_deps = set()
for dist in pkg_resources.require('plover'):
    plover_deps.add(dist.as_requirement())

# Load plugins.
registry = Registry(suppress_errors=False)
registry.update()

# Find plugins requirements.
plugins = OrderedDict()
plugins_deps = set()
for plugin_dist in registry.list_distributions():
    if plugin_dist.dist.project_name != 'plover':
        plugins[plugin_dist.dist.as_requirement()] = set()
for requirement, deps in plugins.items():
    for dist in pkg_resources.require(str(requirement)):
        if dist.as_requirement() not in plover_deps:
            deps.add(dist.as_requirement())
    plugins_deps.update(deps)

# List requirements.
コード例 #15
0
ファイル: test_engine.py プロジェクト: morinted/plover
class EngineTestCase(unittest.TestCase):

    @contextmanager
    def _setup(self, **kwargs):
        FakeMachine.instance = None
        self.reg = Registry()
        self.reg.register_plugin('machine', EntryPoint.parse('Fake = test.test_engine:FakeMachine'))
        self.kbd = FakeKeyboardEmulation()
        self.cfg = FakeConfig(**kwargs)
        self.events = []
        self.engine = FakeEngine(self.cfg, self.kbd)
        def hook_callback(hook, *args, **kwargs):
            self.events.append((hook, args, kwargs))
        for hook in self.engine.HOOKS:
            self.engine.hook_connect(hook, partial(hook_callback, hook))
        try:
            with mock.patch('plover.engine.registry', self.reg):
                yield
        finally:
            del self.reg
            del self.cfg
            del self.engine
            del self.events

    def test_engine(self):
        with self._setup():
            # Config load.
            self.assertEqual(self.engine.load_config(), True)
            self.assertEqual(self.events, [])
            # Startup.
            self.engine.start()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'initializing'), {}),
                ('machine_state_changed', ('Fake', 'connected'), {}),
                ('config_changed', (self.cfg.as_dict(),), {}),
            ])
            self.assertIsNotNone(FakeMachine.instance)
            self.assertFalse(FakeMachine.instance.is_suppressed)
            # Output enabled.
            self.events = []
            self.engine.output = True
            self.assertEqual(self.events, [
                ('output_changed', (True,), {}),
            ])
            self.assertTrue(FakeMachine.instance.is_suppressed)
            # Machine reconnection.
            self.events = []
            self.engine.reset_machine()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'stopped'), {}),
                ('machine_state_changed', ('Fake', 'initializing'), {}),
                ('machine_state_changed', ('Fake', 'connected'), {}),
            ])
            self.assertIsNotNone(FakeMachine.instance)
            self.assertTrue(FakeMachine.instance.is_suppressed)
            # Output disabled
            self.events = []
            self.engine.output = False
            self.assertEqual(self.events, [
                ('output_changed', (False,), {}),
            ])
            self.assertFalse(FakeMachine.instance.is_suppressed)
            # Stopped.
            self.events = []
            self.engine.quit()
            self.assertEqual(self.events, [
                ('machine_state_changed', ('Fake', 'stopped'), {}),
            ])
            self.assertIsNone(FakeMachine.instance)
コード例 #16
0
    return sorted(requirements, key=lambda r: str(r).lower())


# Find all available distributions.
all_requirements = [
    dist.as_requirement()
    for dist in pkg_resources.working_set
]

# Find Plover requirements.
plover_deps = set()
for dist in pkg_resources.require('plover'):
    plover_deps.add(dist.as_requirement())

# Load plugins.
registry = Registry(suppress_errors=False)
registry.update()

# Find plugins requirements.
plugins = OrderedDict()
plugins_deps = set()
for plugin_dist in registry.list_distributions():
    if plugin_dist.dist.project_name != 'plover':
        plugins[plugin_dist.dist.as_requirement()] = set()
for requirement, deps in plugins.items():
    for dist in pkg_resources.require(str(requirement)):
        if dist.as_requirement() not in plover_deps:
            deps.add(dist.as_requirement())
    plugins_deps.update(deps)

# List requirements.