diff options
| author | Cody Logan <clpo13@gmail.com> | 2020-09-02 15:30:27 -0700 |
|---|---|---|
| committer | Cody Logan <clpo13@gmail.com> | 2020-09-02 15:30:38 -0700 |
| commit | 75dfc31a15f02ff375895e9b695924a8d909c87a (patch) | |
| tree | 156ff12c9a77c049ee4f044163950742ca0dd9b1 | |
| parent | 46744c22fc8c62c526a0d9eac8e7226f4f4ce879 (diff) | |
| download | wikiget-75dfc31a15f02ff375895e9b695924a8d909c87a.tar.gz wikiget-75dfc31a15f02ff375895e9b695924a8d909c87a.zip | |
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.
| -rw-r--r-- | test/test_validations.py | 20 |
1 files changed, 5 insertions, 15 deletions
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 <https://www.gnu.org/licenses/>. -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 |
