def assert_valid_hrefs(self, directory: str = "htmlcov") -> None:
        """Assert that the hrefs in htmlcov/*.html are valid.

        Doesn't check external links (those with a protocol).
        """
        hrefs = collections.defaultdict(set)
        for fname in glob.glob(f"{directory}/*.html"):
            with open(fname, encoding="utf-8") as fhtml:
                html = fhtml.read()
            for href in re.findall(r""" href=['"]([^'"]*)['"]""", html):
                if href.startswith("#"):
                    assert re.search(fr""" id=['"]{href[1:]}['"]""", html), (
                        f"Fragment {href!r} in {fname} has no anchor"
                    )
                    continue
                if "://" in href:
                    continue
                href = href.partition("#")[0]   # ignore fragment in URLs.
                hrefs[href].add(fname)
        for href, sources in hrefs.items():
            assert os.path.exists(f"{directory}/{href}"), (
                f"These files link to {href!r}, which doesn't exist: {', '.join(sources)}"
            )
Assert that the hrefs in htmlcov/*.html are valid.

        Doesn't check external links (those with a protocol).
        
tests/test_html.py