def test_verify_email_addresses(test_input, expected): # Arrange peps = [parser.PEP(Path(f"pep_sphinx_extensions/tests/peps/{test_input}"))] # Act out = writer._verify_email_addresses(peps) # Assert assert out == expected
def test_parse_authors(test_input, expected): # Arrange dummy_object = parser.PEP(Path("pep-0160.txt")) # Act out = parser._parse_authors(dummy_object, test_input, AUTHORS_OVERRIDES) # Assert assert out == expected
def test_pep_details(monkeypatch): pep8 = parser.PEP(Path("pep-0008.txt")) assert pep8.details == { "authors": "GvR, Warsaw, Coghlan", "number": 8, "status": " ", "title": "Style Guide for Python Code", "type": "P", }
def create_pep_zero(app: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None: peps = _parse_peps() pep0_text = writer.PEPZeroWriter().write_pep0(peps) pep0_path = subindices.update_sphinx("pep-0000", pep0_text, docnames, env) peps.append(parser.PEP(pep0_path)) subindices.generate_subindices(SUBINDICES_BY_TOPIC, peps, docnames, env) # Create peps.json json_path = Path(app.outdir, "api", "peps.json").resolve() json_path.parent.mkdir(exist_ok=True) json_path.write_text(create_pep_json(peps), encoding="utf-8")
def _parse_peps() -> list[parser.PEP]: # Read from root directory path = Path(".") peps: list[parser.PEP] = [] for file_path in path.iterdir(): if not file_path.is_file(): continue # Skip directories etc. if file_path.match("pep-0000*"): continue # Skip pre-existing PEP 0 files if file_path.match("pep-????.???") and file_path.suffix in { ".txt", ".rst" }: pep = parser.PEP(path.joinpath(file_path).absolute()) peps.append(pep) return sorted(peps)
def create_pep_zero(_: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None: # Sphinx app object is unneeded by this function # Read from root directory path = Path(".") pep_zero_filename = "pep-0000" peps: list[parser.PEP] = [] pep_pat = re.compile( r"pep-\d{4}") # Path.match() doesn't support regular expressions # AUTHOR_OVERRIDES.csv is an exception file for PEP0 name parsing with open("AUTHOR_OVERRIDES.csv", "r", encoding="utf-8") as f: authors_overrides = {} for line in csv.DictReader(f): full_name = line.pop("Overridden Name") authors_overrides[full_name] = line for file_path in path.iterdir(): if not file_path.is_file(): continue # Skip directories etc. if file_path.match("pep-0000*"): continue # Skip pre-existing PEP 0 files if pep_pat.match( str(file_path)) and file_path.suffix in {".txt", ".rst"}: pep = parser.PEP( path.joinpath(file_path).absolute(), authors_overrides) peps.append(pep) pep0_text = writer.PEPZeroWriter().write_pep0(sorted(peps)) Path(f"{pep_zero_filename}.rst").write_text(pep0_text, encoding="utf-8") # Add to files for builder docnames.insert(1, pep_zero_filename) # Add to files for writer env.found_docs.add(pep_zero_filename)
def test_parse_authors_invalid(): pep = parser.PEP(Path("pep-0008.txt")) with pytest.raises(PEPError, match="no authors found"): parser._parse_authors(pep, "", AUTHORS_OVERRIDES)
def test_pep_equal(): pep_a = parser.PEP(Path("pep-0008.txt")) pep_b = parser.PEP(Path("pep-0008.txt")) assert pep_a == pep_b
def test_pep_less_than(): pep8 = parser.PEP(Path("pep-0008.txt")) pep3333 = parser.PEP(Path("pep-3333.txt")) assert pep8 < pep3333
def test_pep_repr(): pep8 = parser.PEP(Path("pep-0008.txt")) assert repr(pep8) == "<PEP 0008 - Style Guide for Python Code>"
def test_create_pep_json(): peps = [parser.PEP(Path("pep-0008.txt"))] out = pep_index_generator.create_pep_json(peps) assert '"url": "https://peps.python.org/pep-0008/"' in out