62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
import unittest
|
|
from main import *
|
|
from unittest.mock import Mock
|
|
from pathlib import Path
|
|
|
|
# test saving file
|
|
class savingFileTest(unittest.TestCase):
|
|
|
|
def test_text_file(self):
|
|
print('Testing save_input method \n')
|
|
old_file_content = 'testing\n\n\nmore testing'
|
|
with open('test.txt', 'w') as file:
|
|
file.write(old_file_content)
|
|
|
|
script_path = os.path.dirname(os.path.realpath(__file__))
|
|
test_file_path = script_path + '\\test.txt'
|
|
newpath = save_input(test_file_path)
|
|
|
|
new_file_content = ''
|
|
with open(newpath, 'r') as new_file:
|
|
for line in new_file:
|
|
new_file_content += line
|
|
|
|
self.assertEqual(old_file_content, new_file_content)
|
|
os.remove(newpath)
|
|
|
|
|
|
# test using mock checking if a file with analysis had been generated
|
|
class generetingOutputFile(unittest.TestCase):
|
|
|
|
def test_output_file(self):
|
|
|
|
print('Mock testing outputfile')
|
|
m = Mock()
|
|
m.output_file_path = scriptPath + '\\files\\output\\test.pdf'
|
|
|
|
assert Path(m.output_file_path).is_file()
|
|
|
|
|
|
# test deleting input file
|
|
class testDeleteFile(unittest.TestCase):
|
|
|
|
def test_delete_file(self):
|
|
|
|
print('Testing deleting the file')
|
|
new_file = inputFilePath + os.path.sep + 'new_file.txt'
|
|
with open(new_file, 'w') as file:
|
|
file.write('teeeest')
|
|
|
|
with open(new_file) as f:
|
|
content = f.read()
|
|
|
|
assert os.path.exists(new_file)
|
|
self.assertEqual(content, 'teeeest')
|
|
|
|
delete_file(new_file)
|
|
|
|
self.assertFalse(os.path.exists(new_file))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main() |