Add test_large_download, and clean up some test code

This commit is contained in:
Micah Lee 2019-11-09 01:38:35 +08:00
parent 78d5f4ff50
commit 35880c0070
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
2 changed files with 17 additions and 2 deletions

View file

@ -124,7 +124,10 @@ def default_zw():
yield zw
zw.close()
tmp_dir = os.path.dirname(zw.zip_filename)
shutil.rmtree(tmp_dir)
try:
shutil.rmtree(tmp_dir, ignore_errors=True)
except:
pass
@pytest.fixture

View file

@ -40,10 +40,18 @@ class GuiBaseTest(unittest.TestCase):
with open(filename, "w") as file:
file.write(secrets.token_hex(10))
cls.tmpfiles.append(filename)
# A file called "test.txt"
cls.tmpfile_test = os.path.join(cls.tmpdir.name, "test.txt")
with open(cls.tmpfile_test, "w") as file:
file.write("onionshare")
# A large file
size = 1024 * 1024 * 155
cls.tmpfile_large = os.path.join(cls.tmpdir.name, "large_file")
with open(cls.tmpfile_large, "wb") as fout:
fout.write(os.urandom(size))
@classmethod
def tearDownClass(cls):
# Quit
@ -51,6 +59,10 @@ class GuiBaseTest(unittest.TestCase):
cls.gui.close()
cls.gui.cleanup()
try:
shutil.rmtree(cls.tmpdir.name, ignore_errors=True)
except:
pass
# Shared test methods
@ -354,7 +366,7 @@ class GuiBaseTest(unittest.TestCase):
def clear_all_history_items(self, tab, count):
if count == 0:
tab.get_mode().history.clear_button.click()
self.assertEquals(len(tab.get_mode().history.item_list.items.keys()), count)
self.assertEqual(len(tab.get_mode().history.item_list.items.keys()), count)
# Auto-stop timer tests
def set_timeout(self, tab, timeout):