Esempio n. 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)
Esempio n. 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)
Esempio n. 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
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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'}
Esempio n. 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'}
Esempio n. 17
0
 def get_pipeline(self):
     return pipeline('counter',
                     'fib',
                     import_prefix='tests.test_component_types')
Esempio n. 18
0
 def get_pipeline(self):
     return pipeline(self.counter, self.fib)
Esempio n. 19
0
 def get_pipeline(self):
     return pipeline(counter, fib)
Esempio n. 20
0
 def get_pipeline(self):
     generator = iter(['{}', '[]', '{"a": 1}'])
     return pipeline(generator, make_step(io.StringIO),
                     make_step(json.load))
Esempio n. 21
0
 def get_pipeline(self):
     return pipeline(self.dummy_component_1, self.dummy_component_2)