예제 #1
0
def test_as_html_custom_nav(temporary_dir, project_dir, chdir):
    with chdir(temporary_dir):
        temp_project_dir = os.path.join(temporary_dir, "portray")
        shutil.copytree(project_dir, temp_project_dir)
        with chdir(temp_project_dir):
            with open(os.path.join(temp_project_dir, "pyproject.toml"), "w+") as pyproject:
                pyproject.write(CUSTOM_NAV)

            api.as_html()
예제 #2
0
def test_as_html(temporary_dir, project_dir, chdir):
    with chdir(temporary_dir):
        # Directory with no project
        with pytest.raises(exceptions.NoProjectFound):
            api.as_html()

        # Rendering should succeed as soon as a project is within the directory
        temp_project_dir = os.path.join(temporary_dir, "portray")
        shutil.copytree(project_dir, temp_project_dir)
        with chdir(temp_project_dir):
            api.as_html()

            # Rendering a second time should fail
            with pytest.raises(exceptions.DocumentationAlreadyExists):
                api.as_html()

            # Unless we enable overwritting destination
            api.as_html(overwrite=True)

            # Or, we output to a different location
            with tempfile.TemporaryDirectory() as new_temp_directory:
                api.as_html(output_dir=os.path.join(new_temp_directory, "site"))
예제 #3
0
def test_module_no_path(temporary_dir, chdir):
    """Test handling of python modules specified in root project directory but not in path"""
    with chdir(temporary_dir):
        with open(os.path.join(temporary_dir, "my_module.py"), "w") as pathless_module:
            pathless_module.write("def my_method():\n    pass\n")

        # Rendering with no module identification should fail
        with pytest.raises(Exception):
            api.as_html()

        # With module specification, even without path should succeed
        api.as_html(modules=["my_module"])

        # Unless path auto inclusion is turned off
        with open(os.path.join(temporary_dir, "pyproject.toml"), "w") as pyproject:
            pyproject.write("[tool.portray]\nappend_directory_to_python_path = false")
        with pytest.raises(Exception):
            api.as_html()