From 5ce16cf341d4dddd6e77c76c7b7e8ad8cc084053 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 29 May 2020 17:12:06 -0400 Subject: [PATCH] add test --- features/core.feature | 11 +++++++++++ features/environment.py | 6 ++++-- features/steps/core.py | 9 +++++++++ jrnl/install.py | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/features/core.feature b/features/core.feature index 3008cfce..fbf15b54 100644 --- a/features/core.feature +++ b/features/core.feature @@ -113,3 +113,14 @@ Feature: Basic reading and writing to a journal 2013-06-10 15:40 Life is good. """ And we should get no error + + Scenario: Installation with relative journal and referencing from another folder + Given we use the config "missingconfig" + When we run "jrnl hello world" and enter + """ + test.txt + n + """ + and we change directory to "features" + and we run "jrnl -n 1" + Then the output should contain "hello world" diff --git a/features/environment.py b/features/environment.py index 0032cf13..e76d246a 100644 --- a/features/environment.py +++ b/features/environment.py @@ -2,7 +2,7 @@ import os import shutil import sys - +CWD = os.getcwd() def clean_all_working_dirs(): for folder in ("configs", "journals", "cache"): working_dir = os.path.join("features", folder) @@ -26,7 +26,7 @@ def before_scenario(context, scenario): """Before each scenario, backup all config and journal test data.""" # Clean up in case something went wrong clean_all_working_dirs() - + CWD = os.getcwd() for folder in ("configs", "journals"): original = os.path.join("features", "data", folder) working_dir = os.path.join("features", folder) @@ -53,3 +53,5 @@ def before_scenario(context, scenario): def after_scenario(context, scenario): """After each scenario, restore all test data and remove working_dirs.""" clean_all_working_dirs() + if os.getcwd()!=CWD: + os.chdir(CWD) diff --git a/features/steps/core.py b/features/steps/core.py index 79591f57..82161e58 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -79,6 +79,15 @@ def set_config(context, config_file): with open(install.CONFIG_FILE_PATH, "a") as cf: cf.write("version: {}".format(__version__)) +@given('there is no config') +def no_config(context): + nopath = "features/configs/missingconfig.yaml" + install.CONFIG_FILE_PATH = os.path.abspath(nopath) + #install.CONFIG_FILE_PATH_FALLBACK = os.path.abspath(nopath) + +@when('we change directory to "{path}"') +def move_up_dir(context,path): + os.chdir(path) @when('we open the editor and enter "{text}"') @when("we open the editor and enter nothing") diff --git a/jrnl/install.py b/jrnl/install.py index 2b86770c..78745161 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -135,7 +135,7 @@ def install(): # Where to create the journal? path_query = f"Path to your journal file (leave blank for {JOURNAL_FILE_PATH}): " - journal_path = os.path.abspath(input(path_query).strip()) or JOURNAL_FILE_PATH + journal_path = os.path.abspath(input(path_query).strip() or JOURNAL_FILE_PATH) default_config["journals"][DEFAULT_JOURNAL_KEY] = os.path.expanduser( os.path.expandvars(journal_path) )