mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-29 05:56:14 +02:00
Fix OS compatibility issues for editors with spaces, slashes, and quotes (#1153)
* Fix inverted POSIX check, refactor os_compat, and add tests for it * Fix missing parentheses and remove skip_win on test that is passing in Windows now * Fix expected quotes in quoted args * Make output clearer on failing test * Bringing skip_win back to test whose failure is a bit more complicated than expected
This commit is contained in:
parent
b6b6e7750e
commit
9e6cd8820f
7 changed files with 121 additions and 20 deletions
|
@ -42,7 +42,7 @@ def before_feature(context, feature):
|
|||
feature.skip()
|
||||
return
|
||||
|
||||
if "skip_win" in feature.tags and on_windows:
|
||||
if "skip_win" in feature.tags and on_windows():
|
||||
feature.skip("Skipping on Windows")
|
||||
return
|
||||
|
||||
|
@ -69,7 +69,7 @@ def before_scenario(context, scenario):
|
|||
scenario.skip()
|
||||
return
|
||||
|
||||
if "skip_win" in scenario.effective_tags and on_windows:
|
||||
if "skip_win" in scenario.effective_tags and on_windows():
|
||||
scenario.skip("Skipping on Windows")
|
||||
return
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ from collections import defaultdict
|
|||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shlex
|
||||
import time
|
||||
from unittest.mock import patch
|
||||
|
||||
|
@ -23,7 +22,7 @@ from jrnl import __version__
|
|||
from jrnl import plugins
|
||||
from jrnl.cli import cli
|
||||
from jrnl.config import load_config
|
||||
from jrnl.os_compat import on_windows
|
||||
from jrnl.os_compat import split_args
|
||||
|
||||
try:
|
||||
import parsedatetime.parsedatetime_consts as pdt
|
||||
|
@ -88,10 +87,6 @@ class FailedKeyring(keyring.backend.KeyringBackend):
|
|||
keyring.set_keyring(TestKeyring())
|
||||
|
||||
|
||||
def ushlex(command):
|
||||
return shlex.split(command, posix=not on_windows)
|
||||
|
||||
|
||||
def read_journal(context, journal_name="default"):
|
||||
configuration = load_config(context.config_path)
|
||||
with open(configuration["journals"][journal_name]) as journal_file:
|
||||
|
@ -319,7 +314,7 @@ def run_with_input(context, command, inputs=""):
|
|||
else:
|
||||
text = iter([inputs])
|
||||
|
||||
args = ushlex(command)[1:]
|
||||
args = split_args(command)[1:]
|
||||
|
||||
def _mock_editor(command):
|
||||
context.editor_command = command
|
||||
|
@ -403,7 +398,7 @@ def run(context, command, text=""):
|
|||
cache_dir = os.path.join("features", "cache", context.cache_dir)
|
||||
command = command.format(cache_dir=cache_dir)
|
||||
|
||||
args = ushlex(command)
|
||||
args = split_args(command)
|
||||
|
||||
def _mock_editor(command):
|
||||
context.editor_command = command
|
||||
|
|
|
@ -169,17 +169,24 @@ def assert_exported_yaml_file_content(context, file_path, cache_dir=None):
|
|||
|
||||
for actual_line, expected_line in zip(actual_content, expected_content):
|
||||
if actual_line.startswith("tags: ") and expected_line.startswith("tags: "):
|
||||
assert_equal_tags_ignoring_order(actual_line, expected_line)
|
||||
assert_equal_tags_ignoring_order(
|
||||
actual_line, expected_line, actual_content, expected_content
|
||||
)
|
||||
else:
|
||||
assert actual_line.strip() == expected_line.strip(), [
|
||||
actual_line.strip(),
|
||||
expected_line.strip(),
|
||||
[actual_line.strip(), expected_line.strip()],
|
||||
[actual_content, expected_content],
|
||||
]
|
||||
|
||||
|
||||
def assert_equal_tags_ignoring_order(actual_line, expected_line):
|
||||
def assert_equal_tags_ignoring_order(
|
||||
actual_line, expected_line, actual_content, expected_content
|
||||
):
|
||||
actual_tags = set(tag.strip() for tag in actual_line[len("tags: ") :].split(","))
|
||||
expected_tags = set(
|
||||
tag.strip() for tag in expected_line[len("tags: ") :].split(",")
|
||||
)
|
||||
assert actual_tags == expected_tags, [actual_tags, expected_tags]
|
||||
assert actual_tags == expected_tags, [
|
||||
[actual_tags, expected_tags],
|
||||
[expected_content, actual_content],
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue