示例#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)
示例#2
0
    def test_melani_implicit_hyphens(self, monkeypatch):
        r'''
        "15/SE/COhro": "XV secolo",
        "16/SE/COhro": "XVI secolo",

        15/SE/COhro/16/SE/COhro  " XV secolo XVI secolo"
        '''
        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 = ()

        system_dict = {}
        system.setup('Melani', system_mod=Melani, system_dict=system_dict)
        for k, v in system_dict.items():
            monkeypatch.setattr(system, k, v)
示例#3
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)
示例#4
0
def _blackbox_replay_action(blackbox, action_spec):
    action, *args = shlex.split(action_spec)
    if action == 'start_attached':
        assert not args
        blackbox.formatter.start_attached = True
    elif action == 'spaces_after':
        assert not args
        blackbox.formatter.set_space_placement('After Output')
    elif action == 'spaces_before':
        assert not args
        blackbox.formatter.set_space_placement('Before Output')
    elif action == 'system':
        assert len(args) == 1
        system.setup(args[0])
    else:
        raise ValueError('invalid action:\n%r' % action_spec)
示例#5
0
文件: engine.py 项目: ohAitch/plover
 def _update(self, config_update=None, full=False, reset_machine=False):
     original_config = self._config.as_dict()
     # Update configuration.
     if config_update is not None:
         self._config.update(**config_update)
         config = self._config.as_dict()
     else:
         config = original_config
     # Create configuration update.
     if full:
         config_update = config
     else:
         config_update = {
             option: value
             for option, value in config.items()
             if value != original_config[option]
         }
         if 'machine_type' in config_update:
             for opt in (
                 'machine_specific_options',
                 'system_keymap',
             ):
                 config_update[opt] = config[opt]
     # Update logging.
     log.set_stroke_filename(config['log_file_name'])
     log.enable_stroke_logging(config['enable_stroke_logging'])
     log.enable_translation_logging(config['enable_translation_logging'])
     # Update output.
     self._formatter.set_space_placement(config['space_placement'])
     self._formatter.start_attached = config['start_attached']
     self._formatter.start_capitalized = config['start_capitalized']
     self._translator.set_min_undo_length(config['undo_levels'])
     # Update system.
     system_name = config['system_name']
     if system.NAME != system_name:
         log.info('loading system: %s', system_name)
         system.setup(system_name)
     # Update machine.
     update_keymap = False
     start_machine = False
     machine_params = MachineParams(config['machine_type'],
                                    config['machine_specific_options'],
                                    config['system_keymap'])
     # Do not reset if only the keymap changed.
     if self._machine_params is None or \
        self._machine_params.type != machine_params.type or \
        self._machine_params.options != machine_params.options:
         reset_machine = True
     if reset_machine:
         if self._machine is not None:
             self._machine.stop_capture()
             self._machine = None
         machine_type = config['machine_type']
         machine_options = config['machine_specific_options']
         try:
             machine_class = registry.get_plugin('machine', machine_type).obj
         except Exception as e:
             raise InvalidConfigurationError(str(e))
         log.info('setting machine: %s', machine_type)
         self._machine = machine_class(machine_options)
         self._machine.set_suppression(self._is_running)
         self._machine.add_state_callback(self._machine_state_callback)
         self._machine.add_stroke_callback(self._machine_stroke_callback)
         self._machine_params = machine_params
         update_keymap = True
         start_machine = True
     elif self._machine is not None:
         update_keymap = 'system_keymap' in config_update
     if update_keymap:
         machine_keymap = config['system_keymap']
         if machine_keymap is not None:
             self._machine.set_keymap(machine_keymap)
     if start_machine:
         self._machine.start_capture()
     # Update running extensions.
     enabled_extensions = config['enabled_extensions']
     running_extensions = set(self._running_extensions)
     self._stop_extensions(running_extensions - enabled_extensions)
     self._start_extensions(enabled_extensions - running_extensions)
     # Trigger `config_changed` hook.
     if config_update:
         self._trigger_hook('config_changed', config_update)
     # Update dictionaries.
     config_dictionaries = OrderedDict(
         (d.path, d)
         for d in config['dictionaries']
     )
     copy_default_dictionaries(config_dictionaries.keys())
     # Start by unloading outdated dictionaries.
     self._dictionaries_manager.unload_outdated()
     self._set_dictionaries([
         d for d in self._dictionaries.dicts
         if d.path in config_dictionaries and \
            d.path in self._dictionaries_manager
     ])
     # And then (re)load all dictionaries.
     dictionaries = []
     for result in self._dictionaries_manager.load(config_dictionaries.keys()):
         if isinstance(result, DictionaryLoaderException):
             d = ErroredDictionary(result.path, result.exception)
             # Only show an error if it's new.
             if d != self._dictionaries.get(result.path):
                 log.error('loading dictionary `%s` failed: %s',
                           shorten_path(result.path), str(result.exception))
         else:
             d = result
         d.enabled = config_dictionaries[d.path].enabled
         dictionaries.append(d)
     self._set_dictionaries(dictionaries)
示例#6
0
 def _update(self, config_update=None, full=False, reset_machine=False):
     original_config = self._config.as_dict()
     # Update configuration.
     if config_update is not None:
         self._config.update(**config_update)
         config = self._config.as_dict()
     else:
         config = original_config
     # Create configuration update.
     if full:
         config_update = config
     else:
         config_update = {
             option: value
             for option, value in config.items()
             if value != original_config[option]
         }
     # Update logging.
     log.set_stroke_filename(config['log_file_name'])
     log.enable_stroke_logging(config['enable_stroke_logging'])
     log.enable_translation_logging(config['enable_translation_logging'])
     # Update output.
     self._formatter.set_space_placement(config['space_placement'])
     self._formatter.start_attached = config['start_attached']
     self._formatter.start_capitalized = config['start_capitalized']
     self._translator.set_min_undo_length(config['undo_levels'])
     # Update system.
     system_name = config['system_name']
     if system.NAME != system_name:
         log.info('loading system: %s', system_name)
         system.setup(system_name)
     # Update machine.
     update_keymap = False
     start_machine = False
     machine_params = MachineParams(config['machine_type'],
                                    config['machine_specific_options'],
                                    config['system_keymap'])
     # Do not reset if only the keymap changed.
     if self._machine_params is None or \
        self._machine_params.type != machine_params.type or \
        self._machine_params.options != machine_params.options:
         reset_machine = True
     if reset_machine:
         if self._machine is not None:
             self._machine.stop_capture()
             self._machine = None
         machine_type = config['machine_type']
         machine_options = config['machine_specific_options']
         machine_class = registry.get_plugin('machine', machine_type).obj
         log.info('setting machine: %s', machine_type)
         self._machine = machine_class(machine_options)
         self._machine.set_suppression(self._is_running)
         self._machine.add_state_callback(self._machine_state_callback)
         self._machine.add_stroke_callback(self._machine_stroke_callback)
         self._machine_params = machine_params
         update_keymap = True
         start_machine = True
     elif self._machine is not None:
         update_keymap = 'system_keymap' in config_update
     if update_keymap:
         machine_keymap = config['system_keymap']
         if machine_keymap is not None:
             self._machine.set_keymap(machine_keymap)
     if start_machine:
         self._machine.start_capture()
     # Update running extensions.
     enabled_extensions = config['enabled_extensions']
     running_extensions = set(self._running_extensions)
     self._stop_extensions(running_extensions - enabled_extensions)
     self._start_extensions(enabled_extensions - running_extensions)
     # Trigger `config_changed` hook.
     if config_update:
         self._trigger_hook('config_changed', config_update)
     # Update dictionaries.
     config_dictionaries = OrderedDict(
         (d.path, d) for d in config['dictionaries'])
     copy_default_dictionaries(config_dictionaries.keys())
     # Start by unloading outdated dictionaries.
     self._dictionaries_manager.unload_outdated()
     self._set_dictionaries([
         d for d in self._dictionaries.dicts
         if d.path in config_dictionaries and \
            d.path in self._dictionaries_manager
     ])
     # And then (re)load all dictionaries.
     dictionaries = []
     for result in self._dictionaries_manager.load(
             config_dictionaries.keys()):
         if isinstance(result, DictionaryLoaderException):
             d = ErroredDictionary(result.path, result.exception)
             # Only show an error if it's new.
             if d != self._dictionaries.get(result.path):
                 log.error('loading dictionary `%s` failed: %s',
                           shorten_path(result.path), str(result.exception))
         else:
             d = result
         d.enabled = config_dictionaries[d.path].enabled
         dictionaries.append(d)
     self._set_dictionaries(dictionaries)
示例#7
0
from plover import system
from plover.config import DEFAULT_SYSTEM_NAME
from plover.registry import registry


# So our custom assertHelpers are not part of the test failure tracebacks.
__unittest = True


class TestCase(unittest.TestCase):

    def assertRaisesWithMessage(self, exception, msg):
        outer_self = self
        class ContextManager:
            def __enter__(self):
                pass
            def __exit__(self, exc_type, exc_value, traceback):
                if exc_type is exception:
                    return True
                if exc_type is None:
                    outer_self.fail(msg=msg)
                return False
        return ContextManager()


# Setup registry.
registry.update()
# Setup default system.
system.setup(DEFAULT_SYSTEM_NAME)
示例#8
0
 def _update(self, config_update=None, full=False, reset_machine=False):
     original_config = self._config.as_dict()
     # Update configuration.
     if config_update is not None:
         self._config.update(**config_update)
         config = self._config.as_dict()
     else:
         config = original_config
     # Create configuration update.
     if full:
         config_update = config
     else:
         config_update = {option: value for option, value in config.items() if value != original_config[option]}
         if "machine_type" in config_update:
             for opt in ("machine_specific_options", "system_keymap"):
                 config_update[opt] = config[opt]
     # Update logging.
     log.set_stroke_filename(config["log_file_name"])
     log.enable_stroke_logging(config["enable_stroke_logging"])
     log.enable_translation_logging(config["enable_translation_logging"])
     # Update output.
     self._formatter.set_space_placement(config["space_placement"])
     self._formatter.start_attached = config["start_attached"]
     self._formatter.start_capitalized = config["start_capitalized"]
     self._translator.set_min_undo_length(config["undo_levels"])
     # Update system.
     system_name = config["system_name"]
     if system.NAME != system_name:
         log.info("loading system: %s", system_name)
         system.setup(system_name)
     # Update machine.
     update_keymap = False
     start_machine = False
     machine_params = MachineParams(
         config["machine_type"], config["machine_specific_options"], config["system_keymap"]
     )
     if reset_machine or machine_params != self._machine_params:
         if self._machine is not None:
             self._machine.stop_capture()
             self._machine = None
         machine_type = config["machine_type"]
         machine_options = config["machine_specific_options"]
         try:
             machine_class = registry.get_plugin("machine", machine_type).resolve()
         except Exception as e:
             raise InvalidConfigurationError(str(e))
         log.info("setting machine: %s", machine_type)
         self._machine = machine_class(machine_options)
         self._machine.set_suppression(self._is_running)
         self._machine.add_state_callback(self._machine_state_callback)
         self._machine.add_stroke_callback(self._machine_stroke_callback)
         self._machine_params = machine_params
         update_keymap = True
         start_machine = True
     elif self._machine is not None:
         update_keymap = "system_keymap" in config_update
     if update_keymap:
         machine_keymap = config["system_keymap"]
         if machine_keymap is not None:
             self._machine.set_keymap(machine_keymap)
     if start_machine:
         self._machine.start_capture()
     # Update dictionaries.
     dictionaries_files = config["dictionary_file_names"]
     copy_default_dictionaries(dictionaries_files)
     dictionaries = self._dictionaries_manager.load(dictionaries_files)
     self._dictionaries.set_dicts(dictionaries)
     # Trigger `config_changed` hook.
     if config_update:
         self._trigger_hook("config_changed", config_update)
 def setUpClass(cls):
     registry.update()
     system.setup(DEFAULT_SYSTEM_NAME)
示例#10
0
from plover.registry import registry
from plover import system

# Setup registry.
registry.update()
# Setup default system.
system.setup('Michela')
def setup_module(cls):
    registry.update()
    system.setup(DEFAULT_SYSTEM_NAME)
示例#12
0
 def _update(self, config_update=None, full=False, reset_machine=False):
     original_config = self._config.as_dict()
     # Update configuration.
     if config_update is not None:
         self._config.update(**config_update)
         config = self._config.as_dict()
     else:
         config = original_config
     # Create configuration update.
     if full:
         config_update = config
     else:
         config_update = {
             option: value
             for option, value in config.items()
             if value != original_config[option]
         }
         if 'machine_type' in config_update:
             for opt in (
                     'machine_specific_options',
                     'system_keymap',
             ):
                 config_update[opt] = config[opt]
     # Update logging.
     log.set_stroke_filename(config['log_file_name'])
     log.enable_stroke_logging(config['enable_stroke_logging'])
     log.enable_translation_logging(config['enable_translation_logging'])
     # Update output.
     self._formatter.set_space_placement(config['space_placement'])
     self._formatter.start_attached = config['start_attached']
     self._formatter.start_capitalized = config['start_capitalized']
     self._translator.set_min_undo_length(config['undo_levels'])
     # Update system.
     system_name = config['system_name']
     if system.NAME != system_name:
         log.info('loading system: %s', system_name)
         system.setup(system_name)
     # Update machine.
     update_keymap = False
     start_machine = False
     machine_params = MachineParams(config['machine_type'],
                                    config['machine_specific_options'],
                                    config['system_keymap'])
     if reset_machine or machine_params != self._machine_params:
         if self._machine is not None:
             self._machine.stop_capture()
             self._machine = None
         machine_type = config['machine_type']
         machine_options = config['machine_specific_options']
         try:
             machine_class = registry.get_plugin('machine',
                                                 machine_type).resolve()
         except Exception as e:
             raise InvalidConfigurationError(str(e))
         log.info('setting machine: %s', machine_type)
         self._machine = machine_class(machine_options)
         self._machine.set_suppression(self._is_running)
         self._machine.add_state_callback(self._machine_state_callback)
         self._machine.add_stroke_callback(self._machine_stroke_callback)
         self._machine_params = machine_params
         update_keymap = True
         start_machine = True
     elif self._machine is not None:
         update_keymap = 'system_keymap' in config_update
     if update_keymap:
         machine_keymap = config['system_keymap']
         if machine_keymap is not None:
             self._machine.set_keymap(machine_keymap)
     if start_machine:
         self._machine.start_capture()
     # Update dictionaries.
     dictionaries_files = config['dictionary_file_names']
     copy_default_dictionaries(dictionaries_files)
     dictionaries = self._dictionaries_manager.load(dictionaries_files)
     self._dictionaries.set_dicts(dictionaries)
     # Trigger `config_changed` hook.
     if config_update:
         self._trigger_hook('config_changed', config_update)
示例#13
0
import inspect

import pytest

from plover import system
from plover.config import DEFAULT_SYSTEM_NAME
from plover.registry import registry


# Setup registry.
registry.update()
# Setup default system.
system.setup(DEFAULT_SYSTEM_NAME)


def parametrize(tests, arity=None):
    '''Helper for parametrizing pytest tests.

    Expect a list of lambdas, one per test. Each lambda must return
    the parameters for its respecting test.

    Test identifiers will be automatically generated, from the test
    number and its lambda definition line (1.10, 2.12, 3.20, ...).

    If arity is None, the arguments being parametrized will be automatically
    set from the function last arguments, according to the numbers of
    parameters for each test.

    '''
    ids = []
    argvalues = []
示例#14
0
 def setup_class(cls):
     log.set_level(log.WARNING)
     registry.update()
     system.setup('Spanish MQD')
示例#15
0
def setup_plover():
    registry.update()
    system.setup(DEFAULT_SYSTEM_NAME)
示例#16
0
 def setup_class(cls):
     super().setup_class()
     registry.update()
     system.setup('English Stenotype')