test_plugin: Parametrize HookRegistry.group_by_directive tests.
This commit is contained in:
		
							parent
							
								
									d4d9bd6554
								
							
						
					
					
						commit
						484c47a680
					
				
					 1 changed files with 14 additions and 30 deletions
				
			
		| 
						 | 
					@ -63,9 +63,6 @@ def easy_entries():
 | 
				
			||||||
        ]),
 | 
					        ]),
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def hook_types(hooks, key):
 | 
					 | 
				
			||||||
    return {type(hook) for hook in hooks[key]}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def map_errors(errors):
 | 
					def map_errors(errors):
 | 
				
			||||||
    retval = {}
 | 
					    retval = {}
 | 
				
			||||||
    for errkey in errors:
 | 
					    for errkey in errors:
 | 
				
			||||||
| 
						 | 
					@ -73,33 +70,20 @@ def map_errors(errors):
 | 
				
			||||||
        retval.setdefault(key, set()).add(errid)
 | 
					        retval.setdefault(key, set()).add(errid)
 | 
				
			||||||
    return retval
 | 
					    return retval
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_registry_all_by_default():
 | 
					@pytest.mark.parametrize('group_str,expected', [
 | 
				
			||||||
    hook_groups = HOOK_REGISTRY.group_by_directive()
 | 
					    (None, [TransactionError, PostingError]),
 | 
				
			||||||
    hooks = hook_types(hook_groups, 'Transaction')
 | 
					    ('', [TransactionError, PostingError]),
 | 
				
			||||||
    assert len(hooks) >= 2
 | 
					    ('all', [TransactionError, PostingError]),
 | 
				
			||||||
    assert TransactionError in hooks
 | 
					    ('Transaction', [TransactionError, PostingError]),
 | 
				
			||||||
    assert PostingError in hooks
 | 
					    ('-posting', [TransactionError]),
 | 
				
			||||||
 | 
					    ('-configured posting', [PostingError]),
 | 
				
			||||||
def test_registry_one_exclude():
 | 
					    ('configured -posting', [TransactionError]),
 | 
				
			||||||
    hook_groups = HOOK_REGISTRY.group_by_directive('-posting')
 | 
					])
 | 
				
			||||||
    hooks = hook_types(hook_groups, 'Transaction')
 | 
					def test_registry_group_by_directive(group_str, expected):
 | 
				
			||||||
    assert len(hooks) >= 1
 | 
					    args = () if group_str is None else (group_str,)
 | 
				
			||||||
    assert TransactionError in hooks
 | 
					    hook_groups = HOOK_REGISTRY.group_by_directive(*args)
 | 
				
			||||||
    assert PostingError not in hooks
 | 
					    actual = {type(hook) for hook in hook_groups['Transaction']}
 | 
				
			||||||
 | 
					    assert actual.issuperset(expected)
 | 
				
			||||||
def test_registry_exclude_then_include():
 | 
					 | 
				
			||||||
    hook_groups = HOOK_REGISTRY.group_by_directive('-configured posting')
 | 
					 | 
				
			||||||
    hooks = hook_types(hook_groups, 'Transaction')
 | 
					 | 
				
			||||||
    assert len(hooks) >= 1
 | 
					 | 
				
			||||||
    assert TransactionError not in hooks
 | 
					 | 
				
			||||||
    assert PostingError in hooks
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def test_registry_include_then_exclude():
 | 
					 | 
				
			||||||
    hook_groups = HOOK_REGISTRY.group_by_directive('configured -posting')
 | 
					 | 
				
			||||||
    hooks = hook_types(hook_groups, 'Transaction')
 | 
					 | 
				
			||||||
    assert len(hooks) >= 1
 | 
					 | 
				
			||||||
    assert TransactionError in hooks
 | 
					 | 
				
			||||||
    assert PostingError not in hooks
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_registry_unknown_group_name():
 | 
					def test_registry_unknown_group_name():
 | 
				
			||||||
    with pytest.raises(ValueError):
 | 
					    with pytest.raises(ValueError):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue