remove py2 remnants and use mocks in tests

fstring wip
Run pyupgrade
fix broken pyupgrade fstring
run pyupgrade on plugin dir
fixup! remove py2 remnants and use mocks in tests
small print bugfix
The file=sys.stderr was part of the format(), so an error got printed to
stdout
Drop use of codecs package
Use builtins.open() instead
fixup! remove py2 remnants and use mocks in tests
This commit is contained in:
Peter Schmidbauer 2019-10-31 21:12:55 +01:00
parent b7e2e91af3
commit 9d8d6a83ae
28 changed files with 211 additions and 321 deletions

View file

@ -1,7 +1,5 @@
#!/usr/bin/env python
# encoding: utf-8
from __future__ import unicode_literals
import re
import textwrap
from datetime import datetime
@ -51,14 +49,14 @@ class Entry:
@staticmethod
def tag_regex(tagsymbols):
pattern = r'(?u)(?:^|\s)([{tags}][-+*#/\w]+)'.format(tags=tagsymbols)
return re.compile(pattern, re.UNICODE)
pattern = fr'(?u)(?:^|\s)([{tagsymbols}][-+*#/\w]+)'
return re.compile(pattern)
def _parse_tags(self):
tagsymbols = self.journal.config['tagsymbols']
return set(tag.lower() for tag in re.findall(Entry.tag_regex(tagsymbols), self.text))
return {tag.lower() for tag in re.findall(Entry.tag_regex(tagsymbols), self.text)}
def __unicode__(self):
def __str__(self):
"""Returns a string representation of the entry to be written into a journal file."""
date_str = self.date.strftime(self.journal.config['timeformat'])
title = "[{}] {}".format(date_str, self.title.rstrip("\n "))
@ -106,7 +104,7 @@ class Entry:
)
def __repr__(self):
return "<Entry '{0}' on {1}>".format(self.title.strip(), self.date.strftime("%Y-%m-%d %H:%M"))
return "<Entry '{}' on {}>".format(self.title.strip(), self.date.strftime("%Y-%m-%d %H:%M"))
def __hash__(self):
return hash(self.__repr__())