-
-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop Python 2 support, add mocks in tests #705
Conversation
The file=sys.stderr was part of the format(), so an error got printed to stdout
Use builtins.open() instead
c098619
to
7d9795a
Compare
@@ -13,11 +13,11 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x | |||
|
|||
Scenario: Upgrading a journal encrypted with jrnl 1.x | |||
Given we use the config "encrypted_old.json" | |||
When we run "jrnl -n 1" and enter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
@@ -118,7 +115,7 @@ def _parse(self, journal_txt): | |||
# Initialise our current entry | |||
entries = [] | |||
|
|||
date_blob_re = re.compile("(?:^|\n)\[([^\\]]+)\] ") | |||
date_blob_re = re.compile("(?:^|\n)\\[([^\\]]+)\\] ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(optional nitpick): use raw string here for regex to avoid double-escaping
pass | ||
|
||
log.debug('Using journal "%s"', journal_name) | ||
mode_compose, mode_export, mode_import = guess_mode(args, config) | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing whitespace :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, this is optional and a nitpick
@@ -18,7 +17,8 @@ class YAMLExporter(TextExporter): | |||
def export_entry(cls, entry, to_multifile=True): | |||
"""Returns a markdown representation of a single entry, with YAML front matter.""" | |||
if to_multifile is False: | |||
print("{}ERROR{}: YAML export must be to individual files. Please specify a directory to export to.".format("\033[31m", "\033[0m", file=sys.stderr)) | |||
print("{}ERROR{}: YAML export must be to individual files. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(optional) missed ERROR_COLOR
, etc here
config_file = f.read() | ||
if not config_file.strip().startswith("{"): | ||
return | ||
|
||
config = util.load_config(config_path) | ||
|
||
util.prompt("""Welcome to jrnl {}. | ||
print("""Welcome to jrnl {}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer going to stderr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is absolutely fantastic, @pspeter!
I left a few notes for random little nitpicks, but this PR is approved with flying colors. Thank you!
Glad to help! But I could've fixed the nitpicks before merging (and squash the fixup commits) if you waited a little bit ;). |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR should completely remove all the Python 2 compatibility features and other leftovers.
Closes #701, closes #615, fixes #700, might fix #667.
I also removed the wonky testing utilities in jrnl.utils and instead used unittest.mock.patch to simulate user inputs in the tests. It's a bit unusual as well this way, but at least we don't have to mess with replacing std.stdin and sys.stderr and what not. If somebody knows a simpler way to simulate user input that works with builtins.input, getpass.getpass as well as sys.stdin.read, let me know.
This is a bit of a bigger PR, but the tests all pass.
Todo
Checklist