From 3885dee0177af63370db31aa56a092ceeae2912f Mon Sep 17 00:00:00 2001 From: VanillaHellen Date: Wed, 27 Jan 2021 14:07:25 +0100 Subject: [PATCH 1/2] added test for deleting file --- win_venv/files/output/test.pdf | 1 + win_venv/main.py | 5 ++++- win_venv/tests.py | 25 ++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 win_venv/files/output/test.pdf 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 -- 2.20.1 From 2bb6e3fda196bb62ed1af97b9d70bd9addaa5a4c Mon Sep 17 00:00:00 2001 From: VanillaHellen Date: Wed, 27 Jan 2021 14:08:25 +0100 Subject: [PATCH 2/2] fix --- win_venv/tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/win_venv/tests.py b/win_venv/tests.py index 1b68acc..7010f8e 100644 --- a/win_venv/tests.py +++ b/win_venv/tests.py @@ -58,6 +58,5 @@ class testDeleteFile(unittest.TestCase): self.assertFalse(os.path.exists(new_file)) - if __name__ == '__main__': unittest.main() \ No newline at end of file -- 2.20.1