Пример #1
0
def _test_demo(demo):
    import sys

    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot

        pyplot.show = nop
    except ImportError:
        pass
    try:
        import dolfin

        dolfin.plot = nop
        dolfin.interactive = nop
    except ImportError:
        pass
    result = None
    try:
        result = demo()
    except PySideMissing:
        pytest.xfail("PySide missing")
    finally:
        stop_gui_processes()
        from pymor.parallel.default import _cleanup

        _cleanup()

    return result
Пример #2
0
def test_demos(demo_args):
    module, args = demo_args

    import sys
    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot
        pyplot.show = nop
    except ImportError:
        pass
    try:
        import dolfin
        dolfin.plot = nop
        dolfin.interactive = nop
    except ImportError:
        pass
    try:
        ret = _run(module, args)
        # TODO find a better/tighter assert/way to run the code
        assert ret is not None
    except ImportError as ie:
        assert _is_failed_import_ok(ie), ie
    finally:
        stop_gui_processes()
        from pymor.parallel.default import _cleanup
        _cleanup()
Пример #3
0
def _test_demo(demo):
    import sys
    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot
        pyplot.show = nop
    except ImportError:
        pass
    try:
        import dolfin
        dolfin.plot = nop
        dolfin.interactive = nop
    except ImportError:
        pass
    result = None
    try:
        result = demo()
    except PySideMissing:
        pytest.xfail("PySide missing")
    finally:
        stop_gui_processes()
        from pymor.parallel.default import _cleanup
        _cleanup()

    return result
Пример #4
0
def test_demos(demo_args):
    module, args = demo_args
    try:
        ret = _run(module, args)
        # TODO find a better/tighter assert/way to run the code
        assert ret is not None
    except ImportError as ie:
        assert _is_failed_import_ok(ie)
    stop_gui_processes()
Пример #5
0
def test_visualize_patch(backend_gridtype):
    backend, gridtype = backend_gridtype
    domain = LineDomain() if gridtype is OnedGrid else RectDomain()
    dim = 1 if gridtype is OnedGrid else 2
    rhs = GenericFunction(lambda X: np.ones(X.shape[:-1]) * 10, dim)  # NOQA
    dirichlet = GenericFunction(lambda X: np.zeros(X.shape[:-1]), dim)  # NOQA
    diffusion = GenericFunction(lambda X: np.ones(X.shape[:-1]), dim)  # NOQA
    problem = EllipticProblem(domain=domain, rhs=rhs, dirichlet_data=dirichlet, diffusion_functions=(diffusion,))
    grid, bi = discretize_domain_default(problem.domain, grid_type=gridtype)
    discretization, data = discretize_elliptic_cg(analytical_problem=problem, grid=grid, boundary_info=bi)
    U = discretization.solve()
    visualize_patch(data['grid'], U=U, backend=backend)
    sleep(2)  # so gui has a chance to popup
    stop_gui_processes()
Пример #6
0
def _test_demo(demo):
    import sys
    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot
        pyplot.show = nop
    except ImportError:
        pass
    try:
        import dolfin
        dolfin.plot = nop
    except ImportError:
        pass

    # reset default RandomState
    import pymor.tools.random
    pymor.tools.random._default_random_state = None

    result = None
    try:
        result = demo()
    except QtMissing:
        pytest.xfail("Qt missing")
    except GmshError as ge:
        # this error is ok if gmsh isn't installed at all, or in the wrong version
        try:
            import pygmsh
            gmsh_major = pygmsh.get_gmsh_major_version()
            if gmsh_major != 2:
                pytest.xfail(
                    f'GMSH installed in incompatible major {gmsh_major}')
            else:
                raise ge
        except (ImportError, FileNotFoundError):
            pytest.xfail(f'GMSH not intalled')
        else:
            raise ge
    finally:
        stop_gui_processes()
        from pymor.parallel.default import _cleanup
        _cleanup()

    return result
Пример #7
0
def test_visualize_patch(backend_gridtype):
    backend, gridtype = backend_gridtype
    domain = LineDomain() if gridtype is OnedGrid else RectDomain()
    dim = 1 if gridtype is OnedGrid else 2
    rhs = GenericFunction(lambda X: np.ones(X.shape[:-1]) * 10, dim)  # NOQA
    dirichlet = GenericFunction(lambda X: np.zeros(X.shape[:-1]), dim)  # NOQA
    diffusion = GenericFunction(lambda X: np.ones(X.shape[:-1]), dim)  # NOQA
    problem = StationaryProblem(domain=domain, rhs=rhs, dirichlet_data=dirichlet, diffusion=diffusion)
    grid, bi = discretize_domain_default(problem.domain, grid_type=gridtype)
    discretization, data = discretize_stationary_cg(analytical_problem=problem, grid=grid, boundary_info=bi)
    U = discretization.solve()
    try:
        visualize_patch(data['grid'], U=U, backend=backend)
    except PySideMissing as ie:
        pytest.xfail("PySide missing")
    finally:
        stop_gui_processes()
Пример #8
0
def _test_demo(demo):
    import sys
    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot
        pyplot.show = nop
    except ImportError:
        pass
    try:
        import dolfin
        dolfin.plot = nop
    except ImportError:
        pass

    # reset default RandomState
    import pymor.tools.random
    pymor.tools.random._default_random_state = None

    result = None
    try:
        result = demo()
    except QtMissing:
        pytest.xfail("Qt missing")
    except GmshError as ge:
        # this error is ok if gmsh isn't installed at all, or in the wrong version
        try:
            import pygmsh
            gmsh_major = pygmsh.get_gmsh_major_version()
            if gmsh_major != 2:
                pytest.xfail(f'GMSH installed in incompatible major {gmsh_major}')
            else:
                raise ge
        except (ImportError, FileNotFoundError):
            pytest.xfail(f'GMSH not intalled')
        else:
            raise ge
    finally:
        stop_gui_processes()
        from pymor.parallel.default import _cleanup
        _cleanup()

    return result
Пример #9
0
def test_visualize_patch(backend_gridtype):
    backend, gridtype = backend_gridtype
    domain = LineDomain() if gridtype is OnedGrid else RectDomain()
    dim = 1 if gridtype is OnedGrid else 2
    rhs = GenericFunction(lambda X: np.ones(X.shape[:-1]) * 10, dim)  # NOQA
    dirichlet = GenericFunction(lambda X: np.zeros(X.shape[:-1]), dim)  # NOQA
    diffusion = GenericFunction(lambda X: np.ones(X.shape[:-1]), dim)  # NOQA
    problem = StationaryProblem(domain=domain, rhs=rhs, dirichlet_data=dirichlet, diffusion=diffusion)
    grid, bi = discretize_domain_default(problem.domain, grid_type=gridtype)
    d, data = discretize_stationary_cg(analytical_problem=problem, grid=grid, boundary_info=bi)
    U = d.solve()
    try:
        visualize_patch(data['grid'], U=U, backend=backend)
    except QtMissing as ie:
        pytest.xfail("Qt missing")
    finally:
        stop_gui_processes()
Пример #10
0
def test_visualize(grids_with_visualize):
    import sys
    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass
    try:
        from matplotlib import pyplot
        pyplot.show = nop
    except ImportError:
        pass

    try:
        g = grids_with_visualize
        U = np.ones(g.size(g.dim))
        g.visualize(U, g.dim)
    except QtMissing:
        pytest.xfail("Qt missing")
    finally:
        stop_gui_processes()
Пример #11
0
def test_visualize(grids_with_visualize):
    import sys
    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot
        pyplot.show = nop
    except ImportError:
        pass

    try:
        g = grids_with_visualize
        U = np.ones(g.size(g.dim))
        g.visualize(U, g.dim)
    except QtMissing:
        pytest.xfail("Qt missing")
    finally:
        stop_gui_processes()
Пример #12
0
 def teardown(self):
     from pymor.gui.qt import stop_gui_processes
     stop_gui_processes()