Implement test to check editor temporary filename

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
This commit is contained in:
Micah Jerome Ellison 2021-05-15 16:51:40 -07:00 committed by Jonathan Wren
parent 5d4d68fe32
commit 512fb63e1f
2 changed files with 12 additions and 3 deletions

View file

@ -44,9 +44,9 @@ Feature: Journals iteracting with the file system in a way that users can see
Given we use the config "editor.yaml"
When we run "jrnl --edit"
Then the editor should have been called
Then the temporary filename suffix should be ".jrnl"
Then the editor filename should end with ".jrnl"
Scenario: the temporary filename suffix should be "-{template_filename}"
Given we use the config "editor_markdown_extension.yaml"
When we run "jrnl --edit"
Then the temporary filename suffix should be "-extension.md"
Then the editor filename should end with "-extension.md"

View file

@ -141,11 +141,13 @@ def temp_dir():
def working_dir(request):
return os.path.join(request.config.rootpath, "tests")
@fixture
def config_path(temp_dir):
os.chdir(temp_dir.name)
return temp_dir.name + "/jrnl.yaml"
@fixture
def toml_version(working_dir):
pyproject = os.path.join(working_dir, "..", "pyproject.toml")
@ -304,6 +306,13 @@ def count_editor_args(num_args, cli_run, editor_state):
assert len(editor_state["command"]) == int(num_args)
@then(parse('the editor filename should end with "{suffix}"'))
def editor_filename_suffix(suffix, editor_state):
editor_filename = editor_state["tmpfile"]["name"]
assert editor_state["tmpfile"]["name"].endswith(suffix), (editor_filename, suffix)
@then(parse('the editor file content should {comparison} "{str_value}"'))
@then(parse("the editor file content should {comparison} empty"))
@then(parse("the editor file content should {comparison}\n{str_value}"))