Exemple #1
0
def test_added_notes_recursive(app: App) -> None:
    """find_new_notes must find files recursively."""
    directory = app.root / "directory"
    new = app.root / "new.md"
    directory.mkdir()
    new.touch()

    new_notes = find_new_notes(app, find_notes(app))
    assert list(new_notes) == [new]
Exemple #2
0
def test_added_notes_in_db(app: App) -> None:
    """Results of find_new_notes must not already be in the database."""
    new = app.root / "new.md"
    skip = app.root / "skip.md"
    new.touch()
    skip.touch()
    insert_files(app.database, skip, basedir=app.root)

    new_notes = find_new_notes(app, find_notes(app))
    assert list(new_notes) == [new]
Exemple #3
0
def test_added_notes_pattern(app: App) -> None:
    """Results of find_new_notes must match the input pattern."""
    app.config.patterns = {"*.md": True, "*.txt": True}
    directory = app.root / "directory"
    markdown = app.root / "input.md"
    txt = app.root / "input.txt"
    tex = app.root / "ignore.tex"
    directory.mkdir()
    markdown.touch()
    txt.touch()
    tex.touch()

    new_notes = find_new_notes(app, find_notes(app))
    assert sorted(new_notes) == [markdown, txt]
Exemple #4
0
def test_find_new_notes(app: App) -> None:
    """find_new_notes must only return existing files that aren't yet in the
    database and match the input patterns (*.md by default).
    """
    present = app.root / "present.md"
    absent = app.root / "absent.md"
    directory = app.root / "directory"
    txt = app.root / "ignore.txt"
    present.touch()
    absent.touch()
    directory.mkdir()
    txt.touch()

    insert_files(app.database, present, basedir=app.root)

    new_notes = find_new_notes(app, find_notes(app))
    assert list(new_notes) == [absent]
Exemple #5
0
def test_modified_notes(app: App) -> None:
    """find_new_notes must find modified notes after they are deleted from the
    database.
    """
    modified = app.root / "modified.md"
    not_modified = app.root / "not_modified.md"
    added = app.root / "added.md"

    modified.write_text("hello")
    not_modified.write_text("hello")

    insert_files(app.database, modified, not_modified, basedir=app.root)

    not_modified.write_text("hello")  # not modified
    added.write_text("new note")
    modified.write_text("modified")

    delete_notes(app, find_outdated_notes(app, find_notes(app)))

    new_notes = find_new_notes(app, find_notes(app))
    assert sorted(new_notes) == [added, modified]