Example #1
0
def test_mark_completed():
    unit = TodoList([{
        'title': 'Foo'
    }, {
        'title': 'Bar',
        'is_completed': True
    }, {
        'title': 'Baz'
    }, {
        'title': 'Bar'
    }, {
        'title': 'Quux'
    }, {
        'title': 'Bar'
    }])
    unit.mark_completed('Bar')

    assert unit.items == [
        TodoItem('Foo'),
        TodoItem('Bar', is_completed=True),
        TodoItem('Baz'),
        TodoItem('Bar', is_completed=True),
        TodoItem('Quux'),
        TodoItem('Bar')
    ]
Example #2
0
def test_delete_all_completed():
    # All odd items are completed
    unit = TodoList([{
        'title': f"Item {i}",
        'is_completed': i % 2 == 1
    } for i in range(0, 10)])
    unit.delete_all_completed()

    # Result should only contain the even items
    assert unit.items == [TodoItem(f"Item {i}") for i in range(0, 10, 2)]
Example #3
0
def test_delete_with_matching_item():
    unit = TodoList([{
        'title': 'Foo'
    }, {
        'title': 'Bar'
    }, {
        'title': 'Baz'
    }, {
        'title': 'Bar',
        'priority': 2
    }, {
        'title': 'Quux'
    }])
    unit.delete('Bar')

    assert unit.items == [
        TodoItem('Foo'),
        TodoItem('Baz'),
        TodoItem('Bar', 2),
        TodoItem('Quux')
    ]
Example #4
0
def test_constructor():
    unit = TodoList([{
        'title': 'Foo'
    }, {
        'title': 'Bar',
        'priority': 10
    }, {
        'title': 'Baz',
        'is_completed': True
    }])
    assert unit.items == [
        TodoItem('Foo'),
        TodoItem('Bar', priority=10),
        TodoItem('Baz', is_completed=True)
    ]
Example #5
0
def test_save_to_and_load_from_file():
    buffer = BytesIO()
    unit = TodoList([{
        'title': 'Foo'
    }, {
        'title': 'Bar',
        'is_completed': True
    }, {
        'title': 'Baz'
    }, {
        'title': 'Bar',
        'priority': 2
    }, {
        'title': 'Quux',
        'is_completed': True
    }])
    unit.save_to_file(buffer)
    buffer.seek(0)

    restored_unit = TodoList.load_from_file(buffer)
    assert isinstance(restored_unit, TodoList)
    assert restored_unit is not unit
    assert restored_unit.items is not unit.items
    assert restored_unit.items == unit.items
Example #6
0
def test_str():
    unit = TodoList([{
        'title': 'Foo'
    }, {
        'title': 'Bar',
        'is_completed': True
    }, {
        'title': 'Baz'
    }, {
        'title': 'Bar',
        'priority': 2
    }, {
        'title': 'Quux',
        'is_completed': True
    }])
    assert str(unit) == """Todo List:
def main():
    args = get_args()
    if args.create:
        with open(args.file, 'wb'):
            pass
    else:
        save_todos = True
        with open(args.file, 'rb') as file:
            todos = TodoList.load_from_file(file)
        if args.add:
            title, priority = args.add
            todos.add(title, int(priority))
        elif args.delete is not None:
            todos.delete(args.delete)
        elif args.mark_completed is not None:
            todos.mark_completed(args.mark_completed)
        elif args.delete_all_completed:
            todos.delete_all_completed()
        else:
            save_todos = False
            print(todos)
        if save_todos:
            with open(args.file, 'wb') as file:
                todos.save_to_file(file)
Example #8
0
def test_add_with_explicit_values():
    unit = TodoList([{'title': 'Foo'}])
    unit.add('Bar', 10, True)

    assert unit.items == [TodoItem('Foo'), TodoItem('Bar', 10, True)]
Example #9
0
def test_add_with_defaults():
    unit = TodoList([{'title': 'Foo'}])
    unit.add('Bar')

    assert unit.items == [TodoItem('Foo'), TodoItem('Bar')]
Example #10
0
def test_repr():
    unit = TodoList([{'title': 'Foo'}])
    assert repr(unit) == "TodoList([TodoItem('Foo', 1, False)])"
Example #11
0
def test_load_from_empty_file():
    buffer = BytesIO()
    unit = TodoList.load_from_file(buffer)

    assert isinstance(unit, TodoList)
    assert unit.items == []