Skip to content

Commit

Permalink
Add test images generation script (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle authored Oct 16, 2023
1 parent 4a6a505 commit 2876ac2
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
image_cache
40 changes: 40 additions & 0 deletions data/tests/images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#

Please **do not** manually edit this `README.md` as the contents will be overwritten by the `generate_images.py` script.

This directory contains test images generated on the following platform:

----------------------------------------------------------------------------------------
Date: Mon Oct 16 12:35:15 2023 BST

OS : Linux
CPU(s) : 4
Machine : x86_64
Architecture : 64bit
Environment : Python
GPU Vendor : Intel Open Source Technology Center
GPU Renderer : Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)
GPU Version : 4.2 (Core Profile) Mesa 20.0.8

Python 3.11.5 | packaged by conda-forge | (main, Aug 27 2023, 03:34:09) [GCC 12.3.0]

cartopy : 0.22.0
click : 8.1.7
click-default-group : 1.2.4
cmocean : v3.0.3
colorcet : 3.0.1
geovista : 0.5.0.dev14+dirty
matplotlib : 3.8.0
netcdf4 : 1.6.4
numpy : 1.26.0
platformdirs : 3.10.0
pooch : v1.7.0
pykdtree : 1.3.7.post0
pyproj : 3.6.0
pyvista : 0.42.1
scooby : 0.7.2
vtk : 9.2.6
IPython : 8.15.0
fastparquet : 2023.8.0
pandas : 2.1.0
----------------------------------------------------------------------------------------
61 changes: 61 additions & 0 deletions data/tests/images/generate_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Generate test images."""
import importlib
from pathlib import Path
import pkgutil
import shutil

import pyvista as pv
from pytest_pyvista import VerifyImageCache

import geovista as gv
import geovista.examples
from geovista.cache import CACHE
from geovista.report import Report


SCRIPTS = sorted(
[submodule.name for submodule in pkgutil.iter_modules(gv.examples.__path__)]
)

pv.global_theme.load_theme(pv.plotting.themes._TestingTheme())
pv.OFF_SCREEN = True
gv.GEOVISTA_IMAGE_TESTING = True

n_scripts: int = len(SCRIPTS)
width: int = len(str(n_scripts))

cache_dir = Path(__file__).parent.resolve() / "image_cache"
if cache_dir.is_dir():
shutil.rmtree(str(cache_dir))
if not cache_dir.exists():
cache_dir.mkdir()

print(f'\nGenerating {n_scripts} test images in "{cache_dir} ...')

for i, script in enumerate(SCRIPTS):
print(
f'[{i+1:0{width}d}/{n_scripts}] Generating image for "{script}" example ... ',
end="",
flush=True,
)
module = importlib.import_module(f"geovista.examples.{script}")
_ = CACHE.fetch(f"tests/images/{script}.png")
verify_image_cache = VerifyImageCache(f"test_{script}", cache_dir)
verify_image_cache.add_missing_images = True
pv.global_theme.before_close_callback = verify_image_cache
module.main()
print("done!", flush=True)

fname = "README.md"
with open(fname, "w", encoding="utf-8") as fh:
fh.write("# ⚠\n\n")
fh.write(
"Please **do not** manually edit this `README.md` as the contents will be overwritten by the `generate_images.py` script.\n\n"
)
fh.write(
"This directory contains test images generated on the following platform:\n"
)
fh.write(f"{str(Report())}\n")

print('\nUpdated report details in "README.md"\n')
print("👍 All done!")

0 comments on commit 2876ac2

Please sign in to comment.