예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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
예제 #4
0
    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)
예제 #5
0
    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
예제 #6
0
    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
예제 #7
0
    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)
예제 #8
0
    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
예제 #9
0
    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
예제 #10
0
    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
예제 #11
0
    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
예제 #12
0
    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
예제 #13
0
    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
예제 #14
0
    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
예제 #15
0
    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'}
예제 #16
0
    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'}
예제 #17
0
 def get_pipeline(self):
     return pipeline('counter',
                     'fib',
                     import_prefix='tests.test_component_types')
예제 #18
0
 def get_pipeline(self):
     return pipeline(self.counter, self.fib)
예제 #19
0
 def get_pipeline(self):
     return pipeline(counter, fib)
예제 #20
0
 def get_pipeline(self):
     generator = iter(['{}', '[]', '{"a": 1}'])
     return pipeline(generator, make_step(io.StringIO),
                     make_step(json.load))
예제 #21
0
 def get_pipeline(self):
     return pipeline(self.dummy_component_1, self.dummy_component_2)