Skip to content

Commit

Permalink
Skip config files in test directories
Browse files Browse the repository at this point in the history
  • Loading branch information
simisimon committed Dec 13, 2024
1 parent 596d9ad commit 73f814d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/cfgnet/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)
from cfgnet.network.network_configuration import NetworkConfiguration
from cfgnet.exporter.exporter import DotExporter, JSONExporter
from cfgnet.utility.util import get_system_files
from cfgnet.utility.util import get_system_files, is_in_test_directory


class Network:
Expand Down Expand Up @@ -304,6 +304,11 @@ def init_network(cfg: NetworkConfiguration) -> Network:
file_type_plugins = PluginManager.get_file_type_plugins()

for file in sorted(tracked_files):

# skip config files in test directories
if is_in_test_directory(file):
continue

abs_file_path = os.path.join(cfg.project_root_abs, file)

concept_plugin = PluginManager.get_responsible_plugin(
Expand Down Expand Up @@ -348,5 +353,5 @@ def init_network(cfg: NetworkConfiguration) -> Network:
continue

LinkerManager.apply_linkers(network)

return network
17 changes: 11 additions & 6 deletions src/cfgnet/utility/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
from typing import Set, Optional


def is_test_file(abs_file_path) -> bool:
def is_in_test_directory(file_path):
"""
Check if a given file is a test file.
:return: True if test file else False
Checks if a given file is in a test directory.
"""
test_indicators = ["/tests", "test", "tests"]
return any(indicator in abs_file_path for indicator in test_indicators)
# Normalize and split the file path
normalized_path = os.path.normpath(file_path)
directories = normalized_path.split(os.sep)

# Check for 'test' in any directory name
for dir_name in directories:
if 'test' in dir_name.lower():
return True
return False


def get_system_config_dir() -> Optional[str]:
Expand Down

0 comments on commit 73f814d

Please sign in to comment.