def _test_resource(class_, name, check, **kwargs):
    """Common code for testing the HTML and CSS classes."""
    absolute_path = resource_path(name)
    absolute_filename = str(absolute_path)
    url = path2url(absolute_path)
    check(class_(absolute_path, **kwargs))
    check(class_(absolute_filename, **kwargs))
    check(class_(guess=absolute_path, **kwargs))
    check(class_(guess=absolute_filename, **kwargs))
    check(class_(filename=absolute_path, **kwargs))
    check(class_(filename=absolute_filename, **kwargs))
    check(class_(url, **kwargs))
    check(class_(guess=url, **kwargs))
    url = path2url(absolute_filename.encode())
    check(class_(url=url, **kwargs))
    with absolute_path.open('rb') as fd:
        check(class_(fd, **kwargs))
    with absolute_path.open('rb') as fd:
        check(class_(guess=fd, **kwargs))
    with absolute_path.open('rb') as fd:
        check(class_(file_obj=fd, **kwargs))
    content = absolute_path.read_bytes()
    with chdir(Path(__file__).parent):
        relative_path = Path('resources') / name
        relative_filename = str(relative_path)
        check(class_(relative_path, **kwargs))
        check(class_(relative_filename, **kwargs))
        kwargs.pop('base_url', None)
        check(class_(string=content, base_url=relative_filename, **kwargs))
        encoding = kwargs.pop('encoding', 'utf-8')
        with absolute_path.open('r', encoding=encoding) as fd:
            check(class_(file_obj=fd, **kwargs))
        check(class_(
            string=content.decode(encoding), base_url=relative_filename,
            **kwargs))
    with pytest.raises(TypeError):
        class_(filename='foo', url='bar')
Common code for testing the HTML and CSS classes.
tests/test_api.py