예제 #1
0
 def test_unique_ids(self):
     task1 = Task('task 1')
     task2 = Task('task 2')
     task3 = Task('task 3')
     self.assertNotEqual(task1, task2)
     self.assertNotEqual(task1, task3)
     self.assertNotEqual(task2, task3)
     self.assertNotEqual(task1.created_date, task3.created_date)
예제 #2
0
    def test_add_multiple(self):
        fixture = [
            Task("task 1"),
            Task("task 2"),
            Task("task 3"),
        ]

        self.list.add_multiple(fixture)
        result = self.list.list()
        self.assertCountEqual(fixture, result)
예제 #3
0
    def test_list_all_tasks(self):
        fixture = [
            Task("task 1"),
            Task("task 2"),
            Task("task 3"),
        ]

        fixture[1].complete()
        self.list.add_multiple(fixture)
        self.assertCountEqual(fixture, self.list.list())
예제 #4
0
 def test_query_simple_title(self):
     fixture = [
         Task("task 1"),
         Task("task 2"),
     ]
     self.run_query_test(
         query="title = \"task 1\"",
         fixture=fixture,
         expected=[fixture[0]],
     )
예제 #5
0
 def test_query_priority_gt_1(self):
     fixture = [
         Task("task 1"),
         Task("task 2"),
         Task("other task", context="other", priority=2.0),
         Task("task 3"),
         Task("task 4"),
     ]
     self.run_query_test(query="priority > 1",
                         fixture=fixture,
                         expected=[fixture[2]])
예제 #6
0
    def test_completed_true(self):
        fixture = [
            Task("task 1"),
            Task("task 2", completed_date=datetime.now()),
            Task("other task", context="other", priority=2.0),
            Task("task 3", completed_date=datetime.now()),
            Task("task 4"),
        ]

        self.run_query_test(query="completed = true",
                            fixture=fixture,
                            expected=[fixture[1], fixture[3]])
예제 #7
0
 def test_query_other_context(self):
     fixture = [
         Task("task 1"),
         Task("task 2"),
         Task("other task", context="other"),
         Task("task 3"),
     ]
     self.run_query_test(
         query="context = other",
         fixture=fixture,
         expected=[fixture[2]],
     )
예제 #8
0
    def test_return_correct_current_task(self):
        tasks = [
            Task("task 1"),
            Task("task 2"),
        ]

        self.list.add_multiple(tasks)
        current = self.list.current()
        self.assertEqual(tasks[0], current)
        self.list.complete(tasks[0].id)
        current = self.list.current()
        self.assertEqual(tasks[1], current)
예제 #9
0
 def test_query_grouped_expressions(self):
     fixture = [
         Task("task 1"),
         Task("task 2"),
         Task("other task", context="other"),
         Task("task 3"),
         Task("task 4"),
     ]
     self.run_query_test(
         query=
         "(title = \"task 1\" and context = \"default\") or (context = \"other\")",
         fixture=fixture,
         expected=[fixture[0], fixture[2]],
     )
예제 #10
0
 def test_query_multiple_ors(self):
     fixture = [
         Task("task 1"),
         Task("task 2"),
         Task("other task", context="other"),
         Task("task 3"),
         Task("task 4"),
     ]
     self.run_query_test(
         query=
         "title = \"task 4\" or title = \"task 1\" or title = \"other task\"",
         fixture=fixture,
         expected=[fixture[0], fixture[4], fixture[2]],
     )
예제 #11
0
 def test_query_string_literal_only(self):
     fixture = [
         Task("task 1"),
         Task("task 2"),
         Task("other task", context="other"),
         Task("task 3"),
         Task("task 4"),
     ]
     self.run_query_test(query="task",
                         fixture=fixture,
                         expected=[
                             fixture[0], fixture[1], fixture[2], fixture[3],
                             fixture[4]
                         ])
예제 #12
0
 def test_query_priority_equals_1_0(self):
     fixture = [
         Task("task 1"),
         Task("task 2"),
         Task("other task", context="other"),
         Task("task 3"),
         Task("task 4"),
     ]
     self.run_query_test(query="priority = 1.0",
                         fixture=fixture,
                         expected=[
                             fixture[0], fixture[1], fixture[2], fixture[3],
                             fixture[4]
                         ])
예제 #13
0
 def search(self, ast):
     """Evaluate the AST and return a List of matching results."""
     return [
         Task.from_dict(doc)
         for doc in self._collection.find(self.__eval(ast.expression),
                                          projection={"_id": False})
     ]
예제 #14
0
 def test_add_a_note_to_a_task(self):
     task = Task("task to be noted")
     self.list.add(task)
     note = Note("a note")
     self.list.add_note(task.id, note)
     noted = self.list.find_by_id(task.id)
     self.assertCountEqual(noted.notes, [note])
예제 #15
0
 def test_update_a_task(self):
     task = Task("task to update")
     self.list.add(task)
     to_update = self.list.find_by_id(task.id)
     to_update.title = "task updated"
     self.list.update(to_update)
     updated = self.list.find_by_id(task.id)
     self.assertEqual(updated, to_update)
예제 #16
0
    def test_query_benchmark(self, task_list, benchmark):
        # Hand-crafted artisinal Abstract Syntax Tree
        ast = AST(
            Expression(
                Token('or'),
                right=Expression(
                    Token('and'),
                    left=Expression(Token('='),
                                    left=Expression(Token('context')),
                                    right=Expression(Token('work'))),
                    right=Expression(
                        Token('or'),
                        left=Expression(Token('>='),
                                        left=Expression(Token('priority')),
                                        right=Expression(Token('2'))),
                        right=Expression(Token('my little pony'))),
                ),
                left=Expression(
                    Token('and'),
                    right=Expression(Token('~'),
                                     right=Expression(
                                         Token('take out the trash')),
                                     left=Expression(Token('title'))),
                    left=Expression(Token('>'),
                                    left=Expression(Token('priority')),
                                    right=Expression(Token('5'))),
                ),
            ), )

        tasks = [
            Task("my little pony"),
            Task("this task won't match anything"),
            Task("a priority 2 task", priority=2.0),
            Task("take out the trash", priority=5.0),
            Task("work task 1", context="work"),
            Task("work task 2", context="work"),
            Task("task 1"),
            Task("task 2"),
            Task("task 3"),
            Task("task 4"),
        ]

        task_list.add_multiple(tasks)
        benchmark(task_list.search, ast=ast)
예제 #17
0
파일: add_cmd.py 프로젝트: zackse/taskforge
def import_file(filename, task_list):
    """Import tasks from filename into the configured task list"""
    import json

    with open(filename) as tasks_file:
        task = json.load(tasks_file)
        if isinstance(task, list):
            tasks = [Task.from_dict(t) for t in task]
            task_list.add_multiple(tasks)
        else:
            task_list.add(task)
예제 #18
0
 def current(self):
     """Return the current task."""
     doc = self._collection.find_one({
         "completed_date": None,
     },
                                     projection={"_id": False},
                                     sort=[
                                         ("priority", pymongo.DESCENDING),
                                         ("created_date",
                                          pymongo.ASCENDING),
                                     ])
     return Task.from_dict(doc)
예제 #19
0
    def test_sort_order(self):
        task1 = Task('task 1')
        task2 = Task('task 2')
        task3 = Task('task 3')

        listask1 = sorted([task3, task2, task1])

        self.assertEqual(listask1[0], task1)
        self.assertEqual(listask1[1], task2)
        self.assertEqual(listask1[2], task3)

        task1.priority = 3.0
        task2.priority = 1.0
        task3.priority = 2.0

        listask2 = sorted([task3, task2, task1])

        self.assertEqual(listask2[0], task1)
        self.assertEqual(listask2[1], task3)
        self.assertEqual(listask2[2], task2)
예제 #20
0
파일: add_cmd.py 프로젝트: zackse/taskforge
def run(args, task_list=None):
    """Parse the docopt args and call add_task."""
    if args['--from-file']:
        import_file(args['--from-file'], task_list)
        return

    if not args['<title>']:
        print('when not importing tasks title is required')
        sys.exit(1)

    title = ' '.join(args['<title>'])
    priority = float(args['--priority']) if args['--priority'] else 1.0
    context = args['--context'] if args['--context'] else 'default'
    body = args['--body'] if args['--body'] else ''

    if args['--top']:
        priority = top_priority(task_list)

    task_list.add(Task(title, body=body, context=context, priority=priority))
예제 #21
0
파일: sqlite.py 프로젝트: zackse/taskforge
    def task_from_row(self, row):
        """Convert a SQL row tuple back into a Task object.

        Raises a NotFoundError if row is None
        """
        if row is None:
            raise NotFoundError

        if len(row) != 7:
            raise NotFoundError

        return Task(
            id=row[0],
            title=row[1],
            body=row[2],
            context=row[3],
            priority=row[4],
            created_date=datetime.fromtimestamp(row[5]),
            completed_date=datetime.fromtimestamp(row[6]) if row[6] else None,
            notes=self.__get_notes(row[0]))
예제 #22
0
def run(args, task_list=None):
    """Open task by ID in $EDITOR. Update task based on result."""
    try:
        if args['<ID>']:
            task = task_list.find_by_id(args['<ID>'])
        else:
            task = task_list.current()

        tmp = NamedTemporaryFile(mode='w+', suffix='.toml', delete=False)
        toml.dump(task.to_dict(), tmp)
        tmp.close()

        editor(tmp.name)

        with open(tmp.name) as tmp:
            new_task = Task.from_dict(toml.load(tmp))

        task_list.update(new_task)
        os.remove(tmp.name)
    except NotFoundError:
        print('no task with that ID exists')
        sys.exit(1)
예제 #23
0
 def test_complete_a_task(self):
     task = Task('task to complete')
     self.list.add(task)
     self.list.complete(task.id)
     result = self.list.find_by_id(task.id)
     self.assertEqual(result.is_completed(), True)
예제 #24
0
 def find_by_id(self, task_id):
     """Find a task by task_id."""
     return Task.from_dict(
         self._collection.find_one({"id": task_id},
                                   projection={"_id": False}))
예제 #25
0
 def test_add_one_and_find_by_id(self):
     task = Task("task 1")
     self.list.add(task)
     res = self.list.find_by_id(task.id)
     self.assertEqual(task, res)
예제 #26
0
 def list(self):
     """Return a python list of the Task in this List."""
     return [
         Task.from_dict(doc)
         for doc in self._collection.find(projection={"_id": False})
     ]