From 75dfc31a15f02ff375895e9b695924a8d909c87a Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Wed, 2 Sep 2020 15:30:27 -0700 Subject: Use pytest's tmp_path fixture for verify_hash test This removes the need to check if the test directory is writable since pytest will handle that. --- test/test_validations.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/test_validations.py b/test/test_validations.py index c84370f..8322c7e 100644 --- a/test/test_validations.py +++ b/test/test_validations.py @@ -16,10 +16,6 @@ # You should have received a copy of the GNU General Public License # along with Wikiget. If not, see . -import os - -import pytest - from wikiget.validations import valid_file, valid_site, verify_hash @@ -81,23 +77,17 @@ def test_valid_file_input(): assert file_match is not None -def test_verify_hash(): +def test_verify_hash(tmp_path): """ Confirm that verify_hash returns the proper SHA1 hash. """ - # TODO: do we need to actually create a file? file_name = 'testfile' file_contents = 'foobar' file_sha1 = '8843d7f92416211de9ebb963ff4ce28125932878' - try: - dl = open(file_name, 'w') - except PermissionError: - pytest.skip('need write access to create test file') - else: - with dl: - dl.write(file_contents) + tmp_file = tmp_path / file_name - assert verify_hash(file_name) == file_sha1 + with tmp_file.open('w') as f: + f.write(file_contents) - os.remove(file_name) + assert verify_hash(tmp_file) == file_sha1 -- cgit v1.2.3