From 59fb733468e02aa1d5cb51ee4192d77c2cbf4e1c Mon Sep 17 00:00:00 2001 From: Agata Date: Mon, 21 Dec 2020 23:10:17 +0100 Subject: [PATCH] added save_input unittest --- win_venv/main.py | 3 +-- win_venv/tests.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/win_venv/main.py b/win_venv/main.py index bd5895f..fce4d13 100644 --- a/win_venv/main.py +++ b/win_venv/main.py @@ -23,9 +23,8 @@ def save_input(oldpath): timestamp = str(int(time.time())) filename = timestamp + '.' + oldpath.split('.')[-1] newpath = filePath + '\\' + filename - print(oldpath) - print(newpath) shutil.copy(oldpath, newpath) + return newpath class LibraryTableButtons(QWidget): diff --git a/win_venv/tests.py b/win_venv/tests.py index 28c61d0..aa92acb 100644 --- a/win_venv/tests.py +++ b/win_venv/tests.py @@ -1 +1,26 @@ -#tests +import unittest +from main import * + +# 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) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file