How to use the urlwatch.filters.FilterBase.__subclasses__ function in urlwatch

To help you get started, we’ve selected a few urlwatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thp / urlwatch / test / test_filters.py View on Github external
filter = filter_tests[test_name]['filter']
        data = filter_tests[test_name]['data']
        expected_result = filter_tests[test_name]['expected_result']
        if isinstance(filter, dict):
            key = next(iter(filter))
            kind, subfilter = key, filter[key]
        elif isinstance(filter, str):
            if ',' in filter:
                raise ValueError('Only single filter allowed in this test')
            elif ':' in filter:
                kind, subfilter = filter.split(':', 1)
            else:
                kind = filter
                subfilter = None
        logger.info('filter kind: %s, subfilter: %s', kind, subfilter)
        filtercls = FilterBase.__subclasses__.get(kind)
        if filtercls is None:
            raise ValueError('Unknown filter kind: %s:%s' % (filter_kind, subfilter))
        result = filtercls(None, None).filter(data, subfilter)
        logger.debug('Expected result:\n%s', expected_result)
        logger.debug('Actual result:\n%s', result)
        eq_(result, expected_result)