Salome HOME
aa17d285a889a9d44b42e01a9b7cbe1bf79e6446
[modules/med.git] / src / MEDOP / tui / xmedpy / properties.py
1 #!/usr/bin/env python
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 # This file defines some properties for test purposes
23
24 import os
25
26 try:
27     MED_ROOT_DIR=os.environ["MED_ROOT_DIR"]
28 except KeyError, e:
29     raise RuntimeError("MED_ROOT_DIR should be defined to load the test data")
30
31 RESDIR=os.path.join(MED_ROOT_DIR,"share","salome","resources","med","medop_testfiles")
32
33 def testdata_01():
34     testFileName = "testfield.med"
35     testMeshName = "Mesh"
36     testFieldName= "testfield1"
37     testFieldIt  = -1
38     testFieldDt  = -1
39     testTypeOfField = 0 # On cells
40     return testFileName, testMeshName, testFieldName, testTypeOfField, testFieldIt, testFieldDt
41
42 def testdata_02():
43     testFileName = "smallmesh_varfield.med"
44     testMeshName = "My2DMesh"
45     testFieldName= "testfield2"
46     testFieldIt  = 1
47     testFieldDt  = 1
48     testTypeOfField = 1 # On nodes
49     return testFileName, testMeshName, testFieldName, testTypeOfField, testFieldIt, testFieldDt
50
51 def testdata_03():
52     testFileName = "fieldlena.med"
53     testMeshName = "lenamesh"
54     testFieldName= "lenafield"
55     testFieldIt  = 3
56     testFieldDt  = 0
57     testTypeOfField = 0 # On cells
58     return testFileName, testMeshName, testFieldName, testTypeOfField, testFieldIt, testFieldDt
59
60 # Default values
61 testdata=testdata_02
62 testFileName, testMeshName, testFieldName, testTypeOfField, testFieldIt, testFieldDt = testdata()
63 testFilePath = os.path.join(RESDIR,testFileName)
64
65 # Setup test values
66 def setup(testdata=testdata_02):
67     global testFileName, testMeshName, testFieldName
68     global testFieldIt, testFieldDt, testFilePath, testTypeOfField
69     testFileName, testMeshName, testFieldName, testTypeOfField, testFieldIt, testFieldDt = testdata()
70     testFilePath = os.path.join(RESDIR,testFileName)
71
72 def display():
73     """
74     Displays the properties values defined in this script.
75     """
76     print 60*"=" + " Properties values - START"
77     print "MED_ROOT_DIR = ",MED_ROOT_DIR
78     print "RESDIR       = ",RESDIR
79     print "testFileName = ",testFileName
80     print "testFilePath = ",testFilePath
81     print 60*"=" + " Properties values - END"
82
83 #display()
84
85 def getFilePath(filename):
86     """
87     Returns the absolute path for a given file base name. The base
88     name must match with a file contained in the test files directory.
89     """
90     filepath = os.path.join(RESDIR,filename)
91     if not os.path.exists(filepath):
92         raise RuntimeError("The file %s does not exists"%filepath)
93     return filepath