示例#1
0
    def runTests(self):
        from fipy.tools import numerix
        printoptions = numerix.get_printoptions()
        if "legacy" in printoptions:
            numerix.set_printoptions(legacy="1.13")

        super(_TestProgram, self).runTests()
示例#2
0
 def GetMesh(self):
     """Create and get the FiPy mesh.
     """
     np.set_printoptions(threshold=np.nan)
     #        print self.vertices
     #        print self.faces
     #        print self.cells
     return fipy.meshes.mesh2D.Mesh2D(self.vertices, self.faces, self.cells)
示例#3
0
def testmod(m=None,
            name=None,
            globs=None,
            verbose=None,
            report=True,
            optionflags=0,
            extraglobs=None,
            raise_on_error=False,
            exclude_empty=False):
    """Test examples in the given module.  Return (#failures, #tests).

    Largely duplicated from :func:`doctest.testmod`, but using
    :class:`_SelectiveDocTestParser`.

    Test examples in docstrings in functions and classes reachable
    from module m (or the current module if m is not supplied), starting
    with m.__doc__.

    Also test examples reachable from dict m.__test__ if it exists and is
    not None.  m.__test__ maps names to functions, classes and strings;
    function and class docstrings are tested even if the name is private;
    strings are tested directly, as if they were docstrings.

    Return (#failures, #tests).

    See help(doctest) for an overview.

    Optional keyword arg "name" gives the name of the module; by default
    use m.__name__.

    Optional keyword arg "globs" gives a dict to be used as the globals
    when executing examples; by default, use m.__dict__.  A copy of this
    dict is actually used for each docstring, so that each docstring's
    examples start with a clean slate.

    Optional keyword arg "extraglobs" gives a dictionary that should be
    merged into the globals that are used to execute examples.  By
    default, no extra globals are used.  This is new in 2.4.

    Optional keyword arg "verbose" prints lots of stuff if true, prints
    only failures if false; by default, it's true iff "-v" is in sys.argv.

    Optional keyword arg "report" prints a summary at the end when true,
    else prints nothing at the end.  In verbose mode, the summary is
    detailed, else very brief (in fact, empty if all tests passed).

    Optional keyword arg "optionflags" or's together module constants,
    and defaults to 0.  This is new in 2.3.  Possible values (see the
    docs for details):

        DONT_ACCEPT_TRUE_FOR_1
        DONT_ACCEPT_BLANKLINE
        NORMALIZE_WHITESPACE
        ELLIPSIS
        SKIP
        IGNORE_EXCEPTION_DETAIL
        REPORT_UDIFF
        REPORT_CDIFF
        REPORT_NDIFF
        REPORT_ONLY_FIRST_FAILURE

    as well as FiPy's flags

        GMSH
        SCIPY
        TVTK
        SERIAL
        PARALLEL
        PROCESSOR_0
        PROCESSOR_0_OF_2
        PROCESSOR_1_OF_2
        PROCESSOR_0_OF_3
        PROCESSOR_1_OF_3
        PROCESSOR_2_OF_3

    Optional keyword arg "raise_on_error" raises an exception on the
    first unexpected exception or failure. This allows failures to be
    postmortem debugged.
    """
    # If no module was given, then use __main__.
    if m is None:
        # DWA - m will still be None if this wasn't invoked from the command
        # line, in which case the following TypeError is about as good an error
        # as we should expect
        m = sys.modules.get('__main__')

    # Check that we were actually given a module.
    if not inspect.ismodule(m):
        raise TypeError("testmod: module required; %r" % (m, ))

    # If no name was given, then use the module's name.
    if name is None:
        name = m.__name__

    # Find, parse, and run all tests in the given module.
    finder = doctest.DocTestFinder(exclude_empty=exclude_empty,
                                   parser=_SelectiveDocTestParser())

    if raise_on_error:
        runner = doctest.DebugRunner(verbose=verbose, optionflags=optionflags)
    else:
        runner = doctest.DocTestRunner(verbose=verbose,
                                       optionflags=optionflags)

    from fipy.tools import numerix
    printoptions = numerix.get_printoptions()
    if "legacy" in printoptions:
        numerix.set_printoptions(legacy="1.13")

    for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
        runner.run(test)

    if report:
        runner.summarize()
        report_skips()

    results = doctest.TestResults(runner.failures, runner.tries)

    if "legacy" in printoptions:
        numerix.set_printoptions(legacy=printoptions["legacy"])

    return results
示例#4
0
文件: test.py 项目: yswang0927/fipy
    def run_tests(self):
        import sys
        if self.Trilinos or self.trilinos or self.no_pysparse:
            try:
                ## The import scipy statement is added to allow
                ## the --Trilinos tests to run without throwing a
                ## segmentation fault. This is caused by weird
                ## behavior in scipy and PyTrilinos depending on
                ## the order in which modules are imported
                try:
                    import scipy
                except:
                    pass
                import PyTrilinos
            except ImportError as a:
                print("!!! Trilinos library is not installed", file=sys.stderr)
                return

        if self.pyamgx:
            try:
                ## Unregister the function pyamgx.finalize
                ## from atexit. This prevents
                ## pyamgx from printing an error message
                ## about memory leaks and a dump of leaked memory.
                ## The memory leaks happen because
                ## the tests do not use the pyamgx solvers
                ## "cleanly", i.e., they do not use the
                ## `with` statement.
                import pyamgx
                import atexit
                if hasattr(atexit, 'unregister'):
                    atexit.unregister(pyamgx.finalize)
                else:
                    atexit._exithandlers.remove((pyamgx.finalize, (), {}))
            except ImportError as e:
                print("!!! pyamgx package is not installed", file=sys.stederr)
                return

        if self.inline:
            try:
                import weave
            except ImportError as a:
                print("!!! weave library is not installed", file=sys.stderr)
                return

        if self.pythoncompiled is not None:
            import os
            os.environ['PYTHONCOMPILED'] = self.pythoncompiled

        self.printPackageInfo()

        from pkg_resources import EntryPoint
        import unittest
        loader_ep = EntryPoint.parse("x=" + self.test_loader)
        loader_class = loader_ep.load(require=False)

        from fipy.tools import numerix
        printoptions = numerix.get_printoptions()
        if "legacy" in printoptions:
            numerix.set_printoptions(legacy="1.13")

        try:
            unittest.main(None,
                          None, [unittest.__file__] + self.test_args,
                          testLoader=loader_class())
        except SystemExit as exitErr:
            # unittest.main(..., exit=...) not available until Python 2.7
            from fipy.tests.doctestPlus import report_skips
            report_skips()
            if self.timetests is not None:
                pass
            else:
                raise

        if "legacy" in printoptions:
            numerix.set_printoptions(legacy=printoptions["legacy"])

        if self.timetests is not None:
            from fipy.tests.doctestPlus import _DocTestTimes
            import numpy
            _DocTestTimes = numpy.rec.fromrecords(_DocTestTimes,
                                                  formats='f8,S255',
                                                  names='time,test')
            _DocTestTimes.sort(order=('time', 'test'))
            numpy.savetxt(self.timetests, _DocTestTimes[::-1], fmt="%8.4f\t%s")

        raise exitErr
from datetime import datetime, timedelta

home_dir = os.getcwd()
dir_name = "/results"
dir_name2 = home_dir + dir_name
test = os.listdir(dir_name2)
for item in test:
    if item.endswith("9a.txt"):
        os.remove(os.path.join(dir_name2, item))
    if item.endswith("9a.vtk"):
        os.remove(os.path.join(dir_name2, item))
    if item.endswith("9a.vtp"):
        os.remove(os.path.join(dir_name2, item))
        
        
np.set_printoptions(threshold=sys.maxsize)

class NullIO(StringIO):
    def write(self, txt):
       pass

######################
#
# plant
#
####################### 
pl = pb.MappedPlant() #pb.MappedRootSystem() #pb.MappedPlant()

path = "../../../modelparameter/plant/" #"../../../modelparameter/rootsystem/" 
name = "oneroot_mgiraud" #"smallPlant_mgiraud"#"manyleaves"#"smallPlant"# "oneroot" #"Anagallis_femina_Leitner_2010"  # Zea_mays_1_Leitner_2010
pl.readParameters(path + name + ".xml")
示例#6
0
        if self.pythoncompiled is not None:
            import os
            os.environ['PYTHONCOMPILED'] = self.pythoncompiled

        self.printPackageInfo()

        from pkg_resources import EntryPoint
        import unittest
        loader_ep = EntryPoint.parse("x=" + self.test_loader)
        loader_class = loader_ep.load(require=False)

        from fipy.tools import numerix
        printoptions = numerix.get_printoptions()
        if "legacy" in printoptions:
            numerix.set_printoptions(legacy="1.13")

        try:
            unittest.main(None,
                          None, [unittest.__file__] + self.test_args,
                          testLoader=loader_class())
        except SystemExit, exitErr:
            # unittest.main(..., exit=...) not available until Python 2.7
            from fipy.tests.doctestPlus import report_skips
            report_skips()
            if self.timetests is not None:
                pass
            else:
                raise

        if "legacy" in printoptions:
示例#7
0
文件: test.py 项目: usnistgov/fipy
    def run_tests(self):
        import sys
        if self.Trilinos or self.trilinos or self.no_pysparse:
            try:
                ## The import scipy statement is added to allow
                ## the --Trilinos tests to run without throwing a
                ## segmentation fault. This is caused by weird
                ## behavior in scipy and PyTrilinos depending on
                ## the order in which modules are imported
                try:
                    import scipy
                except:
                    pass
                import PyTrilinos
            except ImportError as a:
                print("!!! Trilinos library is not installed", file=sys.stderr)
                return

        if self.pyamgx:
            try:
                ## Unregister the function pyamgx.finalize
                ## from atexit. This prevents
                ## pyamgx from printing an error message
                ## about memory leaks and a dump of leaked memory.
                ## The memory leaks happen because
                ## the tests do not use the pyamgx solvers
                ## "cleanly", i.e., they do not use the
                ## `with` statement.
                import pyamgx
                import atexit
                if hasattr(atexit, 'unregister'):
                    atexit.unregister(pyamgx.finalize)
                else:
                    atexit._exithandlers.remove(
                        (pyamgx.finalize, (), {}))
            except ImportError as e:
                print("!!! pyamgx package is not installed", file=sys.stederr)
                return

        if self.inline:
            try:
                import weave
            except ImportError as a:
                print("!!! weave library is not installed", file=sys.stderr)
                return

        if self.pythoncompiled is not None:
            import os
            os.environ['PYTHONCOMPILED'] = self.pythoncompiled

        self.printPackageInfo()

        from pkg_resources import EntryPoint
        import unittest
        loader_ep = EntryPoint.parse("x="+self.test_loader)
        loader_class = loader_ep.load(require=False)

        from fipy.tools import numerix
        printoptions = numerix.get_printoptions()
        if "legacy" in printoptions:
            numerix.set_printoptions(legacy="1.13")

        try:
            unittest.main(
                None, None, [unittest.__file__]+self.test_args,
                testLoader = loader_class()
                )
        except SystemExit as exitErr:
            # unittest.main(..., exit=...) not available until Python 2.7
            from fipy.tests.doctestPlus import report_skips
            report_skips()
            if self.timetests is not None:
                pass
            else:
                raise

        if "legacy" in printoptions:
            numerix.set_printoptions(legacy=printoptions["legacy"])

        if self.timetests is not None:
            from fipy.tests.doctestPlus import _DocTestTimes
            import numpy
            _DocTestTimes = numpy.rec.fromrecords(_DocTestTimes, formats='f8,S255', names='time,test')
            _DocTestTimes.sort(order=('time', 'test'))
            numpy.savetxt(self.timetests, _DocTestTimes[::-1], fmt="%8.4f\t%s")

        raise exitErr
示例#8
0
def testmod(m=None, name=None, globs=None, verbose=None,
            report=True, optionflags=0, extraglobs=None,
            raise_on_error=False, exclude_empty=False):
    """Test examples in the given module.  Return (#failures, #tests).

    Largely duplicated from :func:`doctest.testmod`, but using
    :class:`_SelectiveDocTestParser`.

    Test examples in docstrings in functions and classes reachable
    from module m (or the current module if m is not supplied), starting
    with m.__doc__.

    Also test examples reachable from dict m.__test__ if it exists and is
    not None.  m.__test__ maps names to functions, classes and strings;
    function and class docstrings are tested even if the name is private;
    strings are tested directly, as if they were docstrings.

    Return (#failures, #tests).

    See help(doctest) for an overview.

    Optional keyword arg "name" gives the name of the module; by default
    use m.__name__.

    Optional keyword arg "globs" gives a dict to be used as the globals
    when executing examples; by default, use m.__dict__.  A copy of this
    dict is actually used for each docstring, so that each docstring's
    examples start with a clean slate.

    Optional keyword arg "extraglobs" gives a dictionary that should be
    merged into the globals that are used to execute examples.  By
    default, no extra globals are used.  This is new in 2.4.

    Optional keyword arg "verbose" prints lots of stuff if true, prints
    only failures if false; by default, it's true iff "-v" is in sys.argv.

    Optional keyword arg "report" prints a summary at the end when true,
    else prints nothing at the end.  In verbose mode, the summary is
    detailed, else very brief (in fact, empty if all tests passed).

    Optional keyword arg "optionflags" or's together module constants,
    and defaults to 0.  This is new in 2.3.  Possible values (see the
    docs for details):

        DONT_ACCEPT_TRUE_FOR_1
        DONT_ACCEPT_BLANKLINE
        NORMALIZE_WHITESPACE
        ELLIPSIS
        SKIP
        IGNORE_EXCEPTION_DETAIL
        REPORT_UDIFF
        REPORT_CDIFF
        REPORT_NDIFF
        REPORT_ONLY_FIRST_FAILURE

    as well as FiPy's flags

        GMSH
        SCIPY
        TVTK
        SERIAL
        PARALLEL
        PROCESSOR_0
        PROCESSOR_0_OF_2
        PROCESSOR_1_OF_2
        PROCESSOR_0_OF_3
        PROCESSOR_1_OF_3
        PROCESSOR_2_OF_3

    Optional keyword arg "raise_on_error" raises an exception on the
    first unexpected exception or failure. This allows failures to be
    postmortem debugged.
    """
    # If no module was given, then use __main__.
    if m is None:
        # DWA - m will still be None if this wasn't invoked from the command
        # line, in which case the following TypeError is about as good an error
        # as we should expect
        m = sys.modules.get('__main__')

    # Check that we were actually given a module.
    if not inspect.ismodule(m):
        raise TypeError("testmod: module required; %r" % (m,))

    # If no name was given, then use the module's name.
    if name is None:
        name = m.__name__

    # Find, parse, and run all tests in the given module.
    finder = doctest.DocTestFinder(exclude_empty=exclude_empty,
                                   parser=_SelectiveDocTestParser())

    if raise_on_error:
        runner = doctest.DebugRunner(verbose=verbose, optionflags=optionflags)
    else:
        runner = doctest.DocTestRunner(verbose=verbose, optionflags=optionflags)

    from fipy.tools import numerix
    printoptions = numerix.get_printoptions()
    if "legacy" in printoptions:
        numerix.set_printoptions(legacy="1.13")

    for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
        runner.run(test)

    if report:
        runner.summarize()
        report_skips()

    results = doctest.TestResults(runner.failures, runner.tries)

    if "legacy" in printoptions:
        numerix.set_printoptions(legacy=printoptions["legacy"])

    return results