def test_filter18(self): todos = load_file('test/data/FilterTest1.txt') grep1 = Filter.GrepFilter('part') grep2 = Filter.GrepFilter('important') grep = Filter.OrFilter(grep1, grep2) filtered_todos = grep.filter(todos) reference = load_file('test/data/FilterTest5-result.txt') self.assertEquals(todolist_to_string(filtered_todos), \ todolist_to_string(reference))
def test_filter17(self): todos = load_file('test/data/FilterTest1.txt') grep1 = Filter.GrepFilter('task') grep2 = Filter.GrepFilter('project') andfilter = Filter.AndFilter(grep1, grep2) filtered_todos = andfilter.filter(todos) reference = load_file('test/data/FilterTest4-result.txt') self.assertEquals(todolist_to_string(filtered_todos), \ todolist_to_string(reference))
def arg_filters(): result = [] for arg in self.args: if re.match(Filter.ORDINAL_TAG_MATCH, arg): argfilter = Filter.OrdinalTagFilter(arg) elif len(arg) > 1 and arg[0] == '-': # when a word starts with -, exclude it argfilter = Filter.GrepFilter(arg[1:]) argfilter = Filter.NegationFilter(argfilter) else: argfilter = Filter.GrepFilter(arg) result.append(argfilter) return result
def test_filter16(self): todos = load_file('test/data/FilterTest1.txt') grep = Filter.NegationFilter(Filter.GrepFilter('+project')) filtered_todos = grep.filter(todos) reference = load_file('test/data/FilterTest3-result.txt') self.assertEquals(todolist_to_string(filtered_todos), \ todolist_to_string(reference))
def test_filter8(self): """ Test case sensitive match (forced, with lowercase). """ todos = load_file('test/data/FilterTest1.txt') grep = Filter.GrepFilter('+Project', False) filtered_todos = grep.filter(todos) reference = load_file('test/data/FilterTest1a-result.txt') self.assertEquals(todolist_to_string(filtered_todos), \ todolist_to_string(reference))
def test_filter4(self): """ Test case insensitive match. """ todos = load_file('test/data/FilterTest1.txt') grep = Filter.GrepFilter('+project') filtered_todos = grep.filter(todos) reference = load_file('test/data/FilterTest1a-result.txt') self.assertEquals(todolist_to_string(filtered_todos), \ todolist_to_string(reference))
def test_view(self): """ Check filters and printer for views. """ todofile = TodoFile('test/data/FilterTest1.txt') ref = load_file('test/data/ViewTest1-result.txt') todolist = TodoList(todofile.read()) sorter = Sorter('text') todofilter = Filter.GrepFilter('+Project') view = todolist.view(sorter, [todofilter]) self.assertEqual(print_view(view), todolist_to_string(ref))
def todo_by_regexp(p_identifier): """ Returns the todo that is (uniquely) identified by the given regexp. If the regexp matches more than one item, no result is returned. """ result = None candidates = Filter.GrepFilter(p_identifier).filter(self._todos) if len(candidates) == 1: result = candidates[0] else: raise InvalidTodoException return result
def test_filter19(self): todos = load_file('test/data/FilterTest1.txt') grep = Filter.GrepFilter(1) filtered_todos = grep.filter(todos) self.assertEquals(filtered_todos, [])