Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dictionary implementation test framework #1302

Conversation

benoit-pierre
Copy link
Member

@benoit-pierre benoit-pierre commented Apr 29, 2021

Summary of changes

Add plover_build_utils.testing.dictionary_test helper, usage:

@dictionary_test
class TestMyDictionaryClass:

    # Mandatory: `implementation` class.
    DICT_CLASS = MyDictionaryClass

    # Mandatory: extension.
    DICT_EXTENSION = 'json'

    # Mandatory: valid sample dictionary contents.
    DICT_SAMPLE = b'{}'

    # Optional: if `True`, will check the implementation class
    # is registered as a valid `plover.dictionary` entrypoint.
    DICT_REGISTERED = True

    # Optional: if `False`, `len`, `__iter__`, and `items`
    # are not supported, and must respectively return:
    # 0 and empty sequences.
    # Note: only supported for read-only implementations,
    # writable implementations must support all sequence
    # methods.
    DICT_SUPPORT_SEQUENCE_METHODS = False

    # Optional: if `False`, then `reverse_lookup` is not
    # supported, and must return an empty set.
    DICT_SUPPORT_REVERSE_LOOKUP = False

    # Optional: if `False`, then `casereverse_lookup` is not
    # supported, and must return an empty set.
    # Note: if supported, then `DICT_SUPPORT_REVERSE_LOOKUP`
    # must be too.
    DICT_SUPPORT_CASEREVERSE_LOOKUP = False

    # Optional: load tests.
    DICT_LOAD_TESTS = (
        lambda: (
            # Dictionary file contents.
            b'''
            ''',
            # Expected entries, in Python-dictionary like format.
            '''
            "TEFT": 'test',
            'TEFT/-G': "testing",
            '''
        ),
    )

    # Optional: save tests.
    # Note: only for writable implementations.
    DICT_SAVE_TESTS = (
        lambda: (
            # Initial entries, in Python-dictionary like format.
            '''
            "TEFT": 'test',
            'TEFT/-G': "testing",
            '''
            # Expected saved dictionary contents, or `None`
            # to skip the byte-for-byte test of the resulting
            # file contents.
            b'''
            ''',
        ),
    )

    # Optional: if implemented, will be called to format
    # the contents before saving to a dictionary file,
    # including for load and save tests.
    @staticmethod
    def make_dict(self, contents):
        return contents

Fix 2 issues with StenoDictionary implementation:

  • If the class implementation is marked as read-only, then loading from a writable file should still result in a read-only dictionary.
  • Don't allow clear on a read-only dictionary.

Pull Request Checklist

  • Changes have tests
  • News fragment added in news.d. See documentation for details

@benoit-pierre benoit-pierre force-pushed the improve_dictionary_implementation_test_framework branch from ee36da0 to d3e70f8 Compare April 29, 2021 02:58
news.d/api/1302.new.md Outdated Show resolved Hide resolved
plover_build_utils/testing/parametrize.py Outdated Show resolved Hide resolved
plover_build_utils/testing/parametrize.py Outdated Show resolved Hide resolved
plover_build_utils/testing/parametrize.py Outdated Show resolved Hide resolved
plover_build_utils/testing/steno.py Show resolved Hide resolved
@benoit-pierre benoit-pierre force-pushed the improve_dictionary_implementation_test_framework branch from d3e70f8 to 24bbd90 Compare May 14, 2021 19:52
@benoit-pierre benoit-pierre merged commit 84c0b9d into openstenoproject:master May 14, 2021
@benoit-pierre benoit-pierre deleted the improve_dictionary_implementation_test_framework branch May 14, 2021 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants