Пример #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)