コード例 #1
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_format_colors():
    event = Event.fromString(_get_text('event_dt_simple'), **EVENT_KWARGS)
    format_ = '{red}{title}{reset}'
    assert human_formatter(format_)(event.attributes(dt.date(
        2014, 4, 9))) == '\x1b[31mAn Event\x1b[0m\x1b[0m'
    assert human_formatter(format_, colors=False)(event.attributes(
        dt.date(2014, 4, 9), colors=False)) == 'An Event'
コード例 #2
0
 def test_search_recurrence_id_only_multi(self, coll_vdirs):
     """test searching for recurring events which only have a recuid event,
     and no master"""
     coll, vdirs = coll_vdirs
     assert len(list(coll.search('Event'))) == 0
     event = Event.fromString(_get_text('event_dt_multi_recuid_no_master'),
                              calendar=cal1,
                              locale=LOCALE_BERLIN)
     coll.new(event, cal1)
     events = sorted(coll.search('Event'))
     assert len(events) == 2
     assert human_formatter('{start} {end} {title}')(events[0].attributes(
         dt.date.today())) == '30.06. 07:30 30.06. 12:00 Arbeit\x1b[0m'
     assert human_formatter('{start} {end} {title}')(events[1].attributes(
         dt.date.today())) == '07.07. 08:30 07.07. 12:00 Arbeit\x1b[0m'
コード例 #3
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_format_24():
    """test if events ending at 00:00/24:00 are displayed as ending the day
    before"""
    event_dt = _get_text('event_dt_simple')
    start = BERLIN.localize(dt.datetime(2014, 4, 9, 19, 30))
    end = BERLIN.localize(dt.datetime(2014, 4, 10))
    event = Event.fromString(event_dt, **EVENT_KWARGS)
    event.update_start_end(start, end)
    format_ = '{start-end-time-style} {title}{repeat-symbol}'
    assert human_formatter(format_)(event.attributes(dt.date(
        2014, 4, 9))) == '19:30-24:00 An Event\x1b[0m'
コード例 #4
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_event_dt_rr():
    event_dt_rr = _get_text('event_dt_rr')
    event = Event.fromString(event_dt_rr, **EVENT_KWARGS)
    assert event.recurring is True

    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 9))) == '09:30-10:30 An Event ⟳\x1b[0m'
    assert SEARCH_FORMATTER(event.attributes(dt.date(2014, 4, 9))) == \
        '09.04.2014 09:30-10:30 An Event ⟳\x1b[0m'
    assert human_formatter('{repeat-pattern}')(event.attributes(
        dt.date(2014, 4, 9))) == 'FREQ=DAILY;COUNT=10\x1b[0m'
コード例 #5
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_event_dt_duration():
    """event has no end, but duration"""
    event_dt_duration = _get_text('event_dt_duration')
    event = Event.fromString(event_dt_duration, **EVENT_KWARGS)
    assert event.start == BERLIN.localize(dt.datetime(2014, 4, 9, 9, 30))
    assert event.end == BERLIN.localize(dt.datetime(2014, 4, 9, 10, 30))
    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 9))) == '09:30-10:30 An Event\x1b[0m'
    assert SEARCH_FORMATTER(event.attributes(dt.date(2014, 4, 9))) == \
        '09.04.2014 09:30-10:30 An Event\x1b[0m'
    assert human_formatter('{duration}')(
        event.attributes(relative_to=dt.date.today())) == '1h\x1b[0m'
コード例 #6
0
 def test_invalid_timezones(self, coll_vdirs):
     """testing if we can delete any of two events in two different
     calendars with the same filename"""
     coll, vdirs = coll_vdirs
     event = Event.fromString(_get_text('invalid_tzoffset'),
                              calendar=cal1,
                              locale=LOCALE_BERLIN)
     coll.new(event, cal1)
     events = sorted(coll.search('Event'))
     assert len(events) == 1
     assert human_formatter('{start} {end} {title}')(events[0].attributes(dt.date.today())) == \
         '02.12. 08:00 02.12. 09:30 Some event\x1b[0m'
コード例 #7
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_event_d_long():
    event_d_long = _get_text('event_d_long')
    event = Event.fromString(event_d_long, **EVENT_KWARGS)
    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 9))) == '↦ Another Event\x1b[0m'
    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 10))) == '↔ Another Event\x1b[0m'
    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 11))) == '⇥ Another Event\x1b[0m'
    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 12))) == ' Another Event\x1b[0m'
    assert SEARCH_FORMATTER(event.attributes(dt.date(2014, 4, 16))) == \
        '09.04.2014-11.04.2014 Another Event\x1b[0m'
    assert human_formatter('{duration}')(
        event.attributes(relative_to=dt.date(2014, 4, 11))) == '3d\x1b[0m'
コード例 #8
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_event_dt_tz_missing():
    """localized event DTSTART;TZID=foo, but VTIMEZONE components missing"""
    event_str = _get_text('event_dt_local_missing_tz')
    event = Event.fromString(event_str, **EVENT_KWARGS)
    assert event.start == BERLIN.localize(dt.datetime(2014, 4, 9, 9, 30))
    assert event.end == BERLIN.localize(dt.datetime(2014, 4, 9, 10, 30))
    assert event.start_local == BERLIN.localize(dt.datetime(2014, 4, 9, 9, 30))
    assert event.end_local == BERLIN.localize(dt.datetime(2014, 4, 9, 10, 30))
    assert human_formatter('{duration}')(
        event.attributes(relative_to=dt.date.today())) == '1h\x1b[0m'

    event = Event.fromString(event_str, calendar='foobar', locale=LOCALE_MIXED)
    assert event.start == BERLIN.localize(dt.datetime(2014, 4, 9, 9, 30))
    assert event.end == BERLIN.localize(dt.datetime(2014, 4, 9, 10, 30))
    assert event.start_local == BOGOTA.localize(dt.datetime(2014, 4, 9, 2, 30))
    assert event.end_local == BOGOTA.localize(dt.datetime(2014, 4, 9, 3, 30))
コード例 #9
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_event_d_rr():
    event_d_rr = _get_text('event_d_rr')
    event = Event.fromString(event_d_rr, **EVENT_KWARGS)
    assert event.recurring is True
    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 9))) == ' Another Event ⟳\x1b[0m'
    assert SEARCH_FORMATTER(event.attributes(dt.date(2014, 4, 9))) == \
        '09.04.2014 Another Event ⟳\x1b[0m'
    assert human_formatter('{repeat-pattern}')(event.attributes(
        dt.date(2014, 4, 9))) == 'FREQ=DAILY;COUNT=10\x1b[0m'

    start = dt.date(2014, 4, 10)
    end = dt.date(2014, 4, 11)
    event = Event.fromString(event_d_rr, start=start, end=end, **EVENT_KWARGS)
    assert event.recurring is True
    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 10))) == ' Another Event ⟳\x1b[0m'
    assert SEARCH_FORMATTER(event.attributes(dt.date(2014, 4, 10))) == \
        '10.04.2014 Another Event ⟳\x1b[0m'
コード例 #10
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_event_dt_floating():
    """start and end time have no timezone, i.e. a floating event"""
    event_str = _get_text('event_dt_floating')
    event = Event.fromString(event_str, **EVENT_KWARGS)
    assert isinstance(event, FloatingEvent)
    assert LIST_FORMATTER(event.attributes(dt.date(
        2014, 4, 9))) == '09:30-10:30 An Event\x1b[0m'
    assert human_formatter('{duration}')(
        event.attributes(relative_to=dt.date.today())) == '1h\x1b[0m'
    assert SEARCH_FORMATTER(event.attributes(dt.date(2014, 4, 9))) == \
        '09.04.2014 09:30-10:30 An Event\x1b[0m'
    assert event.start == dt.datetime(2014, 4, 9, 9, 30)
    assert event.end == dt.datetime(2014, 4, 9, 10, 30)
    assert event.start_local == BERLIN.localize(dt.datetime(2014, 4, 9, 9, 30))
    assert event.end_local == BERLIN.localize(dt.datetime(2014, 4, 9, 10, 30))

    event = Event.fromString(event_str, calendar='foobar', locale=LOCALE_MIXED)
    assert event.start == dt.datetime(2014, 4, 9, 9, 30)
    assert event.end == dt.datetime(2014, 4, 9, 10, 30)
    assert event.start_local == BOGOTA.localize(dt.datetime(2014, 4, 9, 9, 30))
    assert event.end_local == BOGOTA.localize(dt.datetime(2014, 4, 9, 10, 30))
コード例 #11
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
def test_invalid_format_string():
    event_dt = _get_text('event_dt_simple')
    event = Event.fromString(event_dt, **EVENT_KWARGS)
    format_ = '{start-end-time-style} {title}{foo}'
    with pytest.raises(KeyError):
        human_formatter(format_)(event.attributes(dt.date(2014, 4, 9)))
コード例 #12
0
ファイル: event_test.py プロジェクト: PsychicNoodles/khal
import pytest
import pytz
from freezegun import freeze_time
from icalendar import vRecur, vText
from khal.khalendar.event import (AllDayEvent, Event, FloatingEvent,
                                  LocalizedEvent, create_timezone)
from khal.controllers import human_formatter

from .utils import (BERLIN, BOGOTA, GMTPLUS3, LOCALE_BERLIN, LOCALE_BOGOTA,
                    LOCALE_MIXED, NEW_YORK, _get_text, normalize_component)

EVENT_KWARGS = {'calendar': 'foobar', 'locale': LOCALE_BERLIN}

LIST_FORMAT = '{calendar-color}{cancelled}{start-end-time-style} {title}{repeat-symbol}'
LIST_FORMATTER = human_formatter(LIST_FORMAT)
SEARCH_FORMAT = '{calendar-color}{cancelled}{start-long}{to-style}' + \
    '{end-necessary-long} {title}{repeat-symbol}'
SEARCH_FORMATTER = human_formatter(SEARCH_FORMAT)


def test_no_initialization():
    with pytest.raises(ValueError):
        Event('', '')


def test_invalid_keyword_argument():
    with pytest.raises(TypeError):
        Event.fromString(_get_text('event_dt_simple'), keyword='foo')