Пример #1
0
def test_editor():
    """test for the issue in #666"""
    editor = StartEndEditor(
        BERLIN.localize(dt.datetime(2017, 10, 2, 13)),
        BERLIN.localize(dt.datetime(2017, 10, 4, 18)),
        conf=CONF
    )
    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
    assert editor.changed is False
    for _ in range(3):
        editor.keypress((10, ), 'tab')
    for _ in range(3):
        editor.keypress((10, ), 'shift tab')
    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
    assert editor.changed is False
Пример #2
0
def test_popup(monkeypatch):
    """making sure the popup calendar gets callend with the right inital value

    #405
    """
    class FakeCalendar():
        def store(self, *args, **kwargs):
            self.args = args
            self.kwargs = kwargs

    fake = FakeCalendar()
    monkeypatch.setattr('khal.ui.calendarwidget.CalendarWidget.__init__',
                        fake.store)
    see = StartEndEditor(START, END, CONF)
    see.widgets.startdate.keypress((22, ), 'enter')
    assert fake.kwargs['initial'] == date(2015, 4, 26)
    see.widgets.enddate.keypress((22, ), 'enter')
    assert fake.kwargs['initial'] == date(2015, 4, 27)
Пример #3
0
def test_editor():
    """test for the issue in #666"""
    editor = StartEndEditor(BERLIN.localize(dt.datetime(2017, 10, 2, 13)),
                            BERLIN.localize(dt.datetime(2017, 10, 4, 18)),
                            conf=CONF)
    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
    assert editor.changed is False
    for _ in range(3):
        editor.keypress((10, ), 'tab')
    for _ in range(3):
        editor.keypress((10, ), 'shift tab')
    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
    assert editor.changed is False
Пример #4
0
def test_convert_to_date():
    """test for the issue in #666"""
    editor = StartEndEditor(BERLIN.localize(dt.datetime(2017, 10, 2, 13)),
                            BERLIN.localize(dt.datetime(2017, 10, 4, 18)),
                            conf=CONF)
    canvas = editor.render((50, ), True)
    assert CanvasTranslator(canvas, palette).transform() == (
        '[ ] Allday\nFrom: \x1b[31m2.10.2017 \x1b[0m \x1b[34m13:00 \x1b[0m\n'
        'To:   \x1b[34m04.10.2017\x1b[0m \x1b[34m18:00 \x1b[0m\n')

    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
    assert editor.changed is False
    assert editor.allday is False

    # set to all day event
    editor.keypress((10, ), 'shift tab')
    editor.keypress((10, ), ' ')
    for _ in range(3):
        editor.keypress((10, ), 'tab')
    for _ in range(3):
        editor.keypress((10, ), 'shift tab')

    canvas = editor.render((50, ), True)
    assert CanvasTranslator(canvas, palette).transform() == (
        '[X] Allday\nFrom: \x1b[34m02.10.2017\x1b[0m  \n'
        'To:   \x1b[34m04.10.2017\x1b[0m  \n')

    assert editor.changed is True
    assert editor.allday is True
    assert editor.startdt == dt.date(2017, 10, 2)
    assert editor.enddt == dt.date(2017, 10, 4)
Пример #5
0
def test_convert_to_date():
    """test for the issue in #666"""
    editor = StartEndEditor(
        BERLIN.localize(dt.datetime(2017, 10, 2, 13)),
        BERLIN.localize(dt.datetime(2017, 10, 4, 18)),
        conf=CONF
    )
    canvas = editor.render((50, ), True)
    assert CanvasTranslator(canvas, palette).transform() == (
        '[ ] Allday\nFrom: \x1b[31m2.10.2017 \x1b[0m \x1b[34m13:00 \x1b[0m\n'
        'To:   \x1b[34m04.10.2017\x1b[0m \x1b[34m18:00 \x1b[0m\n'
    )

    assert editor.startdt == BERLIN.localize(dt.datetime(2017, 10, 2, 13))
    assert editor.enddt == BERLIN.localize(dt.datetime(2017, 10, 4, 18))
    assert editor.changed is False
    assert editor.allday is False

    # set to all day event
    editor.keypress((10, ), 'shift tab')
    editor.keypress((10, ), ' ')
    for _ in range(3):
        editor.keypress((10, ), 'tab')
    for _ in range(3):
        editor.keypress((10, ), 'shift tab')

    canvas = editor.render((50, ), True)
    assert CanvasTranslator(canvas, palette).transform() == (
        '[X] Allday\nFrom: \x1b[34m02.10.2017\x1b[0m  \n'
        'To:   \x1b[34m04.10.2017\x1b[0m  \n'
    )

    assert editor.changed is True
    assert editor.allday is True
    assert editor.startdt == dt.date(2017, 10, 2)
    assert editor.enddt == dt.date(2017, 10, 4)