-
Notifications
You must be signed in to change notification settings - Fork 96
/
test_edit.py
74 lines (56 loc) · 1.82 KB
/
test_edit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import pytest
import papis.database
from tests.testlib import TemporaryLibrary, PapisRunner
script = os.path.join(os.path.dirname(__file__), "scripts.py")
@pytest.mark.library_setup(settings={
"editor": "python {} sed".format(script)
})
def test_edit_run(tmp_library: TemporaryLibrary) -> None:
import papis.config
from papis.commands.edit import run
print(papis.config.get("editor"))
print(__file__)
db = papis.database.get()
docs = db.get_all_documents()
run(docs[0])
db.clear()
db.initialize()
doc, = db.query_dict({"title": "test_edit"})
assert "test_edit" in doc["title"]
@pytest.mark.library_setup(settings={
"editor": "echo",
})
def test_edit_cli(tmp_library: TemporaryLibrary) -> None:
from papis.commands.edit import cli
cli_runner = PapisRunner()
# check run
result = cli_runner.invoke(
cli,
["krishnamurti"])
assert result.exit_code == 0
# check run with non-existent document
result = cli_runner.invoke(
cli,
["this document does not exist"])
assert result.exit_code == 0
# check --all
result = cli_runner.invoke(
cli,
["--all", "--editor", "ls", "krishnamurti"])
assert result.exit_code == 0
assert papis.config.get("editor") == "ls"
# check --notes
notes_name = papis.config.get("notes-name")
assert notes_name
result = cli_runner.invoke(
cli,
["--all", "--editor", "echo", "--notes", "krishnamurti"])
assert result.exit_code == 0
assert papis.config.get("editor") == "echo"
db = papis.database.get()
doc, = db.query_dict({"author": "Krishnamurti"})
folder = doc.get_main_folder()
assert folder is not None
expected_notes_path = os.path.join(folder, notes_name)
assert os.path.exists(expected_notes_path)