def test_assert_include_exclude_raises(self): strings = iter(['foo', 'bar', 'biz', 'fuzzy', 'cow.json']) rgxs = ('^b', '..z', '\.json$') pipeline = banzai.pipeline( strings, banzai.io.regex_filter(include=rgxs, exclude=['cow'])) with pytest.raises(ValueError): result = tuple(pipeline)
def test_regex_filter_include(self): strings = iter(['foo', 'bar', 'biz', 'fuzzy', 'cow.json']) rgxs = ('^b', '..z', '\.json$') pipeline = banzai.pipeline(strings, banzai.io.regex_filter(include=rgxs)) expected = ('bar', 'biz', 'fuzzy', 'cow.json') result = tuple(pipeline) assert result == expected
def test_assert_include_exclude_type_raises(self): strings = iter(['foo', 'bar', 'biz', 'fuzzy', 'cow.json']) class Filterer(banzai.io.RegexFilterer): include = ('^b', '..z', '\.json$') exclude = ('cow',) pipeline = banzai.pipeline(strings, Filterer) with pytest.raises(ValueError): result = tuple(pipeline)
def test_regex_filter_include_type(self): strings = iter(['foo', 'bar', 'biz', 'fuzzy', 'cow.json']) class Filterer(banzai.io.RegexFilterer): include = ('^b', '..z', '\.json$') pipeline = banzai.pipeline(strings, Filterer) expected = ('bar', 'biz', 'fuzzy', 'cow.json') result = tuple(pipeline) assert result == expected
def test_file_find_match_abspath(self): rgxs = ('moomoo', 'spam') file_finder = banzai.io.find_files(self.tempdir, exclude=rgxs) pipeline = banzai.pipeline(file_finder) output = set(tuple(pipeline)) expected_names = ('bar', 'baz', 'cows/bessie', 'cows/bull', 'foo') join = os.path.join expected = {join(self.tempdir, name) for name in expected_names} assert output == expected
def test_assert_include_exclude_type_raises(self): strings = iter(['foo', 'bar', 'biz', 'fuzzy', 'cow.json']) class Filterer(banzai.io.RegexFilterer): include = ('^b', '..z', '\.json$') exclude = ('cow', ) pipeline = banzai.pipeline(strings, Filterer) with pytest.raises(ValueError): result = tuple(pipeline)
def test_regex_filter_include(self): strings = iter(['foo', 'bar', 'biz', 'fuzzy', 'cow.json']) rgxs = ('^b', '..z', '\.json$') pipeline = banzai.pipeline( strings, banzai.io.regex_filter(include=rgxs)) expected = ('bar', 'biz', 'fuzzy', 'cow.json') result = tuple(pipeline) assert result == expected
def test_file_find_match_relpath(self): rgxs = ('oo', 'm') file_finder = banzai.io.find_files(start_dir=self.tempdir, include=rgxs, match_abspath=False) pipeline = banzai.pipeline(file_finder) output = set(tuple(pipeline)) expected_names = ('spam', 'foo', 'cows/moomoo') join = os.path.join expected = {join(self.tempdir, name) for name in expected_names} assert output == expected
def test_passed_in_logger(self): '''Test that passed in logger is actually used. ''' strings = iter(['foo', 'bar', 'biz', 'fuzzy', 'cow.json']) rgxs = ('oo', 'z$', '^z') logger = logging.getLogger('testlogger') pipeline = banzai.pipeline( strings, banzai.io.regex_filter(exclude=rgxs), logger=logger) assert pipeline.logger is logger
def test_not_passed_in_logger(self): '''Control test, that default logger differs from random logger. ''' strings = iter(['foo', 'bar', 'biz', 'fuzzy', 'cow.json']) rgxs = ('oo', 'z$', '^z') logger = logging.getLogger('testlogger') pipeline = banzai.pipeline( strings, banzai.io.regex_filter(exclude=rgxs)) assert pipeline.logger is not logger
def test_file_find_match_relpath(self): rgxs = ('oo', 'm') file_finder = banzai.io.find_files( start_dir=self.tempdir, include=rgxs, match_abspath=False) pipeline = banzai.pipeline(file_finder) output = set(tuple(pipeline)) expected_names = ('spam', 'foo', 'cows/moomoo') join = os.path.join expected = {join(self.tempdir, name) for name in expected_names} assert output == expected
def test_adhoc_file_find(self): '''Verify that os.walk and regex_filter find them correctly. ''' def flatten(upstream): for stringlist in upstream: yield from iter(stringlist) rgxs = ('oo', 'm') pipeline = banzai.pipeline(os.walk(self.tempdir), operator.itemgetter(2), flatten, banzai.io.regex_filter(include=rgxs)) output = set(tuple(pipeline)) assert output == {'spam', 'foo', 'moomoo'}
def test_adhoc_file_find(self): '''Verify that os.walk and regex_filter find them correctly. ''' def flatten(upstream): for stringlist in upstream: yield from iter(stringlist) rgxs = ('oo', 'm') pipeline = banzai.pipeline( os.walk(self.tempdir), operator.itemgetter(2), flatten, banzai.io.regex_filter(include=rgxs)) output = set(tuple(pipeline)) assert output == {'spam', 'foo', 'moomoo'}
def get_pipeline(self): return pipeline('counter', 'fib', import_prefix='tests.test_component_types')
def get_pipeline(self): return pipeline(self.counter, self.fib)
def get_pipeline(self): return pipeline(counter, fib)
def get_pipeline(self): generator = iter(['{}', '[]', '{"a": 1}']) return pipeline(generator, make_step(io.StringIO), make_step(json.load))
def get_pipeline(self): return pipeline(self.dummy_component_1, self.dummy_component_2)