mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +02:00
update handling of cache directories in test suite (easier syntax)
This commit is contained in:
parent
93f383cb78
commit
11c7a878c3
3 changed files with 33 additions and 19 deletions
|
@ -399,15 +399,15 @@ Feature: Custom formats
|
||||||
Scenario Outline: Export to yaml
|
Scenario Outline: Export to yaml
|
||||||
Given we use the config "<config>.yaml"
|
Given we use the config "<config>.yaml"
|
||||||
And we use the password "test" if prompted
|
And we use the password "test" if prompted
|
||||||
And we create cache directory "exported_journal"
|
And we create a cache directory
|
||||||
When we run "jrnl --export yaml -o {cache_dir}" with cache directory "exported_journal"
|
When we run "jrnl --export yaml -o {cache_dir}"
|
||||||
Then cache directory "exported_journal" should contain the files
|
Then the cache should contain the files
|
||||||
"""
|
"""
|
||||||
2020-08-29_entry-the-first.md
|
2020-08-29_entry-the-first.md
|
||||||
2020-08-31_a-second-entry-in-what-i-hope-to-be-a-long-series.md
|
2020-08-31_a-second-entry-in-what-i-hope-to-be-a-long-series.md
|
||||||
2020-09-24_the-third-entry-finally-after-weeks-without-writing.md
|
2020-09-24_the-third-entry-finally-after-weeks-without-writing.md
|
||||||
"""
|
"""
|
||||||
And the content of file "2020-08-29_entry-the-first.md" in cache directory "exported_journal" should be
|
And the content of file "2020-08-29_entry-the-first.md" in the cache should be
|
||||||
"""
|
"""
|
||||||
title: Entry the first.
|
title: Entry the first.
|
||||||
date: 2020-08-29 11:11
|
date: 2020-08-29 11:11
|
||||||
|
@ -446,15 +446,15 @@ Feature: Custom formats
|
||||||
# https://github.com/jrnl-org/jrnl/issues/881
|
# https://github.com/jrnl-org/jrnl/issues/881
|
||||||
Given we use the config "<config>.yaml"
|
Given we use the config "<config>.yaml"
|
||||||
And we use the password "test" if prompted
|
And we use the password "test" if prompted
|
||||||
And we create cache directory "bug768"
|
And we create a cache directory
|
||||||
When we run "jrnl --export yaml -o {cache_dir}" with cache directory "bug768"
|
When we run "jrnl --export yaml -o {cache_dir}"
|
||||||
Then cache directory "bug768" should contain the files
|
Then the cache should contain the files
|
||||||
"""
|
"""
|
||||||
2020-08-29_entry-the-first.md
|
2020-08-29_entry-the-first.md
|
||||||
2020-08-31_a-second-entry-in-what-i-hope-to-be-a-long-series.md
|
2020-08-31_a-second-entry-in-what-i-hope-to-be-a-long-series.md
|
||||||
2020-09-24_the-third-entry-finally-after-weeks-without-writing.md
|
2020-09-24_the-third-entry-finally-after-weeks-without-writing.md
|
||||||
"""
|
"""
|
||||||
And the content of file "2020-09-24_the-third-entry-finally-after-weeks-without-writing.md" in cache directory "bug768" should be
|
And the content of file "2020-09-24_the-third-entry-finally-after-weeks-without-writing.md" in the cache should be
|
||||||
"""
|
"""
|
||||||
title: The third entry finally after weeks without writing.
|
title: The third entry finally after weeks without writing.
|
||||||
date: 2020-09-24 09:14
|
date: 2020-09-24 09:14
|
||||||
|
|
|
@ -333,12 +333,11 @@ def all_input_was_used(context):
|
||||||
@when('we run "{command}"')
|
@when('we run "{command}"')
|
||||||
@when('we run "{command}" and pipe')
|
@when('we run "{command}" and pipe')
|
||||||
@when('we run "{command}" and pipe "{text}"')
|
@when('we run "{command}" and pipe "{text}"')
|
||||||
@when('we run "{command}" with cache directory "{cache_dir}"')
|
def run(context, command, text=""):
|
||||||
def run(context, command, text="", cache_dir=None):
|
|
||||||
text = text or context.text or ""
|
text = text or context.text or ""
|
||||||
|
|
||||||
if cache_dir is not None:
|
if "cache_dir" in context and context.cache_dir is not None:
|
||||||
cache_dir = os.path.join("features", "cache", cache_dir)
|
cache_dir = os.path.join("features", "cache", context.cache_dir)
|
||||||
command = command.format(cache_dir=cache_dir)
|
command = command.format(cache_dir=cache_dir)
|
||||||
|
|
||||||
args = ushlex(command)
|
args = ushlex(command)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import random
|
||||||
|
import string
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
from behave import given
|
from behave import given
|
||||||
|
@ -116,18 +118,27 @@ def assert_xml_output_tags(context, expected_tags_json_list):
|
||||||
|
|
||||||
|
|
||||||
@given('we create cache directory "{dir_name}"')
|
@given('we create cache directory "{dir_name}"')
|
||||||
def create_directory(context, dir_name):
|
@given("we create a cache directory")
|
||||||
|
def create_directory(context, dir_name=None):
|
||||||
|
if not dir_name:
|
||||||
|
dir_name = "cache_" + "".join(
|
||||||
|
random.choices(string.ascii_uppercase + string.digits, k=20)
|
||||||
|
)
|
||||||
|
|
||||||
working_dir = os.path.join("features", "cache", dir_name)
|
working_dir = os.path.join("features", "cache", dir_name)
|
||||||
if os.path.exists(working_dir):
|
if os.path.exists(working_dir):
|
||||||
shutil.rmtree(working_dir)
|
shutil.rmtree(working_dir)
|
||||||
os.makedirs(working_dir)
|
os.makedirs(working_dir)
|
||||||
|
context.cache_dir = dir_name
|
||||||
|
|
||||||
|
|
||||||
@then('cache directory "{dir_name}" should contain the files')
|
@then('cache "{dir_name}" should contain the files')
|
||||||
@then(
|
@then('cache "{dir_name}" should contain the files {expected_files_json_list}')
|
||||||
'cache directory "{dir_name}" should contain the files {expected_files_json_list}'
|
@then("the cache should contain the files")
|
||||||
)
|
def assert_dir_contains_files(context, dir_name=None, expected_files_json_list=""):
|
||||||
def assert_dir_contains_files(context, dir_name, expected_files_json_list=""):
|
if not dir_name:
|
||||||
|
dir_name = context.cache_dir
|
||||||
|
|
||||||
working_dir = os.path.join("features", "cache", dir_name)
|
working_dir = os.path.join("features", "cache", dir_name)
|
||||||
actual_files = os.listdir(working_dir)
|
actual_files = os.listdir(working_dir)
|
||||||
|
|
||||||
|
@ -142,7 +153,11 @@ def assert_dir_contains_files(context, dir_name, expected_files_json_list=""):
|
||||||
|
|
||||||
|
|
||||||
@then('the content of file "{file_path}" in cache directory "{cache_dir}" should be')
|
@then('the content of file "{file_path}" in cache directory "{cache_dir}" should be')
|
||||||
def assert_exported_yaml_file_content(context, file_path, cache_dir):
|
@then('the content of file "{file_path}" in the cache should be')
|
||||||
|
def assert_exported_yaml_file_content(context, file_path, cache_dir=None):
|
||||||
|
if not cache_dir:
|
||||||
|
cache_dir = context.cache_dir
|
||||||
|
|
||||||
expected_content = context.text.strip().splitlines()
|
expected_content = context.text.strip().splitlines()
|
||||||
full_file_path = os.path.join("features", "cache", cache_dir, file_path)
|
full_file_path = os.path.join("features", "cache", cache_dir, file_path)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue