From 40df5be6d7ad5472a069962295fc52abec134992 Mon Sep 17 00:00:00 2001 From: Adams Pierre David <57180807+adamspd@users.noreply.github.com> Date: Sun, 1 Sep 2024 20:12:03 +0200 Subject: [PATCH] temporary fix for path problem when testing --- spam_detector_ai/tests/test.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/spam_detector_ai/tests/test.py b/spam_detector_ai/tests/test.py index 43e4ed3..a5362dd 100644 --- a/spam_detector_ai/tests/test.py +++ b/spam_detector_ai/tests/test.py @@ -1,7 +1,9 @@ -# spam_detector_ai/test_and_tuning/test.py - import os import sys +from pathlib import Path + +project_root = Path(__file__).parent.parent.parent +sys.path.append(str(project_root)) from sklearn.metrics import accuracy_score, classification_report, confusion_matrix from sklearn.model_selection import train_test_split @@ -11,18 +13,12 @@ from spam_detector_ai.prediction.predict import SpamDetector from spam_detector_ai.training.train_models import ModelTrainer -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - class TestModel: def __init__(self): self.classifier_types = [ClassifierType.NAIVE_BAYES, ClassifierType.RANDOM_FOREST, ClassifierType.SVM] self.logger = init_logging() - # Determine the directory of this file - current_dir = os.path.dirname(os.path.abspath(__file__)) - # Assuming the spam_detector_ai directory is one level up from the current directory - base_dir = os.path.dirname(current_dir) - data_path = os.path.join(base_dir, 'data/spam.csv') + data_path = os.path.join(project_root, 'spam_detector_ai', 'data', 'spam.csv') self.initial_trainer = ModelTrainer(data_path=data_path, logger=self.logger) self.processed_data = self.initial_trainer.preprocess_data_()