Exemple #1
0
def test_disambiguate():
    # setup
    book = Book('/test', 'txt')

    for name in ['alpha', 'bravo1', 'bravo2']:
        book.notes[name] = Note(name)

    for n in range(clui.DYM_LIMIT + 1):
        book.notes[f'charlie{n}'] = Note(f'charlie{n}')

    # success: one match
    assert clui.disambiguate(book, 'al') == book['alpha']

    # failure: zero matches
    with pytest.raises(click.ClickException) as exc:
        clui.disambiguate(book, 'nope')
    exc.match("Note 'nope' does not exist.")

    # failure: multiple notes, less than DYM_LIMIT
    with pytest.raises(click.ClickException) as exc:
        clui.disambiguate(book, 'bravo')
    exc.match("Ambiguous note name. Did you mean: 'bravo1', 'bravo2?'")

    # failure: multiple notes, more than DYM_LIMIT
    with pytest.raises(click.ClickException) as exc:
        clui.disambiguate(book, 'charlie')
    exc.match(f"Ambiguous note name, {clui.DYM_LIMIT+1} notes match.")
Exemple #2
0
    def create(self, name, string):
        '''
        Create and return a new Note in the Book.
        '''

        dest = tools.path.join(self.dire, f'{name}.{self.ext}')
        tools.file.create(dest, string)
        self.notes[name] = Note(dest)
        return self.notes[name]
Exemple #3
0
def test_disambiguate(book):
    # setup
    book.notes['bravo2'] = Note('bravo2')

    # success: unique name
    assert set(book.disambiguate('al')) == {book['alpha']}

    # success: exact match
    assert set(book.disambiguate('bravo')) == {book['bravo']}

    # success: partial match
    assert set(book.disambiguate('brav')) == {book['bravo'], book['bravo2']}
Exemple #4
0
def test_exists(note):
    # success
    assert note.exists()
    assert not Note('/nope.txt').exists()
Exemple #5
0
def test_eq(note):
    # success
    assert note == note
    assert note != Note('/nope.txt')
    assert note != 'not a note'
Exemple #6
0
def note(tmpdir):
    path = tmpdir.join('alpha.txt')
    path.write('alpha\nbravo')
    return Note(path)