From 6997fe3290b313219866a5e1e4c4de246380e684 Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Sat, 15 Jul 2023 17:07:07 +0200 Subject: [PATCH] Optimize slow tests --- tests/test_compress_assets_plugin.py | 4 ++-- tests/test_encrypt.py | 14 +++++++------- tests/test_gallery.py | 22 +++++++++------------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/tests/test_compress_assets_plugin.py b/tests/test_compress_assets_plugin.py index 9000363..161904b 100644 --- a/tests/test_compress_assets_plugin.py +++ b/tests/test_compress_assets_plugin.py @@ -12,11 +12,11 @@ CURRENT_DIR = os.path.dirname(__file__) def make_gallery(settings, tmpdir, method): + settings["source"] = os.path.join(settings["source"], "dir1") settings["destination"] = str(tmpdir) # Really speed up testing settings["use_orig"] = True - if "sigal.plugins.compress_assets" not in settings["plugins"]: - settings["plugins"] += ["sigal.plugins.compress_assets"] + settings["plugins"] = ["sigal.plugins.compress_assets"] # Set method settings.setdefault("compress_assets_options", {})["method"] = method diff --git a/tests/test_encrypt.py b/tests/test_encrypt.py index 5179359..ea29808 100644 --- a/tests/test_encrypt.py +++ b/tests/test_encrypt.py @@ -22,19 +22,19 @@ def get_key_tag(settings): def test_encrypt(settings, tmpdir, disconnect_signals, caplog): + settings["source"] = os.path.join(settings["source"], "encryptTest") settings["destination"] = str(tmpdir) - if "sigal.plugins.encrypt" not in settings["plugins"]: - settings["plugins"] += ["sigal.plugins.encrypt"] + settings["plugins"] = ["sigal.plugins.encrypt"] init_plugins(settings) - gal = Gallery(settings) + gal = Gallery(settings, ncpu=1) with pytest.raises(ValueError, match="no encrypt_options in settings"): gal.build() settings["encrypt_options"] = {} - gal = Gallery(settings) + gal = Gallery(settings, ncpu=1) with pytest.raises(ValueError, match="no password provided"): gal.build() @@ -45,7 +45,7 @@ def test_encrypt(settings, tmpdir, disconnect_signals, caplog): "encrypt_symlinked_originals": False, } - gal = Gallery(settings) + gal = Gallery(settings, ncpu=1) gal.build() # check the encrypt cache exists @@ -57,7 +57,7 @@ def test_encrypt(settings, tmpdir, disconnect_signals, caplog): encryptCache = pickle.load(cacheFile) assert isinstance(encryptCache, dict) - testAlbum = gal.albums["encryptTest"] + testAlbum = gal.albums["."] key, tag = get_key_tag(settings) for media in testAlbum: @@ -94,7 +94,7 @@ def test_encrypt(settings, tmpdir, disconnect_signals, caplog): caplog.clear() caplog.set_level("DEBUG") - gal = Gallery(settings) + gal = Gallery(settings, ncpu=1) gal.build() # Doesn't work on Actions ... # assert 'Loaded cache with 34 entries' in caplog.messages diff --git a/tests/test_gallery.py b/tests/test_gallery.py index 72ff9a5..211c161 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -381,11 +381,8 @@ def test_gallery_max_img_pixels(settings, tmpdir, monkeypatch): # to show that settings['max_img_pixels'] works. monkeypatch.setattr("PIL.Image.MAX_IMAGE_PIXELS", 100_000_000) - with open(str(tmpdir.join("my.css")), mode="w") as f: - f.write("color: red") - + settings["source"] = os.path.join(settings["source"], "dir2") settings["destination"] = str(tmpdir) - settings["user_css"] = str(tmpdir.join("my.css")) settings["max_img_pixels"] = 5000 logger = logging.getLogger("sigal") @@ -408,15 +405,14 @@ def test_empty_dirs(settings): assert "dir1/empty" not in gal.albums -def test_ignores(settings, tmpdir): - tmp = str(tmpdir) - settings["destination"] = tmp - settings["ignore_directories"] = ["*test2", "accentué"] - settings["ignore_files"] = ["dir2/Hubble*", "*.png", "*CMB_*"] +def test_ignores(settings, tmp_path): + settings["source"] = os.path.join(settings["source"], "dir1") + settings["destination"] = str(tmp_path) + settings["ignore_directories"] = ["*test2"] + settings["ignore_files"] = ["*.gif", "*CMB_*"] gal = Gallery(settings, ncpu=1) gal.build() - assert "test2" not in os.listdir(join(tmp, "dir1")) - assert "accentué" not in os.listdir(tmp) - assert "CMB_Timeline300_no_WMAP.jpg" not in os.listdir(join(tmp, "dir1", "test1")) - assert "Hubble Interacting Galaxy NGC 5257.jpg" not in os.listdir(join(tmp, "dir2")) + assert not (tmp_path / "test2").exists() + assert not (tmp_path / "test1" / "example.gif").exists() + assert not (tmp_path / "test1" / "CMB_Timeline300_no_WMAP.jpg").exists()