if MPI.size(MPI.comm_world) > 1:
MPI.barrier(MPI.comm_world)
-
-@pytest.fixture
def worker_id(request):
"""Returns thread id when running with pytest-xdist in parallel."""
if hasattr(request.config, 'slaveinput'):
else:
return 'master'
+@pytest.fixture
+def worker_id_fixture(request):
+ return worker_id(request)
@pytest.yield_fixture(scope="function")
def gc_barrier_fixture():
(UnitCubeMesh, (2, 2, 2)),
# cell.contains(Point) does not work correctly
# for quad/hex cells once it is fixed, this test will pass
- xfail((UnitSquareMesh.create, (4, 4, CellType.Type.quadrilateral))),
- xfail((UnitCubeMesh.create, (2, 2, 2, CellType.Type.hexahedron)))])
+ pytest.param(((UnitSquareMesh.create, (4, 4, CellType.Type.quadrilateral))), marks=xfail),
+ pytest.param(((UnitCubeMesh.create, (2, 2, 2, CellType.Type.hexahedron))), marks=xfail)])
def test_tabulate_all_coordinates(mesh_factory):
func, args = mesh_factory
mesh = func(*args)
"FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.hexahedron), 'DQ', 2)",
"FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.triangle), 'N1curl', 1)",
"FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.tetrahedron), 'N1curl', 1)",
- xfail_ffc("FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.quadrilateral), 'N1curl', 1)"),
- xfail_ffc("FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.hexahedron), 'N1curl', 1)"),
+ pytest.param(("FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.quadrilateral), 'N1curl', 1)"), marks=xfail_ffc),
+ pytest.param(("FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.hexahedron), 'N1curl', 1)"), marks=xfail_ffc),
"FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.triangle), 'N1curl', 2)",
"FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.tetrahedron), 'N1curl', 2)",
- xfail_ffc("FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.quadrilateral), 'N1curl', 2)"),
- xfail_ffc("FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.hexahedron), 'N1curl', 2)"),
+ pytest.param(("FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.quadrilateral), 'N1curl', 2)"), marks=xfail_ffc),
+ pytest.param(("FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.hexahedron), 'N1curl', 2)"), marks=xfail_ffc),
"FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.triangle), 'RT', 1)",
"FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.tetrahedron), 'RT', 1)",
- xfail_ffc("FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.quadrilateral), 'RT', 1)"),
- xfail_ffc("FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.hexahedron), 'RT', 1)"),
+ pytest.param(("FunctionSpace(UnitSquareMesh.create(6, 6, CellType.Type.quadrilateral), 'RT', 1)"), marks=xfail_ffc),
+ pytest.param(("FunctionSpace(UnitCubeMesh.create(2, 2, 2, CellType.Type.hexahedron), 'RT', 1)"), marks=xfail_ffc),
])
def test_dofs_dim(space):
"""Test function GenericDofMap::dofs(mesh, dim)"""
(UnitSquareMesh.create, (4, 4, CellType.Type.quadrilateral)),
# cell_normal has not been implemented for hex cell
# cell.orientation() does not work
- xfail((UnitCubeMesh.create, (2, 2, 2, CellType.Type.hexahedron)))])
+ pytest.param(((UnitCubeMesh.create, (2, 2, 2, CellType.Type.hexahedron))), marks=xfail)])
def test_evaluate_dofs(mesh_factory):
func, args = mesh_factory
line_resolution = 8
-
-@fixture
-def line1d(request):
+def line1d_impl(request):
n = line_resolution
us = [i/float(n-1) for i in range(n)]
vertices = [(u**2,) for u in us]
return create_line_mesh(vertices)
-
-@fixture
-def rline1d(request):
+def rline1d_impl(request):
n = line_resolution
us = [i/float(n-1) for i in range(n)]
vertices = [(u**2,) for u in us]
vertices = list(reversed(vertices)) # same as line1d, just reversed here
return create_line_mesh(vertices)
-
-@fixture
-def line2d(request):
+def line2d_impl(request):
n = line_resolution
us = [i/float(n-1) for i in range(n)]
vertices = [(cos(DOLFIN_PI*u), sin(DOLFIN_PI*u)) for u in us]
mesh.init_cell_orientations(Expression(("0.0", "1.0"), degree=0))
return mesh
-
-@fixture
-def rline2d(request):
+def rline2d_impl(request):
n = line_resolution
us = [i/float(n-1) for i in range(n)]
vertices = [(cos(DOLFIN_PI*u), sin(DOLFIN_PI*u)) for u in us]
mesh.init_cell_orientations(Expression(("0.0", "1.0"), degree=0))
return mesh
-
-@fixture
-def line3d(request):
+def line3d_impl(request):
n = line_resolution
us = [i/float(n-1) for i in range(n)]
vertices = [(cos(4.0*DOLFIN_PI*u),
mesh = create_line_mesh(vertices)
return mesh
-
-@fixture
-def rline3d(request):
+def rline3d_impl(request):
n = line_resolution
us = [i/float(n-1) for i in range(n)]
vertices = [(cos(4.0*DOLFIN_PI*u),
mesh = create_line_mesh(vertices)
return mesh
-
-@fixture
-def square2d(request):
+def square2d_impl(request):
cellname = "triangle"
side = sqrt(sqrt(3.0))
vertices = [
mesh = create_mesh(vertices, cells)
return mesh
-
-@fixture
-def square3d(request):
+def square3d_impl(request):
cellname = "triangle"
vertices = [
(0.0, 0.0, 1.0),
return mesh
+@fixture
+def line1d(request):
+ return line1d_impl(request)
+
+@fixture
+def rline1d(request):
+ return rline1d_impl(request)
+
+@fixture
+def line2d(request):
+ return line2d_impl(request)
+
+@fixture
+def rline2d(request):
+ return rline2d_impl(request)
+
+@fixture
+def line3d(request):
+ return line3d_impl(request)
+
+@fixture
+def rline3d(request):
+ return rline3d_impl(request)
+
+@fixture
+def square2d(request):
+ return square2d_impl(request)
+
+@fixture
+def square3d(request):
+ return square3d_impl(request)
@skip_in_parallel
def test_line_meshes(line1d, line2d, line3d, rline1d, rline2d, rline3d):
"DG", 0))
-@skip_in_parallel
@pytest.mark.parametrize("mesh", [
- line1d(None),
- line2d(None),
- line3d(None),
- rline1d(None),
- rline2d(None),
- rline3d(None), ])
+ line1d_impl(None),
+ line2d_impl(None),
+ line3d_impl(None),
+ rline1d_impl(None),
+ rline2d_impl(None),
+ rline3d_impl(None), ])
+@skip_in_parallel
def test_manifold_line_geometry(mesh, uflacs_representation_only):
assert uflacs_representation_only == "uflacs"
assert parameters["form_compiler"]["representation"] == "uflacs"
(UnitCubeMesh, (2, 2, 2)),
(UnitSquareMesh.create, (4, 4, CellType.Type.quadrilateral)),
(UnitCubeMesh.create, (2, 2, 2, CellType.Type.hexahedron)),
- (line1d, (None,)),
- (line2d, (None,)),
- (line3d, (None,)),
- (rline1d, (None,)),
- (rline2d, (None,)),
- (rline3d, (None,)),
- (square2d, (None,)),
- (square3d, (None,)),
+ (line1d_impl, (None,)),
+ (line2d_impl, (None,)),
+ (line3d_impl, (None,)),
+ (rline1d_impl, (None,)),
+ (rline2d_impl, (None,)),
+ (rline3d_impl, (None,)),
+ (square2d_impl, (None,)),
+ (square3d_impl, (None,)),
# Tested geometric quantities are not implemented for higher-order cells
- xfail_jit((UnitDiscMesh.create, (MPI.comm_world, 4, 2, 2))),
- xfail_jit((UnitDiscMesh.create, (MPI.comm_world, 4, 2, 3))),
- xfail_jit((SphericalShellMesh.create, (MPI.comm_world, 2,))),
-])
+ pytest.param(((UnitDiscMesh.create, (MPI.comm_world, 4, 2, 2))), marks=xfail_jit),
+ pytest.param(((UnitDiscMesh.create, (MPI.comm_world, 4, 2, 3))), marks=xfail_jit),
+ pytest.param(((SphericalShellMesh.create, (MPI.comm_world, 2,))), marks=xfail_jit)])
@skip_in_parallel
def test_geometric_quantities(uflacs_representation_only, mesh_factory):
+
func, args = mesh_factory
mesh = func(*args)
assert Q.sub(0) == Q.extract_sub_space([0])
-def test_in_operator(f, g, V, V2, W, W2):
+def test_in_operator(f, g, V, V2, W, W2, mesh):
assert f in V
assert f in V2
assert g in W
assert g in W2
with pytest.raises(RuntimeError):
- mesh() in V
+ mesh in V
def test_collapse(W, V):
import pytest
from dolfin_utils.test import skip_if_not_PETSc, skip_in_parallel
-backends = ["PETSc", skip_in_parallel("Eigen")]
+backends = ["PETSc", pytest.param(("Eigen"), marks=skip_in_parallel)]
@pytest.mark.parametrize('backend', backends)
def test_lu_solver(backend):
import pytest
from dolfin_utils.test import *
-backends = ["PETSc", skip_in_parallel("Eigen")]
+backends = ["PETSc", pytest.param(("Eigen"), marks=skip_in_parallel)]
def build_elastic_nullspace(V, x):
"""Function to build nullspace for 2D/3D elasticity"""
(UnitIntervalMesh, (8,)),
(UnitSquareMesh, (4, 4)),
# FIXME: Problem in test_shared_entities
- xfail_in_parallel((UnitDiscMesh.create, (MPI.comm_world, 10, 1, 2))),
- xfail_in_parallel((UnitDiscMesh.create, (MPI.comm_world, 10, 2, 2))),
- xfail_in_parallel((UnitDiscMesh.create, (MPI.comm_world, 10, 1, 3))),
- xfail_in_parallel((UnitDiscMesh.create, (MPI.comm_world, 10, 2, 3))),
- xfail_in_parallel((SphericalShellMesh.create, (MPI.comm_world, 1,))),
- xfail_in_parallel((SphericalShellMesh.create, (MPI.comm_world, 2,))),
+ pytest.param(((UnitDiscMesh.create, (MPI.comm_world, 10, 1, 2))), marks=xfail_in_parallel),
+ pytest.param(((UnitDiscMesh.create, (MPI.comm_world, 10, 2, 2))), marks=xfail_in_parallel),
+ pytest.param(((UnitDiscMesh.create, (MPI.comm_world, 10, 1, 3))), marks=xfail_in_parallel),
+ pytest.param(((UnitDiscMesh.create, (MPI.comm_world, 10, 2, 3))), marks=xfail_in_parallel),
+ pytest.param(((SphericalShellMesh.create, (MPI.comm_world, 1,))), marks=xfail_in_parallel),
+ pytest.param(((SphericalShellMesh.create, (MPI.comm_world, 2,))), marks=xfail_in_parallel),
(UnitCubeMesh, (2, 2, 2)),
(UnitSquareMesh.create, (4, 4, CellType.Type.quadrilateral)),
(UnitCubeMesh.create, (2, 2, 2, CellType.Type.hexahedron)),
- xfail_in_parallel((create_two_good_quads, ())),
+ pytest.param(((create_two_good_quads, ())), marks=xfail_in_parallel),
]
# FIXME: Fix this xfail
from dolfin_utils.test import skip_in_parallel
# test case with interface-edge overlap
-@pytest.fixture
-def test_case_1(M, N):
+def case_1_impl(M, N):
multimesh = MultiMesh()
mesh0 = UnitSquareMesh(M, M)
mesh1 = RectangleMesh(Point(0.25, 0.25), Point(0.75, 0.75), N, N)
return multimesh
# test case with squares on the diagonal
-@pytest.fixture
-def test_case_2(width, offset, Nx):
+def case_2_impl(width, offset, Nx):
# Mesh width (must be less than 1)
assert width < 1
multimesh.build()
return multimesh
-test_cases = [test_case_1(4,3),
- test_case_2(DOLFIN_PI/5, 0.1111, 3)]
+@pytest.fixture
+def case_1(M, N):
+ return case_1_impl(M,N)
+
+@pytest.fixture
+def case_2(width, offset, Nx):
+ return case_2_impl(width, offset, Nx)
+
+test_cases = [case_1_impl(4,3),
+ case_2_impl(DOLFIN_PI/5, 0.1111, 3)]
@skip_in_parallel
@pytest.mark.parametrize("multimesh", test_cases)
from dolfin_utils.test import skip_in_parallel, fixture
-@fixture
-def exactsolution_2d():
+def exactsolution_2d_impl():
return Expression("x[0] + x[1]", degree=1)
-@fixture
-def exactsolution_3d():
+def exactsolution_3d_impl():
return Expression("x[0] + x[1] + x[2]", degree=1)
-@fixture
def solve_multimesh_poisson(mesh_0, mesh_1, exactsolution):
-
# Build multimesh
multimesh = MultiMesh()
multimesh.add(mesh_0)
return uh
+@fixture
+def exactsolution_2d():
+ return exactsolution_2d_impl()
+
+@fixture
+def exactsolution_3d():
+ return exactsolution_3d_impl()
+
@pytest.mark.slow
@skip_in_parallel
-def test_multimesh_poisson_2d():
+def test_multimesh_poisson_2d(exactsolution_2d):
# This tests solves a Poisson problem on two meshes in 2D with u =
# x+y as exact solution
mesh_1 = RectangleMesh(Point(0.1*DOLFIN_PI, 0.1*DOLFIN_PI),
Point(0.2*DOLFIN_PI, 0.2*DOLFIN_PI),
2, 2)
-
# Solve multimesh Poisson
- uh = solve_multimesh_poisson(mesh_0, mesh_1, exactsolution_2d())
+ uh = solve_multimesh_poisson(mesh_0, mesh_1, exactsolution_2d)
# Check error
- assert errornorm(exactsolution_2d(), uh, 'L2', degree_rise=1) < DOLFIN_EPS_LARGE
+ assert errornorm(exactsolution_2d, uh, 'L2', degree_rise=1) < DOLFIN_EPS_LARGE
@pytest.mark.slow
@pytest.mark.skip
@skip_in_parallel
@pytest.mark.skipif(True, reason="3D not fully implemented")
-def test_multimesh_poisson_3d():
+def test_multimesh_poisson_3d(exactsolution_3d):
# This tests solves a Poisson problem on two meshes in 3D with u =
# x+y+z as exact solution
2, 2, 2)
# Solve multimesh Poisson
- uh = solve_multimesh_poisson(mesh_0, mesh_1, exactsolution_3d())
+ uh = solve_multimesh_poisson(mesh_0, mesh_1, exactsolution_3d)
# Check error
- assert errornorm(exactsolution_3d(), uh, 'L2', degree_rise=1) < DOLFIN_EPS_LARGE
+ assert errornorm(exactsolution_3d, uh, 'L2', degree_rise=1) < DOLFIN_EPS_LARGE