From 73f814dac9f036dedb7dcd12976e79106331384d Mon Sep 17 00:00:00 2001 From: Sebastian Simon Date: Fri, 13 Dec 2024 11:04:07 +0100 Subject: [PATCH] Skip config files in test directories --- src/cfgnet/network/network.py | 9 +++++++-- src/cfgnet/utility/util.py | 17 +++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cfgnet/network/network.py b/src/cfgnet/network/network.py index fb8bfcc..a52bc67 100644 --- a/src/cfgnet/network/network.py +++ b/src/cfgnet/network/network.py @@ -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: @@ -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( @@ -348,5 +353,5 @@ def init_network(cfg: NetworkConfiguration) -> Network: continue LinkerManager.apply_linkers(network) - + return network diff --git a/src/cfgnet/utility/util.py b/src/cfgnet/utility/util.py index b7058cb..5c1babc 100644 --- a/src/cfgnet/utility/util.py +++ b/src/cfgnet/utility/util.py @@ -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]: