def test_filter_ids_toggle_pattern_matching(task_pool, caplog): """Ensure pattern matching can be toggled on and off.""" pool = task_pool( { 1: ['1/a:x'], }, {} ) ids = ['*/*'] # ensure pattern matching works _matched, _not_matched = filter_ids( [pool], ids, out=IDTokens.Task, pattern_match=True, ) assert [itask.id_ for itask in _matched] == ['1/a:x'] assert _not_matched == [] # ensure pattern matching can be disabled caplog.clear() _matched, _not_matched = filter_ids( [pool], ids, out=IDTokens.Task, pattern_match=False, ) assert [itask.id_ for itask in _matched] == [] assert _not_matched == ['*/*'] # ensure the ID is logged assert len(caplog.record_tuples) == 1 assert '*/*' in caplog.record_tuples[0][2]
def test_filter_ids_invalid(caplog): """Ensure invalid IDs are handled elegantly.""" matched, not_matched = filter_ids([{}], ['#']) assert matched == [] assert not_matched == ['#'] assert caplog.record_tuples == [ ('cylc', 30, 'No active tasks matching: #'), ] caplog.clear() matched, not_matched = filter_ids([{}], ['#'], warn=False) assert caplog.record_tuples == []
def test_filter_ids_task_mode(task_pool, ids, matched, not_matched): """Ensure tasks are returned in task mode.""" pool = task_pool( { 1: ['1/a:x', '1/b:x', '1/c:x'] }, {} ) _matched, _not_matched = filter_ids([pool], ids) assert [itask.id_ for itask in _matched] == matched assert _not_matched == not_matched
def test_filter_ids_cycle_mode(task_pool, ids, matched, not_matched): """Ensure cycle poinds are returned in cycle mode.""" pool = task_pool( { 1: ['1/a:x', '1/b:x'], 2: ['1/a:x'], 3: [], }, {} ) _matched, _not_matched = filter_ids([pool], ids, out=IDTokens.Cycle) assert _matched == matched assert _not_matched == not_matched
def test_filter_ids_pattern_match_off(task_pool): """Ensure filtering works when pattern matching is turned off.""" pool = task_pool( { 1: ['1/a:x'], }, {} ) _matched, _not_matched = filter_ids( [pool], ['1/a'], out=IDTokens.Task, pattern_match=False, ) assert [itask.id_ for itask in _matched] == ['1/a:x'] assert _not_matched == []
def test_filter_ids_namespace_hierarchy(task_pool, ids, matched, not_matched): """Ensure matching includes namespaces.""" pool = task_pool( { 1: ['1/a:x', '1/b1:x', '1/b2:x'] }, { 'a': ['A'], 'b1': ['B'], 'b2': ['B'], }, ) _matched, _not_matched = filter_ids( [pool], ids, pattern_match=False, ) assert [itask.id_ for itask in _matched] == matched assert _not_matched == not_matched
def test_filter_ids_log_errors(caplog): _, _not_matched = filter_ids({}, ['/////']) assert _not_matched == ['/////'] assert caplog.record_tuples == [('cylc', 30, 'Invalid ID: /////')]
def test_filter_ids_out_format(): filter_ids({}, [], out=IDTokens.Cycle) with pytest.raises(ValueError): filter_ids({}, [], out=IDTokens.Job)