def test_default_task_is_open(): """ Check that by default there is no result for a task """ # Given task = ResearchTask() # When result = task.is_open() # Then assert result is True
def test_unknown_result_filter_matches_no_results(result, value): """ An unknown result filter will match no result types """ # Given task = ResearchTask() matcher = TaskMatcher() matcher.result_filter("foo") # When task.result = result assert matcher.match(task) is value
def test_string_repr_includes_description(): """ The str() representation should include the description """ # Given task = ResearchTask() task.description = "DESCRIPTION" # When string = str(task) # Then assert task.description in string
def test_unset_fields_are_defaulted(): """ Check that when converting a task, any fields not set in py are defaulted """ # Given task = ResearchTask() task_data = {} # When task.from_py(task_data) # Then assert task.source == "" assert task.description == ""
def test_text_filter_successful_match(): """ The text_filter should match tasks containing the text """ # Given task = ResearchTask() matcher = TaskMatcher() matcher.text_filter("foo") # When task.source = "A foo bar" match = matcher.match(task) # Then assert match is True
def test_text_filter_failed_match(): """ The text_filter should not match tasks not containing the text """ # Given task = ResearchTask() matcher = TaskMatcher() matcher.text_filter("foo") # When task.source = "A baz bar" match = matcher.match(task) # Then assert match is False
def test_filters_are_anded(source, result, value): """ Test that filters are 'and'ed together """ # Given task = ResearchTask() matcher = TaskMatcher() matcher.result_filter("open") matcher.text_filter("foo") # When task.source = source task.result = result # Then assert matcher.match(task) is value
def test_delete_task_does_nothing_if_index_out_of_bounds(): """ delete_task() does nothing if the index is too large """ # Given plan = ResearchPlan() task_one = ResearchTask() task_two = ResearchTask() task_three = ResearchTask() plan.tasks.append(task_one) plan.tasks.append(task_two) plan.tasks.append(task_three) # When plan.delete_task(5) # Then assert len(plan.tasks) == 3
def test_empty_result_filter_matches_all_results(): """ An empty result filter will match all possible result types """ # Given nil_result = ResearchResult(False) success_result = ResearchResult(True) task = ResearchTask() matcher = TaskMatcher() matcher.result_filter("") # When task.result = None assert matcher.match(task) is True task.result = nil_result assert matcher.match(task) is True task.result = success_result assert matcher.match(task) is True
def test_success_result_filter_matches_success_results(): """ A success result filter will match success result types """ # Given nil_result = ResearchResult(False) success_result = ResearchResult(True) task = ResearchTask() matcher = TaskMatcher() matcher.result_filter("success") # When task.result = None assert matcher.match(task) is False task.result = nil_result assert matcher.match(task) is False task.result = success_result assert matcher.match(task) is True
def test_delete_task_deletes_the_specified_task(): """ delete_task() does nothing if there are no tasks """ # Given plan = ResearchPlan() task_one = ResearchTask() task_two = ResearchTask() task_three = ResearchTask() plan.tasks.append(task_one) plan.tasks.append(task_two) plan.tasks.append(task_three) # When plan.delete_task(1) # Then assert len(plan.tasks) == 2 assert plan.tasks[0] == task_one assert plan.tasks[1] == task_three
def test_ancestor_filter_has_no_effect_if_no_plan_passed(): """ When no plan is passed to the match function, the ancestor filter should have no effect """ # Given task = ResearchTask() matcher = TaskMatcher() matcher.ancestor_filter("Henry") # When assert matcher.match(task, None) is True
def test_default_matches_all(): """ A new TaskMatcher should match all Tasks """ # Given task = ResearchTask() matcher = TaskMatcher() # When result = matcher.match(task) # Then assert result is True
def test_get_font_returns_strikeout_for_task_with_result(): """ A task with a nil result should show up as strike-out """ # Given model = TreeModel() project = ResearchProject("") plan = ResearchPlan() task = ResearchTask() task.result = ResearchResult(False) plan.tasks.append(task) project.plans.append(plan) model.set_project(project) plan_index = model.index(0, 0, model.plans_index) task_index = model.index(0, 0, plan_index) # When font = model.data(task_index, Qt.FontRole) # Then assert font.strikeOut() is True
def test_ancestor_matches_plan(ancestor, value): """ When the plan is passed and ancestor filter set, it should be applied """ # Given task = ResearchTask() plan = ResearchPlan() matcher = TaskMatcher() matcher.ancestor_filter("Henry") # When plan.ancestor = ancestor # Then assert matcher.match(task, plan) is value
def test_delete_removes_plan(): """ Delete removes plan from underlying data structure """ # Given model = TreeModel() project = ResearchProject("") plan = ResearchPlan() task = ResearchTask() plan.tasks.append(task) project.plans.append(plan) model.set_project(project) plan_index = model.index(0, 0, model.plans_index) # When model.delete_node(plan_index) # Then assert len(project.plans) == 0
def test_to_py_sets_fields(): """ The to_py() function should create a python data structure of the class fields """ # Given task = ResearchTask() task.source = "SOURCE" task.source_link = 123 task.description = "DESCRIPTION" # When data = task.to_py() # Then assert data["description"] == task.description assert data["source"] == task.source assert data["source_link"] == task.source_link assert data["result"] == task.result assert len(data.keys()) == 4 # To verify nothing else was added
def test_task_links_are_checked(): """ Check the following: * Unchanged links are respected * Broken links are identified * Updated links are identified """ # Given project = ResearchProject("") individuals = [] sources = [] plan = ResearchPlan() source_linked = Source("S123", "Linked", "Author", "Pub", "abbr") sources.append(source_linked) task_linked = ResearchTask() task_linked.source = source_linked.autocomplete_name() task_linked.source_link = source_linked.pointer plan.tasks.append(task_linked) task_broken = ResearchTask() task_broken.source = "Broken Source" task_broken.source_link = "FooBar" plan.tasks.append(task_broken) source_altered = Source("S987", "Altered", "Author", "Pub", "abbr") sources.append(source_altered) task_altered = ResearchTask() task_altered.source = "Altered Source" task_altered.source_link = source_altered.pointer plan.tasks.append(task_altered) project.plans.append(plan) tree_model = TreeModel() tree_model.set_project(project) individuals_model = IndividualsModel(individuals) sources_model = SourcesModel(sources) context = DataContext( data_model=tree_model, individuals_model=individuals_model, sources_model=sources_model, ) updater = LinkUpdater(context) # When updater.calculate_updates() # Then assert updater.has_pending_updates() is True assert len(updater.ancestor_updates) == 0 assert len(updater.source_updates) == 1