From 34207f872f200a58c4a9dc3da864bf45df8d3b72 Mon Sep 17 00:00:00 2001 From: Micah Jerome Ellison Date: Sat, 4 Jul 2020 15:09:05 -0700 Subject: [PATCH] Add Python version check and faulty test to confirm it's working (should fail on 3.6 build only) --- features/core.feature | 4 ++++ features/steps/core.py | 11 +++++++++++ jrnl/cli.py | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/features/core.feature b/features/core.feature index 5bec4e95..99bcf5a5 100644 --- a/features/core.feature +++ b/features/core.feature @@ -135,3 +135,7 @@ Feature: Basic reading and writing to a journal When we run "jrnl --diagnostic" Then the output should contain "jrnl" And the output should contain "Python" + + Scenario: Version warning appears for versions below 3.7 + When we run "jrnl --diagnostic" + Then the Python version warning should appear if our version is below "3.7" diff --git a/features/steps/core.py b/features/steps/core.py index 13b11bd2..14c5268a 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -371,6 +371,17 @@ def list_journal_directory(context, journal="default"): for file in f: print(os.path.join(root, file)) +@then("the Python version warning should appear if our version is below {version}") +def check_python_warning_if_version_low_enough(context, version): + import packaging.version + import platform + + if packaging.version.parse(platform.python_version()) < packaging.version.parse(version): + out = context.stderr_capture.getvalue() + assert "THIS SHOULD FAIL ON 3.6 REMOVE WHEN CONFIRMING - WARNING: Python versions" in out + else: + assert True + @then("fail") def debug_fail(context): diff --git a/jrnl/cli.py b/jrnl/cli.py index 8e583391..e97130ac 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -21,6 +21,7 @@ import argparse import logging +import packaging.version import platform import re import sys @@ -313,6 +314,9 @@ def configure_logger(debug=False): def run(manual_args=None): + if packaging.version.parse(platform.python_version()) < packaging.version.parse('3.7'): + print("WARNING: Python versions below 3.7 are not supported by jrnl\n", file=sys.stderr) + if manual_args is None: manual_args = sys.argv[1:]