Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivieFranklova committed Dec 9, 2024
1 parent 6f8f0a4 commit 7f67d8b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
14 changes: 10 additions & 4 deletions tests/runner/test_runner_connectors.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import os
import unittest

from similarity_runner.src.impl.filesystem_connector import FilesystemConnector, FSConnectorSettings

THIS_DIR = os.path.dirname(os.path.abspath(__file__))

class TestFileSystemConnector(unittest.TestCase):
def setUp(self):
self.file1 = os.path.join(THIS_DIR, '../data/netflix_titles.csv')
self.file2 = os.path.join(THIS_DIR, '../data/disney_movies.csv')
self.dir = os.path.join(THIS_DIR, '../data')
def test_get_data_files(self):
connector = FilesystemConnector()
settings = FSConnectorSettings(files_paths="../data/netflix_titles.csv,../data/disney_movies.csv",
settings = FSConnectorSettings(files_paths=self.file1 + "," + self.file2,
directory_paths="",
filetypes="csv")
res = connector.get_data(settings)
connector.close()
self.assertEqual(len(res), 2)
self.assertEqual(res[0].source_name, "../data/netflix_titles")
self.assertEqual(res[1].source_name, "../data/disney_movies")
self.assertEqual(res[0].source_name, self.file1.replace(".csv", ""))
self.assertEqual(res[1].source_name, self.file2.replace(".csv", ""))

def test_get_data_folder(self):
connector = FilesystemConnector()
settings = FSConnectorSettings(files_paths="",
directory_paths="../data",
directory_paths=self.dir,
filetypes="csv")
data = connector.get_data(settings)
connector.close()
Expand Down
43 changes: 26 additions & 17 deletions tests/runner/test_runner_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import unittest

import pandas as pd

from similarity_runner.src.impl.filesystem_connector import load_files_from_list
from similarity_runner.src.models.connectors import FileType

THIS_DIR = os.path.dirname(os.path.abspath(__file__))

def csv_to_parquet(file: str, sep: str = ',') -> str:
"""
Expand All @@ -16,36 +18,43 @@ def csv_to_parquet(file: str, sep: str = ',') -> str:
return file.replace(".csv", ".parquet")

class TestLoadFilesFromList(unittest.TestCase):
def setUp(self):
self.netflix_file = os.path.join(THIS_DIR, '../data/netflix_titles.csv')
self.netflix_file_parquet = os.path.join(THIS_DIR, '../data/netflix_titles.parquet')
self.disney_file = os.path.join(THIS_DIR, '../data/disney_movies.csv')
self.disney_file_parquet = os.path.join(THIS_DIR, '../data/disney_movies.parquet')
self.dir = os.path.join(THIS_DIR, '../data')

def test_load_csv_file(self):
res = load_files_from_list(["../data/netflix_titles.csv"], (FileType.CSV, ))
res = load_files_from_list([self.netflix_file], (FileType.CSV,))
self.assertEqual(len(res), 1)
self.assertEqual(res[0].source_name, "../data/netflix_titles")
self.assertEqual(res[0].source_name, self.netflix_file.replace(".csv", ""))

def test_load_csv_files(self):
res = load_files_from_list(["../data/netflix_titles.csv", "../data/disney_movies.csv"], (FileType.CSV, ))
res = load_files_from_list([self.netflix_file, self.disney_file], (FileType.CSV,))
self.assertEqual(len(res), 2)
self.assertEqual(res[0].source_name, "../data/netflix_titles")
self.assertEqual(res[1].source_name, "../data/disney_movies")
self.assertEqual(res[0].source_name, self.netflix_file.replace(".csv", ""))
self.assertEqual(res[1].source_name, self.disney_file.replace(".csv", ""))


def test_load_parquet_file(self):
csv_to_parquet("../data/netflix_titles.csv")
res = load_files_from_list(["../data/netflix_titles.parquet"], (FileType.PARQUET, ))
csv_to_parquet(self.netflix_file)
res = load_files_from_list([self.netflix_file_parquet], (FileType.PARQUET, ))
self.assertEqual(len(res), 1)
self.assertEqual(res[0].source_name, "../data/netflix_titles")
self.assertEqual(res[0].source_name, self.netflix_file_parquet.replace(".parquet", ""))

def test_load_parquet_files(self):
csv_to_parquet("../data/netflix_titles.csv")
csv_to_parquet("../data/disney_movies.csv")
res = load_files_from_list(["../data/netflix_titles.parquet", "../data/disney_movies.parquet"], (FileType.PARQUET, ))
csv_to_parquet(self.netflix_file)
csv_to_parquet(self.disney_file)
res = load_files_from_list([self.netflix_file_parquet, self.disney_file_parquet], (FileType.PARQUET, ))
self.assertEqual(len(res), 2)
self.assertEqual(res[0].source_name, "../data/netflix_titles")
self.assertEqual(res[1].source_name, "../data/disney_movies")
self.assertEqual(res[0].source_name, self.netflix_file_parquet.replace(".parquet", ""))
self.assertEqual(res[1].source_name, self.disney_file_parquet.replace(".parquet", ""))


def test_load_csv_and_parquet_files(self):
csv_to_parquet("../data/netflix_titles.csv")
res = load_files_from_list(["../data/netflix_titles.parquet", "../data/disney_movies.csv"], (FileType.PARQUET, FileType.CSV))
csv_to_parquet(self.netflix_file)
res = load_files_from_list([self.netflix_file_parquet, self.disney_file], (FileType.PARQUET, FileType.CSV))
self.assertEqual(len(res), 2)
self.assertEqual(res[0].source_name, "../data/netflix_titles")
self.assertEqual(res[1].source_name, "../data/disney_movies")
self.assertEqual(res[0].source_name, self.netflix_file_parquet.replace(".parquet", ""))
self.assertEqual(res[1].source_name, self.disney_file.replace(".csv", ""))

0 comments on commit 7f67d8b

Please sign in to comment.