From fe7fb488c0824da5ba588dc2801e13ccf4c09bd7 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:54:34 -0700 Subject: [PATCH] Do some trickery to support Python 3.11 and mocking invalid module names --- .../tests/test_migration_encrypted_webp_conversion.py | 10 ++++++++-- src/documents/tests/test_migration_webp_conversion.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/documents/tests/test_migration_encrypted_webp_conversion.py b/src/documents/tests/test_migration_encrypted_webp_conversion.py index fbb5a8611..d8c5ddd52 100644 --- a/src/documents/tests/test_migration_encrypted_webp_conversion.py +++ b/src/documents/tests/test_migration_encrypted_webp_conversion.py @@ -1,3 +1,4 @@ +import importlib import shutil import tempfile from pathlib import Path @@ -10,12 +11,17 @@ from django.test import override_settings from documents.tests.utils import TestMigrations +# https://github.com/python/cpython/issues/100950 +migration_1037_obj = importlib.import_module( + "documents.migrations.1037_webp_encrypted_thumbnail_conversion", +) + @override_settings(PASSPHRASE="test") @mock.patch( - "documents.migrations.1037_webp_encrypted_thumbnail_conversion.multiprocessing.pool.Pool.map", + f"{__name__}.migration_1037_obj.multiprocessing.pool.Pool.map", ) -@mock.patch("documents.migrations.1037_webp_encrypted_thumbnail_conversion.run_convert") +@mock.patch(f"{__name__}.migration_1037_obj.run_convert") class TestMigrateToEncrytpedWebPThumbnails(TestMigrations): migrate_from = "1036_alter_savedviewfilterrule_rule_type" migrate_to = "1037_webp_encrypted_thumbnail_conversion" diff --git a/src/documents/tests/test_migration_webp_conversion.py b/src/documents/tests/test_migration_webp_conversion.py index db5fd83af..18367cbe6 100644 --- a/src/documents/tests/test_migration_webp_conversion.py +++ b/src/documents/tests/test_migration_webp_conversion.py @@ -1,3 +1,4 @@ +import importlib import shutil import tempfile from pathlib import Path @@ -10,11 +11,16 @@ from django.test import override_settings from documents.tests.utils import TestMigrations +# https://github.com/python/cpython/issues/100950 +migration_1021_obj = importlib.import_module( + "documents.migrations.1021_webp_thumbnail_conversion", +) + @mock.patch( - "documents.migrations.1021_webp_thumbnail_conversion.multiprocessing.pool.Pool.map", + f"{__name__}.migration_1021_obj.multiprocessing.pool.Pool.map", ) -@mock.patch("documents.migrations.1021_webp_thumbnail_conversion.run_convert") +@mock.patch(f"{__name__}.migration_1021_obj.run_convert") class TestMigrateWebPThumbnails(TestMigrations): migrate_from = "1020_merge_20220518_1839" migrate_to = "1021_webp_thumbnail_conversion"