Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_project_properties(project_dir):
auto_test(config.project, _auto_allow_exceptions=(exceptions.NoProjectFound,))
auto_test(
config.project, directory=project_dir, _auto_allow_exceptions=(exceptions.NoProjectFound,)
)
def test_project_properties(project_dir):
auto_test(config.project, _auto_allow_exceptions=(exceptions.NoProjectFound,))
auto_test(
config.project, directory=project_dir, _auto_allow_exceptions=(exceptions.NoProjectFound,)
)
def test_project_setup_py(temporary_dir):
with open(os.path.join(temporary_dir, "setup.py"), "w") as setup_file:
setup_file.write(FAKE_SETUP_FILE)
project_config = config.project(directory=temporary_dir, config_file="")
assert project_config["modules"] == ["fake"]
def test_project_flit_setup(temporary_dir):
with open(os.path.join(temporary_dir, "pyproject.toml"), "w") as setup_file:
setup_file.write(FAKE_PYPROJECT_TOML_FLIT)
project_config = config.project(directory=temporary_dir, config_file="pyproject.toml")
assert project_config["modules"] == ["preconvert"]
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:
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()
# 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"))
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()
# 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"))
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()