From 5d597f1ca96659418f9fc4e68a81773cad7e0517 Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Fri, 29 Mar 2024 14:25:08 +0100 Subject: [PATCH] Use new "with ()" style --- .../tests/models/test_bookwyrm_export_job.py | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/bookwyrm/tests/models/test_bookwyrm_export_job.py b/bookwyrm/tests/models/test_bookwyrm_export_job.py index a02cfe052..29a2a07c1 100644 --- a/bookwyrm/tests/models/test_bookwyrm_export_job.py +++ b/bookwyrm/tests/models/test_bookwyrm_export_job.py @@ -233,22 +233,24 @@ class BookwyrmExportJob(TestCase): models.bookwyrm_export_job.create_archive_task(job_id=self.job.id) self.job.refresh_from_db() - with self.job.export_data.open("rb") as tar_file: - with BookwyrmTarFile.open(mode="r", fileobj=tar_file) as tar: - archive_json_file = tar.extractfile("archive.json") - data = json.load(archive_json_file) + with ( + self.job.export_data.open("rb") as tar_file, + BookwyrmTarFile.open(mode="r", fileobj=tar_file) as tar, + ): + archive_json_file = tar.extractfile("archive.json") + data = json.load(archive_json_file) - # JSON from the archive should be what we want it to be - self.assertEqual(data, self.job.export_json) + # JSON from the archive should be what we want it to be + self.assertEqual(data, self.job.export_json) - # User avatar should be present in archive - with self.local_user.avatar.open() as expected_avatar: - archive_avatar = tar.extractfile(data["icon"]["url"]) - self.assertEqual(expected_avatar.read(), archive_avatar.read()) + # User avatar should be present in archive + with self.local_user.avatar.open() as expected_avatar: + archive_avatar = tar.extractfile(data["icon"]["url"]) + self.assertEqual(expected_avatar.read(), archive_avatar.read()) - # Edition cover should be present in archive - with self.edition.cover.open() as expected_cover: - archive_cover = tar.extractfile( - data["books"][0]["edition"]["cover"]["url"] - ) - self.assertEqual(expected_cover.read(), archive_cover.read()) + # Edition cover should be present in archive + with self.edition.cover.open() as expected_cover: + archive_cover = tar.extractfile( + data["books"][0]["edition"]["cover"]["url"] + ) + self.assertEqual(expected_cover.read(), archive_cover.read())