Skip to content
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

Merged
merged 9 commits into from
Nov 12, 2019

Conversation

pspeter
Copy link
Contributor

@pspeter pspeter commented Oct 31, 2019

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

  • Remove from __future__ imports
  • Switch util functions to builtins print()/input()
  • Rework tests to mock user input
  • Remove all mentions of unicode
  • Change str.format() to f-strings
  • Change codecs.open to builtins.open

Checklist

  • The code change is tested and works locally.
  • Tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?

This was referenced Oct 31, 2019
@pspeter pspeter marked this pull request as ready for review November 1, 2019 13:16
The file=sys.stderr was part of the format(), so an error got printed to stdout
Use builtins.open() instead
@pspeter pspeter force-pushed the cleanup-py2-leftovers branch 2 times, most recently from c098619 to 7d9795a Compare November 5, 2019 12:37
@wren wren added this to the v2.1.1 - Doctor's Orders milestone Nov 9, 2019
@wren wren changed the base branch from master to v2.1.1 November 9, 2019 22:47
@micahellison micahellison changed the base branch from v2.1.1 to master November 12, 2019 03:05
@@ -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
Copy link
Member

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)\\[([^\\]]+)\\] ")
Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace :(

Copy link
Member

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. "
Copy link
Member

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 {}.
Copy link
Member

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.

Copy link
Member

@wren wren left a 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!

@wren wren merged commit c098888 into jrnl-org:master Nov 12, 2019
@pspeter
Copy link
Contributor Author

pspeter commented Nov 12, 2019

Glad to help! But I could've fixed the nitpicks before merging (and squash the fixup commits) if you waited a little bit ;).
I'll rebase my other PRs now.

@pspeter pspeter deleted the cleanup-py2-leftovers branch November 12, 2019 09:12
@wren wren changed the title remove py2 remnants and use mocks in tests Drop Python 2 support, add mocks in tests Jan 10, 2020
@wren wren added the enhancement New feature or request label Jan 10, 2020
@wren wren added the deprecated Removed functionality or features label Jan 10, 2020
@lock
Copy link

lock bot commented May 21, 2020

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.

@lock lock bot added the 🔒 Outdated label May 21, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
deprecated Removed functionality or features enhancement New feature or request 🔒 Outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants