From 1bc431f5390b280d1f162131f592cde03028fabb Mon Sep 17 00:00:00 2001 From: Christian Geier Date: Thu, 1 Nov 2018 09:13:39 +0100 Subject: [PATCH] Make flake8 happy Ignore new flake8 warnings and fix some style issues. --- khal/khalendar/__init__.py | 2 +- khal/khalendar/event.py | 6 +-- tests/cli_test.py | 8 ++-- tests/parse_datetime_test.py | 90 ++++++++++++++++++------------------ tox.ini | 4 +- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/khal/khalendar/__init__.py b/khal/khalendar/__init__.py index f00045440..e74e629d8 100644 --- a/khal/khalendar/__init__.py +++ b/khal/khalendar/__init__.py @@ -19,4 +19,4 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -from .khalendar import CalendarCollection # flake8: noqa +from .khalendar import CalendarCollection # noqa: F401 diff --git a/khal/khalendar/event.py b/khal/khalendar/event.py index d292ed7b8..5c006c561 100644 --- a/khal/khalendar/event.py +++ b/khal/khalendar/event.py @@ -25,7 +25,6 @@ import datetime as dt import logging import os -from collections import defaultdict import icalendar import pytz @@ -138,7 +137,7 @@ def fromVEvents(cls, events_list, ref=None, **kwargs): if ref is None: ref = 'PROTO' if ref in vevents.keys() else list(vevents.keys())[0] try: - if type(vevents[ref]['DTSTART'].dt) != type(vevents[ref]['DTEND'].dt): # flake8: noqa + if type(vevents[ref]['DTSTART'].dt) != type(vevents[ref]['DTEND'].dt): # noqa: E721 raise ValueError('DTSTART and DTEND should be of the same type (datetime or date)') except KeyError: pass @@ -382,7 +381,8 @@ def _can_handle_alarm(alarm): """ Decides whether we can handle a certain alarm. """ - return alarm.get('ACTION') == 'DISPLAY' and isinstance(alarm.get('TRIGGER').dt, dt.timedelta) + return alarm.get('ACTION') == 'DISPLAY' and \ + isinstance(alarm.get('TRIGGER').dt, dt.timedelta) @property def alarms(self): diff --git a/tests/cli_test.py b/tests/cli_test.py index 1f20c8678..5dbfbcfcc 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -665,10 +665,10 @@ def test_print_ics_command(runner): # Non existing file result = runner.invoke(main_khal, ['printics', 'nonexisting_file']) assert result.exception - assert ('Error: Invalid value for "ics": Could not open file: ' \ - in result.output or \ - 'Error: Invalid value for "[ICS]": Could not open file:' \ - in result.output) + assert ( + 'Error: Invalid value for "ics": Could not open file: ' in result.output or + 'Error: Invalid value for "[ICS]": Could not open file:' + in result.output) # Run on test files result = runner.invoke(main_khal, ['printics', _get_ics_filepath('cal_d')]) diff --git a/tests/parse_datetime_test.py b/tests/parse_datetime_test.py index 16650a2be..7f21aeedb 100644 --- a/tests/parse_datetime_test.py +++ b/tests/parse_datetime_test.py @@ -165,7 +165,7 @@ def test_short_format_contains_year(self): 'longdatetimeformat': '%Y-%m-%d %H:%M', } assert (dt.datetime(2017, 1, 1), True) == guessdatetimefstr( - '2017-1-1'.split(), locale=locale, default_day=dt.datetime.today()) + '2017-1-1'.split(), locale=locale, default_day=dt.datetime.today()) assert (dt.datetime(2017, 1, 1, 16, 30), False) == guessdatetimefstr( '2017-1-1 16:30'.split(), locale=locale, default_day=dt.datetime.today()) @@ -326,55 +326,55 @@ def test_short_format_contains_year(self): # start and end date same, no explicit end date given ('25.10.2013 18:00 20:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T180000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T200000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T180000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T200000')), # start and end date same, ends 24:00 which should be 00:00 (start) of next # day ('25.10.2013 18:00 24:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T180000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131026T000000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T180000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131026T000000')), # start and end date same, explicit end date (but no year) given ('25.10.2013 18:00 26.10. 20:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T180000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131026T200000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T180000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131026T200000')), ('30.12.2013 18:00 2.1. 20:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131230T180000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140102T200000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131230T180000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140102T200000')), # only start date given (no year, past day and month) ('25.01. 18:00 20:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20150125T180000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20150125T200000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20150125T180000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20150125T200000')), # date ends next day, but end date not given ('25.10.2013 23:00 0:30 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T230000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131026T003000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T230000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131026T003000')), ('2.2. 23:00 0:30 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20150202T230000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20150203T003000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20150202T230000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20150203T003000')), # only start datetime given ('25.10.2013 06:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T060000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T070000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T060000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20131025T070000')), # timezone given ('25.10.2013 06:00 America/New_York Äwesöme Event', _create_vevent( - 'DTSTART;TZID=America/New_York;VALUE=DATE-TIME:20131025T060000', - 'DTEND;TZID=America/New_York;VALUE=DATE-TIME:20131025T070000')) + 'DTSTART;TZID=America/New_York;VALUE=DATE-TIME:20131025T060000', + 'DTEND;TZID=America/New_York;VALUE=DATE-TIME:20131025T070000')) ) @@ -388,8 +388,8 @@ def test_construct_event_format_de(): test_set_format_us = _create_testcases( ('1999/12/31-06:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=America/New_York;VALUE=DATE-TIME:19991231T060000', - 'DTEND;TZID=America/New_York;VALUE=DATE-TIME:19991231T070000')), + 'DTSTART;TZID=America/New_York;VALUE=DATE-TIME:19991231T060000', + 'DTEND;TZID=America/New_York;VALUE=DATE-TIME:19991231T070000')), ('2014/12/18 2014/12/20 Äwesöme Event', _create_vevent('DTSTART;VALUE=DATE:20141218', @@ -409,20 +409,20 @@ def test__construct_event_format_us(): # today ('8:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T080000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T090000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T080000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T090000')), # today until tomorrow ('22:00 1:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T220000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140217T010000')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T220000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140217T010000')), # other timezone ('22:00 1:00 Europe/London Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/London;VALUE=DATE-TIME:20140216T220000', - 'DTEND;TZID=Europe/London;VALUE=DATE-TIME:20140217T010000')), + 'DTSTART;TZID=Europe/London;VALUE=DATE-TIME:20140216T220000', + 'DTEND;TZID=Europe/London;VALUE=DATE-TIME:20140217T010000')), ('15.06. Äwesöme Event', _create_vevent('DTSTART;VALUE=DATE:20140615', @@ -440,9 +440,9 @@ def test__construct_event_format_de_complexer(): test_set_leap_year = _create_testcases( ('29.02. Äwesöme Event', _create_vevent( - 'DTSTART;VALUE=DATE:20160229', - 'DTEND;VALUE=DATE:20160301', - 'DTSTAMP;VALUE=DATE-TIME:20160101T202122Z')), + 'DTSTART;VALUE=DATE:20160229', + 'DTEND;VALUE=DATE:20160301', + 'DTSTAMP;VALUE=DATE-TIME:20160101T202122Z')), ) @@ -461,16 +461,16 @@ def test_leap_year(): # today ('8:00 Äwesöme Event :: this is going to be awesome', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T080000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T090000', - 'DESCRIPTION:this is going to be awesome')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T080000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T090000', + 'DESCRIPTION:this is going to be awesome')), # today until tomorrow ('22:00 1:00 Äwesöme Event :: Will be even better', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T220000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140217T010000', - 'DESCRIPTION:Will be even better')), + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T220000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140217T010000', + 'DESCRIPTION:Will be even better')), ('15.06. Äwesöme Event :: and again', _create_vevent('DTSTART;VALUE=DATE:20140615', @@ -491,10 +491,10 @@ def test_description(): # today ('8:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T080000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T090000', - 'DESCRIPTION:please describe the event', - 'RRULE:FREQ=DAILY;UNTIL=20150605T000000'))) + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T080000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T090000', + 'DESCRIPTION:please describe the event', + 'RRULE:FREQ=DAILY;UNTIL=20150605T000000'))) def test_repeat(): @@ -541,11 +541,11 @@ def test_alarm(): # today ('8:00 Äwesöme Event', _create_vevent( - 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T080000', - 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T090000', - 'CATEGORIES:boring meeting', - 'DESCRIPTION:please describe the event', - 'LOCATION:in the office'))) + 'DTSTART;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T080000', + 'DTEND;TZID=Europe/Berlin;VALUE=DATE-TIME:20140216T090000', + 'CATEGORIES:boring meeting', + 'DESCRIPTION:please describe the event', + 'LOCATION:in the office'))) @freeze_time('2014-02-16 12:00:00') diff --git a/tox.ini b/tox.ini index f3e83b455..9f8d76dfe 100644 --- a/tox.ini +++ b/tox.ini @@ -33,7 +33,7 @@ skip_install=True whitelist_externals = sh deps = flake8 commands = - flake8 tests khal setup.py + flake8 --ignore E252,W504,E121 tests khal setup.py sh -c '! grep -ri seperat */*' [testenv:docs] @@ -52,4 +52,4 @@ commands = [flake8] max-line-length = 100 -exclude=.tox,examples,doc +exclude = .tox,examples,doc