Example #1
0
    def test_to_do_list_changed(self):
        # test that handlers work when the list of items changes totally
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do', completed=True)
        todo_list = ToDoList(items=[item_1, item_2])

        item_3 = ToDoItem(description='New thing to do')
        item_4 = ToDoItem(description='Another new thing to do')

        with self.assertTraitChanges(todo_list, 'remaining_items', count=1):
            with self.assertTraitChanges(todo_list, 'remaining', count=1):
                todo_list.items = [item_3, item_4]

        self.assertEqual(todo_list.remaining_items, [item_3, item_4])
        self.assertEqual(todo_list.remaining, 2)
Example #2
0
    def test_to_do_list(self):
        # test that handlers work statically
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do', completed=True)
        todo_list = ToDoList(items=[item_1, item_2])

        self.assertEqual(todo_list.remaining_items, [item_1])
        self.assertEqual(todo_list.remaining, 1)
Example #3
0
    def test_model_view_list_model_replaced(self):
        # test that changing model works
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do')
        todo_list = ToDoList(items=[item_1, item_2])

        model_view = ToDoListModelView(model=todo_list,
                                       display_selection='remaining')

        with self.assertTraitChanges(model_view, 'displayed_items', count=1):
            model_view.model = ToDoList(items=[item_1])

        self.assertEqual(len(model_view.displayed_items), 1)
        self.assertEqual(
            [controller.model for controller in model_view.displayed_items],
            [item_1])
        self.assertEqual(model_view.remaining, '1 item remaining')
Example #4
0
    def test_model_view_plural_remaining(self):
        # test 'remaining' property handles plural case
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do')
        todo_list = ToDoList(items=[item_1, item_2])

        model_view = ToDoListModelView(model=todo_list)

        self.assertEqual(model_view.remaining, '2 items remaining')
Example #5
0
    def test_model_view_none_remaining(self):
        # test 'remaining' property handles zero case
        item_1 = ToDoItem(description='Something to do', completed=True)
        item_2 = ToDoItem(description='Something else to do', completed=True)
        todo_list = ToDoList(items=[item_1, item_2])

        model_view = ToDoListModelView(model=todo_list)

        self.assertEqual(model_view.remaining, 'No items remaining')
Example #6
0
    def test_to_do_item_delete(self):
        # test that delete button works as expected
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do', completed=True)
        todo_list = ToDoList(items=[item_1, item_2])
        controller = ToDoItemController(model=item_1, todo_list=todo_list)

        with self.assertTraitChanges(todo_list, 'items_items', count=1):
            controller.delete = True

        self.assertEqual(todo_list.items, [item_2])
Example #7
0
    def test_to_do_list_completed_changed(self):
        # test that handlers work when an item's status changes
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do')
        todo_list = ToDoList(items=[item_1, item_2])

        with self.assertTraitChanges(todo_list, 'remaining_items', count=1):
            with self.assertTraitChanges(todo_list, 'remaining', count=1):
                item_2.completed = True

        self.assertEqual(todo_list.remaining_items, [item_1])
        self.assertEqual(todo_list.remaining, 1)
Example #8
0
def main():
    """ The application entry-point """
    # set up the model
    todo_list = ToDoList(
        items=[ToDoItem(description=item) for item in handle_arguments()])

    # defer TraitsUI dependent imports until arguments have been parsed
    from todo_list.view import ToDoListModelView

    # run the application
    model_view = ToDoListModelView(model=todo_list)
    model_view.configure_traits()
Example #9
0
    def test_model_view(self):
        # test that handlers work statically
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do', completed=True)
        todo_list = ToDoList(items=[item_1, item_2])

        model_view = ToDoListModelView(model=todo_list)

        self.assertEqual(len(model_view.displayed_items), 2)
        self.assertEqual(
            [controller.model for controller in model_view.displayed_items],
            todo_list.items)
        self.assertEqual(model_view.remaining, '1 item remaining')
Example #10
0
    def test_to_do_list_items_changed(self):
        # test that handlers work when the list of items is modified in-place
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do', completed=True)
        todo_list = ToDoList(items=[item_1, item_2])

        item_3 = ToDoItem(description='New thing to do')

        with self.assertTraitChanges(todo_list, 'remaining_items', count=1):
            with self.assertTraitChanges(todo_list, 'remaining', count=1):
                todo_list.items.append(item_3)

        self.assertEqual(todo_list.remaining_items, [item_1, item_3])
        self.assertEqual(todo_list.remaining, 2)
Example #11
0
    def test_model_view_selection(self):
        # test that 'remaining' selection works
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do', completed=True)
        todo_list = ToDoList(items=[item_1, item_2])

        model_view = ToDoListModelView(model=todo_list,
                                       display_selection='remaining')

        self.assertEqual(len(model_view.displayed_items), 1)
        self.assertEqual(
            [controller.model for controller in model_view.displayed_items],
            todo_list.remaining_items)
        self.assertEqual(model_view.remaining, '1 item remaining')
Example #12
0
    def test_model_view_new_item(self):
        # test that new item action works
        item_1 = ToDoItem(description='Something to do')
        item_2 = ToDoItem(description='Something else to do', completed=True)
        todo_list = ToDoList(items=[item_1, item_2])

        model_view = ToDoListModelView(model=todo_list,
                                       display_selection='remaining')

        with self.assertTraitChanges(model_view, 'displayed_items', count=1):
            model_view.new_item(None)

        self.assertEqual(len(model_view.displayed_items), 2)
        self.assertEqual(
            [controller.model for controller in model_view.displayed_items],
            todo_list.remaining_items)
        self.assertEqual(model_view.remaining, '2 items remaining')
Example #13
0
def main():
    """ The application entry-point """
    # set up the gettext translation infrastructure
    bindtextdomain('todo-list', TRANSLATIONS_DIR)
    textdomain('todo-list')

    # parse the arguments
    items = handle_arguments()

    # defer TraitsUI dependent imports until _ is installed in builtins
    from todo_list.model import ToDoList, ToDoItem
    from todo_list.view import ToDoListModelView

    # set up the model
    todo_list = ToDoList(
        items=[ToDoItem(description=item) for item in items]
    )

    # run the application
    model_view = ToDoListModelView(model=todo_list)
    model_view.configure_traits()