Пример #1
0
def test_show_save_errors(default_database, default_formatter, todo_factory):
    todo = todo_factory()
    lists = list(default_database.lists())

    editor = TodoEditor(todo, lists, default_formatter)
    # editor._loop = mock.MagicMock()

    editor._due.set_edit_text('not a date')
    editor._keypress('ctrl s')

    assert (editor.left_column.body.contents[2].get_text()[0] ==
            'Time description not recognized: not a date')
Пример #2
0
def test_todo_editor_summary(default_database, todo_factory,
                             default_formatter):
    todo = todo_factory()
    lists = list(default_database.lists())

    editor = TodoEditor(todo, lists, default_formatter)
    assert editor._summary.edit_text == "YARR!"

    editor._summary.edit_text = "Goodbye"
    with pytest.raises(ExitMainLoop):  # Look at editor._msg_text if this fails
        editor._keypress("ctrl s")

    assert todo.summary == "Goodbye"
Пример #3
0
def test_todo_editor_priority(default_database, todo_factory,
                              default_formatter):
    todo = todo_factory(priority=1)
    lists = list(default_database.lists())

    editor = TodoEditor(todo, lists, default_formatter)
    assert editor._priority.label == "high"

    editor._priority.keypress(10, "right")
    with pytest.raises(ExitMainLoop):  # Look at editor._msg_text if this fails
        editor._keypress("ctrl s")

    assert todo.priority == 0
Пример #4
0
def test_ctrl_c_clears(default_formatter, todo_factory):
    todo = todo_factory()
    editor = TodoEditor(todo, [todo.list], default_formatter)

    # Simulate that ctrl+c gets pressed, since we can't *really* do that
    # trivially inside unit tests.
    with mock.patch(
        'urwid.main_loop.MainLoop.run', side_effect=KeyboardInterrupt
    ), mock.patch(
        'urwid.main_loop.MainLoop.stop',
    ) as mocked_stop:
        editor.edit()

    assert mocked_stop.call_count == 1
Пример #5
0
def test_todo_editor_due(default_database, todo_factory, default_formatter):
    tz = pytz.timezone("CET")

    todo = todo_factory(due=datetime(2017, 3, 4, 14))
    lists = list(default_database.lists())
    default_formatter.tz = tz

    editor = TodoEditor(todo, lists, default_formatter)
    assert editor._due.edit_text == "2017-03-04 14:00"

    editor._due.edit_text = "2017-03-10 12:00"
    with pytest.raises(ExitMainLoop):  # Look at editor._msg_text if this fails
        editor._keypress("ctrl s")

    assert todo.due == datetime(2017, 3, 10, 12, tzinfo=tz)
Пример #6
0
Файл: cli.py Проект: hut/todoman
def edit(ctx, id, todo_properties, interactive, raw, description):
    '''
    Edit the task with id ID.
    '''
    todo = ctx.db.todo(id)
    if raw:
        click.edit(filename=todo.path)
        return
    old_list = todo.list

    changes = False
    for key, value in todo_properties.items():
        if value:
            changes = True
            setattr(todo, key, value)

    if description:
        if interactive is None:
            interactive = False
        old_description = todo.description
        new_description = click.edit(todo.description)
        if new_description is not None and old_description != new_description:
            todo.description = new_description.strip()
            changes = True

    if interactive or (not changes and interactive is None):
        ui = TodoEditor(todo, ctx.db.lists(), ctx.ui_formatter)
        ui.edit()

    # This little dance avoids duplicates when changing the list:
    new_list = todo.list
    todo.list = old_list
    ctx.db.save(todo)
    if old_list != new_list:
        ctx.db.move(todo, new_list=new_list, from_list=old_list)
    click.echo(ctx.formatter.detailed(todo))
Пример #7
0
def edit(ctx, id, todo_properties, interactive):
    '''
    Edit the task with id ID.
    '''
    todo = ctx.db.todo(id)
    old_list = todo.list

    changes = False
    for key, value in todo_properties.items():
        if value:
            changes = True
            setattr(todo, key, value)

    if interactive or (not changes and interactive is None):
        ui = TodoEditor(todo, ctx.db.lists(), ctx.ui_formatter)
        ui.edit()

    # This little dance avoids duplicates when changing the list:
    new_list = todo.list
    todo.list = old_list
    ctx.db.save(todo)
    if old_list != new_list:
        ctx.db.move(todo, new_list=new_list, from_list=old_list)
    click.echo(ctx.formatter.detailed(todo))
Пример #8
0
def test_toggle_help(default_database, default_formatter, todo_factory):
    todo = todo_factory()
    lists = list(default_database.lists())

    editor = TodoEditor(todo, lists, default_formatter)
    editor._loop = mock.MagicMock()
    assert editor._help_text not in editor.left_column.body.contents

    editor._keypress("f1")
    # Help text is made visible
    assert editor._help_text in editor.left_column.body.contents

    # Called event_loop.draw_screen
    assert editor._loop.draw_screen.call_count == 1
    assert editor._loop.draw_screen.call_args == mock.call()

    editor._keypress("f1")
    # Help text is made visible
    assert editor._help_text not in editor.left_column.body.contents

    # Called event_loop.draw_screen
    assert editor._loop.draw_screen.call_count == 2
    assert editor._loop.draw_screen.call_args == mock.call()