def test_folder_nesting( working_dir, source_dir, source_paths, expected_paths, change_test_dir, ): """ Builds the output folder structure to match the input folder structure. """ # Arrange if working_dir is not None: change_test_dir(working_dir) if callable(source_dir): source_dir = source_dir() sources = [f"{source_dir}/{path}" for path in source_paths] output_dir = "output" expected = [f"{output_dir}/{source_dir}/{path}" for path in expected_paths] # Act files = resolve_file_sources(sources) build_docs(files, output_dir) # Assert for path in expected: assert Path(path).exists() assert not Path("output/.ignoreme").exists() assert not Path("output/.ignoremetoo").exists()
def test_copy_readme_file(change_test_dir): """ Copies all .md files from the source folder to the output. """ # Arrange sources = ["project"] output_dir = "output" # Act files = resolve_file_sources(sources) build_docs(files, output_dir) # Assert assert Path("output/project/module/Readme.md").exists() assert Path( "output/project/module/Readme.md").read_text() == "# This is a test\n"
def test_recurse_folder(source_paths, expected_paths): """ Resursively searches the children when given a folder. """ # Arrange output_dir = "output" expected = [f"{output_dir}/project/{path}" for path in expected_paths] # Act files = resolve_file_sources(source_paths) build_docs(files, output_dir) # Assert for path in expected: assert Path(path).exists() assert not Path("output/.ignoreme").exists() assert not Path("output/.ignoremetoo").exists()
def test_ignore_empty_files(): """ Does not include empty generated files in output. """ # Arrange output_dir = "output" source_paths = ["project"] expected_not_files = ["empty_file.md", "unsupported_type.md"] expected_not_paths = [ f"{output_dir}/project/{path}" for path in expected_not_files ] # Act files = resolve_file_sources(source_paths) build_docs(files, output_dir) # Assert for path in expected_not_paths: assert not Path(path).exists()
def test_resolve_ignored_files(source_paths, ignore_paths, expected_paths, expected_not_paths): """ Ignores files matching the ignore pattern. """ # Arrange output_dir = "output" expected = [f"project/{path}" for path in expected_paths] expected_not = [f"project/{path}" for path in expected_not_paths] # Act files = resolve_file_sources(source_paths, ignore_paths=ignore_paths) build_docs(files, output_dir) # Assert for path in expected: assert str(Path(path)) in files for path in expected_not: assert str(Path(path)) not in files
def test_ignore_flag(source_paths, ignore_paths, expected_paths, expected_not_paths): """ Does not include files matching the ignore pattern in generated output. """ # Arrange output_dir = "output" expected = [f"{output_dir}/project/{path}" for path in expected_paths] expected_not = [ f"{output_dir}/project/{path}" for path in expected_not_paths ] # Act files = resolve_file_sources(source_paths, ignore_paths=ignore_paths) build_docs(files, output_dir) # Assert for path in expected: assert Path(path).exists() for path in expected_not: assert not Path(path).exists()