def test_goaltree_previous_selection_may_be_changed_in_top_view(): goals = Goals('Root') goals.add('Top 1') goals.add('Top 2') goals.hold_select() goals.select(2) e = Enumeration(goals) assert e.all(keys='name,switchable,select') == { 1: {'name': 'Root', 'switchable': False, 'select': 'prev'}, 2: {'name': 'Top 1', 'switchable': True, 'select': 'select'}, 3: {'name': 'Top 2', 'switchable': True, 'select': None}, } e.next_view() assert e.events[-1] == ('hold_select', 2) assert e.all(keys='name,switchable,select') == { 1: {'name': 'Top 1', 'switchable': True, 'select': 'select'}, 2: {'name': 'Top 2', 'switchable': True, 'select': None} } e.insert('Illegal goal') # New goal must not be inserted because previous selection is reset after the view switching e.next_view() assert e.all(keys='name,switchable,select') == { 1: {'name': 'Root', 'switchable': False, 'select': None}, 2: {'name': 'Top 1', 'switchable': True, 'select': 'select'}, 3: {'name': 'Top 2', 'switchable': True, 'select': None}, }
def test_any_goal_may_be_selected_through_enumeration(actions, ch, choice): g = build_from(actions, ch) e = Enumeration(g) e.next_view() e.next_view() rnd_goal = choice(list(e.all().keys())) for i in str(rnd_goal): e.select(int(i)) assert e.all(keys='select')[rnd_goal]['select'] == 'select'
def test_simple_top_enumeration_workflow(): e = Enumeration(Goals('root')) e.add('1') e.add('2') e.select(2) e.next_view() e.select(2) assert e.all() == { 1: {'name': '1'}, 2: {'name': '2'} }
def test_dot_export_top_view(): g = Enumeration(Goals('Root')) g.add('Middle') g.add('Top', 2) g.add('Closed') g.add('More closed', 3) # close 'More closed' g.select(5) g.toggle_close() # close 'Closed' g.select(4) g.toggle_close() g.next_view() assert dot_export(g) == '''digraph g {
def test_goaltree_selection_may_be_changed_in_top_view(): goals = Goals('Root') goals.add('Top 1') goals.add('Top 2') e = Enumeration(goals) assert e.all(keys='name,switchable,select') == { 1: {'name': 'Root', 'switchable': False, 'select': 'select'}, 2: {'name': 'Top 1', 'switchable': True, 'select': None}, 3: {'name': 'Top 2', 'switchable': True, 'select': None}, } e.next_view() assert e.events[-2] == ('select', 2) assert e.events[-1] == ('hold_select', 2) assert e.all(keys='name,switchable,select') == { 1: {'name': 'Top 1', 'switchable': True, 'select': 'select'}, 2: {'name': 'Top 2', 'switchable': True, 'select': None} }
def test_selection_cache_should_be_reset_after_view_switch(): g = Goals('Root') # 1 -> 2 -> 3 -> .. -> 10 -> 11 for i in range(10): g.add(str(i+2), i+1) g.add('Also top', 1) e = Enumeration(g) e.select(1) e.next_view() assert e.all('name,select') == { 1: {'name': '11', 'select': 'select'}, 2: {'name': 'Also top', 'select': None}, } e.select(2) assert e.all('name,select') == { 1: {'name': '11', 'select': 'prev'}, 2: {'name': 'Also top', 'select': 'select'}, }
def test_dot_export_full_view(): g = Enumeration(Goals('Root')) g.add('Middle') g.add('Top', 2) g.add('Closed') g.select(4) g.toggle_close() g.next_view() g.next_view() g.select(1) assert dot_export(g) == '''digraph g { node [shape=box]; 1 [label="1: Root", color=red, style=filled, fillcolor=gray]; 2 [label="2: Middle", color=red]; 3 [label="3: Top", color=red, style="bold,filled", fillcolor=lightgray]; 4 [label="4: Closed", color=green]; 2 -> 1 [color=black]; 4 -> 1 [color=gray]; 3 -> 2 [color=black]; }''' g.hold_select() g.select(3) assert dot_export(g) == '''digraph g {
def test_toggle_switch_view(): e = Enumeration(Goals('Root')) assert e.view == 'open' e.next_view() assert e.view == 'top' e.next_view() assert e.view == 'full' e.next_view() assert e.view == 'open'
def test_top_view_may_be_empty(): e = Enumeration(Goals('closed')) e.toggle_close() e.next_view() assert e.all() == {}