Add some checks to catch test failure

Really just checking that the setup is able to create test files so it
is known they were there then removed.
Windows tests really need verification of
recycle, which is not present.
This commit is contained in:
Andrew Senetar 2021-03-17 20:52:16 -05:00
parent f9fcdb8d8c
commit 356509120b
Signed by: arsenetar
GPG Key ID: C63300DCE48AB2F1
3 changed files with 15 additions and 2 deletions

View File

@ -32,6 +32,7 @@ def testfile():
dir=op.expanduser("~"), prefix="send2trash_test", delete=False dir=op.expanduser("~"), prefix="send2trash_test", delete=False
) )
file.close() file.close()
assert op.exists(file) is True
yield file yield file
# Cleanup trash files on supported platforms # Cleanup trash files on supported platforms
if sys.platform != "win32": if sys.platform != "win32":
@ -57,6 +58,7 @@ def testfiles():
) )
) )
[file.close() for file in files] [file.close() for file in files]
assert all([op.exists(file) for file in files]) is True
yield files yield files
filenames = [op.basename(file.name) for file in files] filenames = [op.basename(file.name) for file in files]
[os.remove(op.join(HOMETRASH, "files", filename)) for filename in filenames] [os.remove(op.join(HOMETRASH, "files", filename)) for filename in filenames]
@ -93,6 +95,7 @@ def testUnicodefile():
name = u"send2trash_tést1" name = u"send2trash_tést1"
file = op.join(op.expanduser(b"~"), name.encode("utf-8")) file = op.join(op.expanduser(b"~"), name.encode("utf-8"))
touch(file) touch(file)
assert op.exists(file) is True
yield file yield file
# Cleanup trash files on supported platforms # Cleanup trash files on supported platforms
if sys.platform != "win32": if sys.platform != "win32":
@ -158,6 +161,7 @@ def testExtVol():
fileName = "test.txt" fileName = "test.txt"
filePath = op.join(volume.trashTopdir, fileName) filePath = op.join(volume.trashTopdir, fileName)
touch(filePath) touch(filePath)
assert op.exists(filePath) is True
yield volume, fileName, filePath yield volume, fileName, filePath
volume.cleanup() volume.cleanup()

View File

@ -26,6 +26,7 @@ def _create_tree(path):
@pytest.fixture @pytest.fixture
def testdir(tmp_path): def testdir(tmp_path):
dirname = "\\\\?\\" + str(tmp_path) dirname = "\\\\?\\" + str(tmp_path)
assert op.exists(dirname) is True
yield dirname yield dirname
shutil.rmtree(dirname, ignore_errors=True) shutil.rmtree(dirname, ignore_errors=True)
@ -34,6 +35,7 @@ def testdir(tmp_path):
def testfile(testdir): def testfile(testdir):
file = op.join(testdir, "testfile.txt") file = op.join(testdir, "testfile.txt")
_create_tree(file) _create_tree(file)
assert op.exists(file) is True
yield file yield file
# Note dir will cleanup the file # Note dir will cleanup the file
@ -42,6 +44,7 @@ def testfile(testdir):
def testfiles(testdir): def testfiles(testdir):
files = [op.join(testdir, "testfile{}.txt".format(index)) for index in range(10)] files = [op.join(testdir, "testfile{}.txt".format(index)) for index in range(10)]
[_create_tree(file) for file in files] [_create_tree(file) for file in files]
assert all([op.exists(file) for file in files]) is True
yield files yield files
# Note dir will cleanup the files # Note dir will cleanup the files
@ -148,6 +151,7 @@ def longfile(longdir):
path = op.join(longdir, name + "{}.txt") path = op.join(longdir, name + "{}.txt")
file = path.format("") file = path.format("")
_create_tree(file) _create_tree(file)
assert op.exists(file) is True
yield file yield file
@ -157,11 +161,14 @@ def longfiles(longdir):
path = op.join(longdir, name + "{}.txt") path = op.join(longdir, name + "{}.txt")
files = [path.format(index) for index in range(10)] files = [path.format(index) for index in range(10)]
[_create_tree(file) for file in files] [_create_tree(file) for file in files]
assert all([op.exists(file) for file in files]) is True
yield files yield files
# NOTE: both legacy and modern test "pass" on windows, but actually are not moving files to the # NOTE: both legacy and modern test "pass" on windows, however sometimes with the same path
# recycle bin, this was tested on latest windows 10, thought to have worked previously # they do not actually recycle files but delete them. Noticed this when testing with the
# recycle bin open, noticed later tests actually worked, modern version can actually detect
# when this happens but not stop it at this moment, and we need a way to verify it when testing.
def test_trash_long_file_modern(longfile): def test_trash_long_file_modern(longfile):
_trash_file(longfile, s2t_modern) _trash_file(longfile, s2t_modern)

View File

@ -18,6 +18,8 @@ def file():
dir=op.expanduser("~"), prefix="send2trash_test", delete=False dir=op.expanduser("~"), prefix="send2trash_test", delete=False
) )
file.close() file.close()
# Verify file was actually created
assert op.exists(file.name) is True
yield file.name yield file.name
# Cleanup trash files on supported platforms # Cleanup trash files on supported platforms
if sys.platform != "win32": if sys.platform != "win32":