Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3_test_refactored_code.py #869

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Codes and Data Analysis Report/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()
Loading