Exemple #1
0
def contains(string: Optional[str] = None, block: bool = False):
    """ Print the names that contains the string. """
    string = _query_user_if_none(string, "Search for words containing: ")
    briefs = read_dict()
    filtered_briefs = [b for b in briefs if string.lower() in b.name.lower()]
    print(brief_grid(filtered_briefs))
    _wait_if(block)
Exemple #2
0
def starting_with(string: Optional[str] = None, block: bool = False):
    """ Print the names that starts with the string. """
    string = _query_user_if_none(string, "Words starting with: ")
    briefs = read_dict()
    lower_str = string.lower()
    filtered_briefs = [
        b for b in briefs if b.name.lower().startswith(lower_str)
    ]
    print(brief_grid(filtered_briefs))
    _wait_if(block)
Exemple #3
0
def add(name: str = None, keys: str = None, tags: Optional[str] = None):
    """ Add a new entry to the dict. """
    name = _query_user_if_none(name, "Brief name: ")
    keys = _query_user_if_none(keys, "Brief keys: ")
    brief = Brief(name, keys, tags=tags)

    briefs = read_dict()
    briefs.sort()
    pd.add_to_dict(brief, briefs)

    pd.save_dict_to_file(briefs)
Exemple #4
0
    def test_load_sorted(self):
        """ Test the loading af a simple file from disk. """
        test_dir_path = Path(__file__).parent
        test_dict_path = test_dir_path / "data/test_dict.tsv"
        briefs_test = parse.read_dict(test_dict_path)

        names = ["Ask", "Forget", "Now"]
        keys = ["SK", "FO-RGT", "NOE"]
        briefs_actual = [Brief(n, k) for n, k in zip(names, keys)]

        self.assertEqual(len(briefs_test), len(briefs_test))
        [self.compare_briefs(t, a) for t, a in zip(briefs_test, briefs_actual)]
Exemple #5
0
def matches_tag(tag: Optional[str] = None, block: bool = False):
    """ Print the names of the strokes that contain the tags. """
    briefs = read_dict()

    if tag is None:
        dict_path = _validate_path(None)
        available_tags = _get_tags(dict_path)
        print(f"Available tags: {available_tags}")
        tag = _query_user_if_none(None, "Select the tag: ")

    filtered_briefs = [b for b in briefs if tag in b.tags]
    print(brief_grid(filtered_briefs))
    _wait_if(block)
Exemple #6
0
    def test_tags(self):
        """ Test the loading of tags from the file. """
        test_dir_path = Path(__file__).parent
        test_dict_path = test_dir_path / "data/test_dict_tags.tsv"
        briefs_test = parse.read_dict(test_dict_path)

        matching_names_test = [
            b.name for b in briefs_test if "single" in b.tags
        ]
        matching_names_expected = ["Comp", "Rather", "Test"]

        self.assertEqual(matching_names_test, matching_names_expected)

        matching_names_test = [b.name for b in briefs_test if "alt" in b.tags]
        matching_names_expected = ["Test"]

        self.assertEqual(matching_names_test, matching_names_expected)
Exemple #7
0
    def test_save_dict(self):
        """ Save the brief list a temporary file. """
        names = ["Ask", "Forget", "Now"]
        keys = ["SK", "FO-RGT", "NOE"]
        briefs_set = [Brief(n, k) for n, k in zip(names, keys)]

        with tempfile.TemporaryDirectory() as dir_:
            dir_path = Path(dir_)
            dict_path = dir_path / "dict.tab"

            # Write the file to disk
            parse.save_dict_to_file(briefs_set, dict_path)

            # Read it again
            briefs_test = parse.read_dict(dict_path)

        names_test = [b.name for b in briefs_test]
        self.assertEqual(names_test, names)
Exemple #8
0
def print_all():
    """ Print all of the words in the dictionary and then exit. """
    briefs = read_dict()
    print(brief_grid(briefs))