diff --git a/win_venv/files/output/test.pdf b/win_venv/files/output/test.pdf new file mode 100644 index 0000000..08778d7 --- /dev/null +++ b/win_venv/files/output/test.pdf @@ -0,0 +1 @@ +{\rtf1} \ No newline at end of file diff --git a/win_venv/main.py b/win_venv/main.py index 7e4a1de..92e379c 100644 --- a/win_venv/main.py +++ b/win_venv/main.py @@ -22,6 +22,9 @@ def files(path): for file in files_list: yield os.path.join(subdir, file) +def delete_file(file): + os.remove(file) + def save_input(oldpath): # add timestamp to the filename, so it wouln't overwrite but the user still knows which file's which timestamp = str(int(time.time())) @@ -77,7 +80,7 @@ class LibraryTableButtons(QWidget): self.exPopup = deletePopup() ret = self.exPopup.exec() if ret == self.exPopup.Yes: - os.remove(file) + delete_file(file) table.fillTable(type, mainWindow) def analyzeFile(): diff --git a/win_venv/tests.py b/win_venv/tests.py index 937b23c..1b68acc 100644 --- a/win_venv/tests.py +++ b/win_venv/tests.py @@ -22,6 +22,7 @@ class savingFileTest(unittest.TestCase): 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 @@ -29,12 +30,34 @@ class generetingOutputFile(unittest.TestCase): def test_output_file(self): - print('Moock testing outputfile') + 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() \ No newline at end of file