Exemple #1
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)
Exemple #2
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)
Exemple #3
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)
Exemple #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)
Exemple #5
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
Exemple #6
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)
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)
Exemple #8
0
    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)
Exemple #9
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.