From 605085c95fe5ab6af337aefc723794f78cf3dfd7 Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Tue, 14 Nov 2023 16:44:34 -0800 Subject: Use fixtures to create test files This reduces the number of temporary folders and files created during testing. Additionally, an actual JPEG is created for a couple tests instead of using random text for the contents. --- tests/test_validations.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'tests/test_validations.py') diff --git a/tests/test_validations.py b/tests/test_validations.py index 161d102..aa4fdd0 100644 --- a/tests/test_validations.py +++ b/tests/test_validations.py @@ -163,14 +163,11 @@ class TestFileInput: class TestVerifyHash: """Define tests related to wikiget.validations.verify_hash.""" - def test_verify_hash(self, tmp_path: Path) -> None: - """Confirm that verify_hash returns the proper SHA1 hash.""" - file_name = "testfile" - file_contents = "foobar" - file_sha1 = "8843d7f92416211de9ebb963ff4ce28125932878" + def test_verify_hash(self, test_file: Path) -> None: + """Confirm that verify_hash returns the proper SHA1 hash. - # create a temporary file with known contents - tmp_file = tmp_path / file_name - tmp_file.write_text(file_contents) + The test file used here is generated by a fixture in conftest.py. + """ + expected_sha1 = "cd19c009a30ca9b68045415a3a0838e64f3c2443" - assert verify_hash(str(tmp_file)) == file_sha1 + assert verify_hash(str(test_file)) == expected_sha1 -- cgit v1.2.3