def test_providing_subfilter_to_filter_without_subfilter_raises_valueerror(): with pytest.raises(ValueError): list( FilterBase.normalize_filter_list([{ 'beautify': { 'asubfilterthatdoesnotexist': True } }]))
def test_providing_unknown_subfilter_raises_valueerror(): with pytest.raises(ValueError): list( FilterBase.normalize_filter_list([{ 'grep': { 're': 'Price: .*', 'anothersubfilter': '42' } }]))
def test_filters(test_name, test_data): filter = test_data['filter'] data = test_data['data'] expected_result = test_data['expected_result'] result = data for filter_kind, subfilter in FilterBase.normalize_filter_list(filter): logger.info('filter kind: %s, subfilter: %s', filter_kind, subfilter) filtercls = FilterBase.__subclasses__.get(filter_kind) if filtercls is None: raise ValueError('Unknown filter kind: %s:%s' % (filter_kind, subfilter)) result = filtercls(None, None).filter(result, subfilter) logger.debug('Expected result:\n%s', expected_result) logger.debug('Actual result:\n%s', result) assert result == expected_result
def test_job(url): job = jobs[url] d = testdata[url] if 'filename' in d: input_data = open(os.path.join(root, 'test/data', d['filename']), 'rb').read() else: input_data = d['input'] for filter_kind, subfilter in FilterBase.normalize_filter_list(job['filter']): filtercls = FilterBase.__subclasses__[filter_kind] input_data = filtercls(None, None).filter(input_data, subfilter) # TODO: FilterBase.process(cls, filter_kind, subfilter, state, data): output_data = d['output'] eq_(input_data, output_data)
def test_url(url, job): testdata = yaml.safe_load( open(os.path.join(here, 'data/filter_documentation_testdata.yaml')).read()) d = testdata[url] if 'filename' in d: input_data = open(os.path.join(here, 'data', d['filename']), 'rb').read() else: input_data = d['input'] for filter_kind, subfilter in FilterBase.normalize_filter_list( job['filter']): filtercls = FilterBase.__subclasses__[filter_kind] input_data = filtercls(None, None).filter(input_data, subfilter) # TODO: FilterBase.process(cls, filter_kind, subfilter, state, data): output_data = d['output'] assert input_data == output_data
def test_invalid_filter_name_raises_valueerror(): with pytest.raises(ValueError): list(FilterBase.normalize_filter_list(['afilternamethatdoesnotexist']))
def test_normalize_filter_list(input, output): assert list(FilterBase.normalize_filter_list(input)) == output
def check_expected(input, output): eq_(list(FilterBase.normalize_filter_list(input)), output)