Skip to content

Commit

Permalink
Merge pull request #250 from gerlero/pytest
Browse files Browse the repository at this point in the history
Use pytest for testing
  • Loading branch information
gerlero authored Feb 29, 2024
2 parents 2bba9c2 + 1e4f423 commit 8ad4692
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 89 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ updates:
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "pip"
directory: "/tests"
schedule:
interval: "weekly"
2 changes: 2 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,5 @@ jobs:
- name: Test
run: |
make test ${{ env.MAKE_VARS }}
env:
PRTE_MCA_rmaps_default_mapping_policy: ':oversubscribe'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/build
Brewfile.lock.json
*.tgz
.DS_Store
.DS_Store
venv
55 changes: 8 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ DEPS_KIND = standalone
DMG_FORMAT = UDRO
APP_HOMEPAGE = https://github.com/gerlero/openfoam-app
APP_VERSION =
TEST_DIR = build/test-v$(OPENFOAM_VERSION)
DIST_NAME = openfoam$(OPENFOAM_VERSION)-app-$(shell uname -m)
INSTALL_DIR = /Applications

Expand Down Expand Up @@ -206,69 +205,31 @@ $(OPENFOAM_TARBALL).sha256:


# Non-build targets and rules
test: test-dmg test-openfoam test-bash test-zsh

test-openfoam:
[ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME)
rm -rf $(TEST_DIR)/test-openfoam
mkdir -p $(TEST_DIR)/test-openfoam
build/$(APP_NAME).app/Contents/Resources/etc/openfoam -c foamInstallationTest
cd $(TEST_DIR)/test-openfoam \
&& "$(CURDIR)/build/$(APP_NAME).app/Contents/Resources/etc/openfoam" < "$(CURDIR)/scripts/test.sh"
build/$(APP_NAME).app/Contents/Resources/volume eject && [ ! -d $(VOLUME) ]

test-bash:
[ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME)
rm -rf $(TEST_DIR)/test-bash
mkdir -p $(TEST_DIR)/test-bash
PATH=$(VOLUME)/usr/opt/bash/bin:$$PATH bash -c \
'source build/$(APP_NAME).app/Contents/Resources/etc/bashrc; \
set -ex; \
foamInstallationTest; \
cd $(TEST_DIR)/test-bash; \
source "$(CURDIR)/scripts/test.sh"'
test: | tests/venv
tests/venv/bin/pip install -r tests/requirements.txt
build/$(APP_NAME).app/Contents/Resources/etc/openfoam -c tests/venv/bin/pytest
build/$(APP_NAME).app/Contents/Resources/volume eject && [ ! -d $(VOLUME) ]

test-zsh:
[ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME)
rm -rf $(TEST_DIR)/test-zsh
mkdir -p $(TEST_DIR)/test-zsh
zsh -c \
'source build/$(APP_NAME).app/Contents/Resources/etc/bashrc; \
set -ex; \
foamInstallationTest; \
cd $(TEST_DIR)/test-zsh; \
source "$(CURDIR)/scripts/test.sh"'
build/$(APP_NAME).app/Contents/Resources/volume eject && [ ! -d $(VOLUME) ]

test-dmg:
[ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME)
hdiutil attach build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg
rm -rf $(TEST_DIR)/test-dmg
mkdir -p $(TEST_DIR)/test-dmg
cd $(TEST_DIR)/test-dmg \
&& source $(VOLUME)/etc/bashrc \
&& foamInstallationTest \
&& "$(CURDIR)/scripts/test.sh"
hdiutil detach $(VOLUME)
tests/venv:
python3 -m venv tests/venv

clean-app:
[ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME)
rm -rf build/$(APP_NAME).app build/$(APP_NAME)-build.sparsebundle.shadow

clean-build: clean-app
rm -f build/$(DIST_NAME).zip
rm -rf build/$(APP_NAME)-build.sparsebundle $(TEST_DIR)/test-openfoam $(TEST_DIR)/test-bash $(TEST_DIR)/test-zsh $(TEST_DIR)/test-dmg
rmdir $(TEST_DIR) || true
rm -rf build/$(APP_NAME)-build.sparsebundle
rmdir build || true

clean: clean-build
rm -f $(OPENFOAM_TARBALL) Brewfile.lock.json
rm -rf tests/venv

uninstall:
rm -rf $(INSTALL_DIR)/$(APP_NAME).app

# Set special targets
.PHONY: app build deps fetch-source zip install test test-openfoam test-bash test-zsh test-dmg clean-app clean-build clean uninstall
.PHONY: app build deps fetch-source zip install test clean-app clean-build clean uninstall
.SECONDARY: $(VOLUME) $(OPENFOAM_TARBALL)
.DELETE_ON_ERROR:
41 changes: 0 additions & 41 deletions scripts/test.sh

This file was deleted.

3 changes: 3 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest>=7,<7.3
pytest-asyncio-cooperative>=0.36,<0.37
aiofoam>=0.4,<0.5
15 changes: 15 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

import os
from pathlib import Path

from aiofoam import Case

@pytest.fixture
async def pitz_case(tmp_path):
case = Case(Path(os.environ["FOAM_TUTORIALS"]) / "incompressible" / "simpleFoam" / "pitzDaily")
return await case.clone(tmp_path / case.name)

@pytest.mark.asyncio_cooperative
async def test_pitz(pitz_case):
await pitz_case.run()
16 changes: 16 additions & 0 deletions tests/test_foamy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

import os
from pathlib import Path

from aiofoam import Case

@pytest.fixture
async def blob(tmp_path):
case = Case(Path(os.environ["FOAM_TUTORIALS"]) / "mesh" / "foamyHexMesh" / "blob")
return await case.clone(tmp_path / case.name)

@pytest.mark.parametrize("parallel", [False, True])
@pytest.mark.asyncio_cooperative
async def test_blob(blob, parallel):
await blob.run(parallel=parallel)
36 changes: 36 additions & 0 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

import os
import shutil
from pathlib import Path

from aiofoam import Case

@pytest.fixture
async def flange(tmp_path):
case = Case(Path(os.environ["FOAM_TUTORIALS"]) / "basic" / "laplacianFoam" / "flange")
return await case.clone(tmp_path / case.name)

@pytest.mark.asyncio_cooperative
async def test_serial(flange):
await flange.run(parallel=False)

@pytest.mark.asyncio_cooperative
async def test_parallel(flange):
await flange.run(parallel=True)
await flange.cmd(["reconstructPar"])

@pytest.mark.asyncio_cooperative
async def test_parallel_manual(flange):
shutil.copytree(flange.path / "0.orig", flange.path / "0")
await flange.cmd(["ansysToFoam", Path(os.environ["FOAM_TUTORIALS"]) / "resources" / "geometry" / "flange.ans", "-scale", "0.001"])
await flange.run(script=False, parallel=True)
await flange.cmd(["reconstructPar"])

@pytest.mark.asyncio_cooperative
async def test_parallel_manual_shell(flange):
shutil.copytree(flange.path / "0.orig", flange.path / "0")
await flange.cmd("ansysToFoam \"$FOAM_TUTORIALS/resources/geometry/flange.ans\" -scale 0.001")
await flange.cmd("decomposePar")
await flange.cmd("laplacianFoam", parallel=True)
await flange.cmd("reconstructPar")
20 changes: 20 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

import os
import subprocess
from pathlib import Path

from aiofoam import Case

@pytest.fixture
async def step(tmp_path):
case = Case(Path(os.environ["FOAM_TUTORIALS"]) / "incompressible" / "simpleFoam" / "backwardFacingStep2D")
return await case.clone(tmp_path / case.name)

@pytest.mark.asyncio_cooperative
async def test_step(step):
await step.run()
assert "FOAM Warning" not in (step.path / "log.simpleFoam").read_text()

def test_cartesian(): # https://github.com/gerlero/openfoam-app/issues/88
subprocess.run(["cartesianMesh", "-help"], check=True)

0 comments on commit 8ad4692

Please sign in to comment.