Merge pull request 'tests' (#13) from tests into master

Reviewed-on: #13
This commit is contained in:
Helena Gałązka 2021-01-27 14:09:10 +01:00
commit cc1d42e4cd
3 changed files with 28 additions and 2 deletions

View File

@ -0,0 +1 @@
{\rtf1}

View File

@ -22,6 +22,9 @@ def files(path):
for file in files_list: for file in files_list:
yield os.path.join(subdir, file) yield os.path.join(subdir, file)
def delete_file(file):
os.remove(file)
def save_input(oldpath): def save_input(oldpath):
# add timestamp to the filename, so it wouln't overwrite but the user still knows which file's which # add timestamp to the filename, so it wouln't overwrite but the user still knows which file's which
timestamp = str(int(time.time())) timestamp = str(int(time.time()))
@ -77,7 +80,7 @@ class LibraryTableButtons(QWidget):
self.exPopup = deletePopup() self.exPopup = deletePopup()
ret = self.exPopup.exec() ret = self.exPopup.exec()
if ret == self.exPopup.Yes: if ret == self.exPopup.Yes:
os.remove(file) delete_file(file)
table.fillTable(type, mainWindow) table.fillTable(type, mainWindow)
def analyzeFile(): def analyzeFile():

View File

@ -22,6 +22,7 @@ class savingFileTest(unittest.TestCase):
new_file_content += line new_file_content += line
self.assertEqual(old_file_content, new_file_content) self.assertEqual(old_file_content, new_file_content)
os.remove(newpath)
# test using mock checking if a file with analysis had been generated # test using mock checking if a file with analysis had been generated
@ -29,12 +30,33 @@ class generetingOutputFile(unittest.TestCase):
def test_output_file(self): def test_output_file(self):
print('Moock testing outputfile') print('Mock testing outputfile')
m = Mock() m = Mock()
m.output_file_path = scriptPath + '\\files\\output\\test.pdf' m.output_file_path = scriptPath + '\\files\\output\\test.pdf'
assert Path(m.output_file_path).is_file() 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__': if __name__ == '__main__':
unittest.main() unittest.main()