diff --git a/strictdoc/core/project_config.py b/strictdoc/core/project_config.py index 80e6d3a91..e2df7a1d3 100644 --- a/strictdoc/core/project_config.py +++ b/strictdoc/core/project_config.py @@ -10,7 +10,7 @@ from dataclasses import dataclass, field from enum import Enum from pathlib import Path -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Dict, List, Optional, Tuple, Pattern import toml @@ -123,6 +123,7 @@ def __init__( exclude_source_paths: Optional[List[str]] = None, grammars: Optional[Dict[str, str]] = None, test_report_root_dict: Optional[Dict[str, str]] = None, + tree_map_test_path_pattern: Optional[str] = None, source_nodes: Optional[List[SourceNodesEntry]] = None, html2pdf_strict: bool = False, html2pdf_template: Optional[str] = None, @@ -293,6 +294,12 @@ def __init__( self.test_report_root_dict: Dict[str, str] = ( test_report_root_dict if test_report_root_dict is not None else {} ) + self.tree_map_test_path_pattern: Pattern[str] = re.compile( + tree_map_test_path_pattern + if tree_map_test_path_pattern is not None + else r"tests/" + ) + self.source_nodes: List[SourceNodesEntry] = ( source_nodes if source_nodes is not None else [] ) @@ -896,6 +903,7 @@ def _load_from_dictionary( include_source_paths: List[str] = [] exclude_source_paths: List[str] = [] test_report_root_dict: Dict[str, str] = {} + tree_map_test_path_pattern: Optional[str] = None source_nodes: List[SourceNodesEntry] = [] html2pdf_strict: bool = False html2pdf_template: Optional[str] = None @@ -1003,6 +1011,10 @@ def _load_from_dictionary( assert isinstance(test_report_root_entry_, dict) test_report_root_dict.update(test_report_root_entry_) + tree_map_test_path_pattern = project_content.get( + "tree_map_test_path_pattern", tree_map_test_path_pattern + ) + section_behavior = project_content.get( "section_behavior", section_behavior ) @@ -1051,6 +1063,7 @@ def _load_from_dictionary( include_source_paths=include_source_paths, exclude_source_paths=exclude_source_paths, test_report_root_dict=test_report_root_dict, + tree_map_test_path_pattern=tree_map_test_path_pattern, source_nodes=source_nodes, html2pdf_strict=html2pdf_strict, html2pdf_template=html2pdf_template, diff --git a/strictdoc/features/tree_map/generator.py b/strictdoc/features/tree_map/generator.py index 0991a24ae..2471026c0 100644 --- a/strictdoc/features/tree_map/generator.py +++ b/strictdoc/features/tree_map/generator.py @@ -180,7 +180,9 @@ def get_node_stats( node_ ) for source_file_tuple_ in source_files: - if "tests/" in source_file_tuple_[0]: + if project_config.tree_map_test_path_pattern.search( + source_file_tuple_[0] + ): node_stats.child_nodes_with_links_to_test_files = 1 else: node_stats.child_nodes_with_links_to_source_files = 1 @@ -547,11 +549,11 @@ def hover_(row_: Any) -> Any: parts.append( GraphSection( title="Requirements coverage with test", - description="""\ + description=f"""\ This graph shows which requirements are covered by at least one test. A requirement is also considered covered if it has child requirements that are themselves covered by tests. A source file is considered a test file if its path -contains "tests/". +matches "{project_config.tree_map_test_path_pattern.pattern}".