def run_ford(monkeypatch, md_file: pathlib.Path, extra_args: list = None): """Modify command line args with argv""" with monkeypatch.context() as m: command = ["ford", str(md_file)] if extra_args is not None: command = command[:1] + extra_args + command[1:] m.setattr(sys, "argv", command) ford.run()
def test_external_project(copy_project_files, monkeypatch, restore_macros): """Check that we can build external projects and get the links correct This is a rough-and-ready test that runs FORD via subprocess, and so won't work unless FORD has been installed. It also relies on access to the internet and an external URL out of our control. """ path = copy_project_files external_project = path / "external_project" top_level_project = path / "top_level_project" # Run FORD in the two projects # First project has "externalize: True" and will generate JSON dump with monkeypatch.context() as m: os.chdir(external_project) m.setattr(sys, "argv", ["ford", "doc.md"]) ford.run() def mock_open(*args, **kwargs): return MockResponse() # Second project uses JSON from first to link to external modules with monkeypatch.context() as m: os.chdir(top_level_project) m.setattr(sys, "argv", ["ford", "doc.md"]) m.setattr(ford.utils, "urlopen", mock_open) ford.run() # Make sure we're in a directory where relative paths won't # resolve correctly os.chdir("/") # Read generated HTML with open(top_level_project / "doc/program/top_level.html", "r") as f: top_program_html = BeautifulSoup(f.read(), features="html.parser") # Find links to external modules uses_box = top_program_html.find(string="Uses").parent.parent.parent links = {tag.text: tag.a["href"] for tag in uses_box("li", class_=None)} assert len(links) == 2 assert "external_module" in links local_url = urlparse(links["external_module"]) assert pathlib.Path(local_url.path).is_file() assert "remote_module" in links remote_url = urlparse(links["remote_module"]) assert remote_url.scheme == "https"
def example_project(tmp_path_factory): this_dir = pathlib.Path(__file__).parent tmp_path = tmp_path_factory.getbasetemp() / "example" shutil.copytree(this_dir / "../example", tmp_path) with pytest.MonkeyPatch.context() as m: os.chdir(tmp_path) m.setattr(sys, "argv", ["ford", "example-project-file.md"]) ford.run() with open(tmp_path / "example-project-file.md", "r") as f: project_file = f.read() settings, _, _ = ford.parse_arguments({}, project_file, tmp_path) doc_path = tmp_path / "doc" return doc_path, settings
#!/usr/bin/env python """Wrapper for FORD fortran documentation generator""" from ford import run if __name__ == '__main__' : run()
from ford import run run()