Skip to content

Commit 40df5be

Browse files
committed
temporary fix for path problem when testing
1 parent b6e1dce commit 40df5be

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

spam_detector_ai/tests/test.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# spam_detector_ai/test_and_tuning/test.py
2-
31
import os
42
import sys
3+
from pathlib import Path
4+
5+
project_root = Path(__file__).parent.parent.parent
6+
sys.path.append(str(project_root))
57

68
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
79
from sklearn.model_selection import train_test_split
@@ -11,18 +13,12 @@
1113
from spam_detector_ai.prediction.predict import SpamDetector
1214
from spam_detector_ai.training.train_models import ModelTrainer
1315

14-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
15-
1616

1717
class TestModel:
1818
def __init__(self):
1919
self.classifier_types = [ClassifierType.NAIVE_BAYES, ClassifierType.RANDOM_FOREST, ClassifierType.SVM]
2020
self.logger = init_logging()
21-
# Determine the directory of this file
22-
current_dir = os.path.dirname(os.path.abspath(__file__))
23-
# Assuming the spam_detector_ai directory is one level up from the current directory
24-
base_dir = os.path.dirname(current_dir)
25-
data_path = os.path.join(base_dir, 'data/spam.csv')
21+
data_path = os.path.join(project_root, 'spam_detector_ai', 'data', 'spam.csv')
2622
self.initial_trainer = ModelTrainer(data_path=data_path, logger=self.logger)
2723
self.processed_data = self.initial_trainer.preprocess_data_()
2824

0 commit comments

Comments
 (0)