Skip to content

Commit

Permalink
3_test_refactored_code.py
Browse files Browse the repository at this point in the history
Signed-off-by: Fabiana Campanari <[email protected]>
  • Loading branch information
FabianaCampanari committed Mar 17, 2024
1 parent 4446ccc commit 8283f63
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Codes and Data Analysis Report/Code/3_test_refactored_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import unittest
import pandas as pd
import os
from refactored_code import classify_theses, process_file, process_files, save_classified_theses_to_excel

class TestRefactoredCode(unittest.TestCase):

def setUp(self):
self.ods = {
'ODS1': pd.DataFrame({'ODS1': ['palavra1', 'palavra2']}),
'ODS2': pd.DataFrame({'ODS2': ['palavra3', 'palavra4']})
}
self.teses = pd.DataFrame({'palavras_chave': ['palavra1 palavra2', 'palavra3 palavra4', 'palavra5 palavra6']})
self.file_paths = {
'file1': 'path/to/file1',
'file2': 'path/to/file2'
}
self.new_folder = 'path/to/new/folder'

def test_classify_theses(self):
result = classify_theses(self.ods, self.teses)
expected = {'ODS1': [0], 'ODS2': [1]}
self.assertEqual(result, expected)

def test_process_file(self):
# Use a real file path for testing
df = process_file('file1', 'path/to/file1', self.new_folder)
self.assertIsInstance(df, pd.DataFrame)

def test_process_files(self):
# Use real file paths for testing
dfs = process_files(self.file_paths, self.new_folder)
self.assertIsInstance(dfs, dict)
for df in dfs.values():
self.assertIsInstance(df, pd.DataFrame)

def test_save_classified_theses_to_excel(self):
classified_theses = classify_theses(self.ods, self.teses)
save_classified_theses_to_excel(classified_theses, 'classified_theses.xlsx', self.teses)
self.assertTrue(os.path.exists('classified_theses.xlsx'))

if __name__ == '__main__':
unittest.main()

0 comments on commit 8283f63

Please sign in to comment.