Browse Source

Optimize slow tests

pull/498/head
Simon Conseil 3 years ago
parent
commit
6997fe3290
  1. 4
      tests/test_compress_assets_plugin.py
  2. 14
      tests/test_encrypt.py
  3. 22
      tests/test_gallery.py

4
tests/test_compress_assets_plugin.py

@ -12,11 +12,11 @@ CURRENT_DIR = os.path.dirname(__file__)
def make_gallery(settings, tmpdir, method): def make_gallery(settings, tmpdir, method):
settings["source"] = os.path.join(settings["source"], "dir1")
settings["destination"] = str(tmpdir) settings["destination"] = str(tmpdir)
# Really speed up testing # Really speed up testing
settings["use_orig"] = True 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 # Set method
settings.setdefault("compress_assets_options", {})["method"] = method settings.setdefault("compress_assets_options", {})["method"] = method

14
tests/test_encrypt.py

@ -22,19 +22,19 @@ def get_key_tag(settings):
def test_encrypt(settings, tmpdir, disconnect_signals, caplog): def test_encrypt(settings, tmpdir, disconnect_signals, caplog):
settings["source"] = os.path.join(settings["source"], "encryptTest")
settings["destination"] = str(tmpdir) 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) init_plugins(settings)
gal = Gallery(settings) gal = Gallery(settings, ncpu=1)
with pytest.raises(ValueError, match="no encrypt_options in settings"): with pytest.raises(ValueError, match="no encrypt_options in settings"):
gal.build() gal.build()
settings["encrypt_options"] = {} settings["encrypt_options"] = {}
gal = Gallery(settings) gal = Gallery(settings, ncpu=1)
with pytest.raises(ValueError, match="no password provided"): with pytest.raises(ValueError, match="no password provided"):
gal.build() gal.build()
@ -45,7 +45,7 @@ def test_encrypt(settings, tmpdir, disconnect_signals, caplog):
"encrypt_symlinked_originals": False, "encrypt_symlinked_originals": False,
} }
gal = Gallery(settings) gal = Gallery(settings, ncpu=1)
gal.build() gal.build()
# check the encrypt cache exists # check the encrypt cache exists
@ -57,7 +57,7 @@ def test_encrypt(settings, tmpdir, disconnect_signals, caplog):
encryptCache = pickle.load(cacheFile) encryptCache = pickle.load(cacheFile)
assert isinstance(encryptCache, dict) assert isinstance(encryptCache, dict)
testAlbum = gal.albums["encryptTest"] testAlbum = gal.albums["."]
key, tag = get_key_tag(settings) key, tag = get_key_tag(settings)
for media in testAlbum: for media in testAlbum:
@ -94,7 +94,7 @@ def test_encrypt(settings, tmpdir, disconnect_signals, caplog):
caplog.clear() caplog.clear()
caplog.set_level("DEBUG") caplog.set_level("DEBUG")
gal = Gallery(settings) gal = Gallery(settings, ncpu=1)
gal.build() gal.build()
# Doesn't work on Actions ... # Doesn't work on Actions ...
# assert 'Loaded cache with 34 entries' in caplog.messages # assert 'Loaded cache with 34 entries' in caplog.messages

22
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. # to show that settings['max_img_pixels'] works.
monkeypatch.setattr("PIL.Image.MAX_IMAGE_PIXELS", 100_000_000) monkeypatch.setattr("PIL.Image.MAX_IMAGE_PIXELS", 100_000_000)
with open(str(tmpdir.join("my.css")), mode="w") as f: settings["source"] = os.path.join(settings["source"], "dir2")
f.write("color: red")
settings["destination"] = str(tmpdir) settings["destination"] = str(tmpdir)
settings["user_css"] = str(tmpdir.join("my.css"))
settings["max_img_pixels"] = 5000 settings["max_img_pixels"] = 5000
logger = logging.getLogger("sigal") logger = logging.getLogger("sigal")
@ -408,15 +405,14 @@ def test_empty_dirs(settings):
assert "dir1/empty" not in gal.albums assert "dir1/empty" not in gal.albums
def test_ignores(settings, tmpdir): def test_ignores(settings, tmp_path):
tmp = str(tmpdir) settings["source"] = os.path.join(settings["source"], "dir1")
settings["destination"] = tmp settings["destination"] = str(tmp_path)
settings["ignore_directories"] = ["*test2", "accentué"] settings["ignore_directories"] = ["*test2"]
settings["ignore_files"] = ["dir2/Hubble*", "*.png", "*CMB_*"] settings["ignore_files"] = ["*.gif", "*CMB_*"]
gal = Gallery(settings, ncpu=1) gal = Gallery(settings, ncpu=1)
gal.build() gal.build()
assert "test2" not in os.listdir(join(tmp, "dir1")) assert not (tmp_path / "test2").exists()
assert "accentué" not in os.listdir(tmp) assert not (tmp_path / "test1" / "example.gif").exists()
assert "CMB_Timeline300_no_WMAP.jpg" not in os.listdir(join(tmp, "dir1", "test1")) assert not (tmp_path / "test1" / "CMB_Timeline300_no_WMAP.jpg").exists()
assert "Hubble Interacting Galaxy NGC 5257.jpg" not in os.listdir(join(tmp, "dir2"))

Loading…
Cancel
Save