← Back to team overview

dolfin team mailing list archive

Re: test

 

Joachim B Haga <jobh@xxxxxxxxxxxx> writes:

> Anders Logg <logg@xxxxxxxxx> writes:
>
>> On Thu, Apr 03, 2008 at 07:48:45PM +0200, Ilmar Wilbers wrote:
>>> Any suggestions on how to use the demos as tests? We need to remove the 
>>  
>> Don't know. Ola?
>
> It would be fairly easy to do something like the following in plot.py
> (untested).  Could of course be extended to actually make 'plot' save
> argument to a File, and compare for regression testing.

Assuming lack of response is due to silent approval, I made it into a patch
(attached). To run without plotting, set the environment variable DOLFIN_NOPLOT
before execution.

-j.

# HG changeset patch
# User "Joachim B Haga <jobh@xxxxxxxxx>"
# Date 1207331117 -7200
# Node ID fda8b41d190ba6d54e39f929141a861b23321737
# Parent  ba94e1c3d30c9b15c12fef28a164ce6a18754cb9
Make plot() noninteractive if DOLFIN_NOPLOT is set.

This is useful in automated testing.

diff --git a/site-packages/dolfin/plot.py b/site-packages/dolfin/plot.py
--- a/site-packages/dolfin/plot.py
+++ b/site-packages/dolfin/plot.py
@@ -1,15 +1,29 @@ try:
-try:
-    from viper.viper_dolfin import Viper, plot, update, interactive, save_plot, figure
-except:
-    def figure(*args):
-        raise RuntimeError, "Unable to plot (Viper plotter not available)"
-    def plot(*args):
-        raise RuntimeError, "Unable to plot (Viper plotter not available)"
+import os
 
-    class Plotter:
-        def __getattr__(self, name):
+__all__ = ['Viper', 'plot', 'update', 'interactive', 'save_plot', 'figure']
 
-            def method(*args, **kwargs):
-                raise RuntimeError, "Unable to plot (Viper plotter not available)"
+if os.environ.has_key('DOLFIN_NOPLOT'):
+    from dolfin import File
 
-            return method
+    def ignore(*args, **kwargs):
+        pass
+    for x in __all__:
+        exec('%s = ignore' % x)
+
+    # Override some functions, to save plot data for regression testing
+    n=0
+    def plot(u, *args, **kwargs):
+        global n
+        n += 1
+        file = File('plot-output-%d.pvd' % n)
+        file << u
+
+else:
+    try:
+        for x in __all__:
+            exec ('from viper.viper_dolfin import %s' % x)
+    except:
+        def no_viper(*args, **kwargs):
+            raise RuntimeError, "Unable to plot (Viper plotter not available)"
+        for x in __all__:
+            exec('%s = no_viper' % x)

Follow ups

References