/[escript]/trunk/downunder/test/python/run_domainbuilder.py
ViewVC logotype

Contents of /trunk/downunder/test/python/run_domainbuilder.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4213 - (show annotations)
Tue Feb 19 01:16:29 2013 UTC (7 years, 4 months ago) by caltinay
File MIME type: text/x-python
File size: 2649 byte(s)
Some cleanup and more consistent logging.

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2013 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2003-2013 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 import logging
24 import numpy as np
25 import os
26 import sys
27 import unittest
28 from esys.escript import inf,sup,saveDataCSV,getMPISizeWorld
29 from esys.downunder.datasources import *
30 from esys.downunder.domainbuilder import DomainBuilder
31
32 # this is mainly to avoid warning messages
33 logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
34
35 try:
36 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
37 except KeyError:
38 TEST_DATA_ROOT='ref_data'
39
40 try:
41 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
42 except KeyError:
43 WORKDIR='.'
44
45
46 NC_DATA1 = os.path.join(TEST_DATA_ROOT, 'zone51.nc')
47 NC_DATA2 = os.path.join(TEST_DATA_ROOT, 'zone52.nc')
48
49 class TestDomainBuilderWithNetCdf(unittest.TestCase):
50 def test_add_garbage(self):
51 db=DomainBuilder()
52 self.assertRaises(TypeError, db.addSource, 42)
53
54 def test_mixing_utm_zones(self):
55 source1 = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
56 source2 = NetCdfData(DataSource.GRAVITY, NC_DATA2, scale_factor=1.)
57 domainbuilder=DomainBuilder()
58 domainbuilder.addSource(source1)
59 self.assertRaises(ValueError, domainbuilder.addSource, source2)
60
61 def test_add_source_after_domain_built(self):
62 db=DomainBuilder()
63 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
64 db.addSource(source1a)
65 _=db.getDomain()
66 source1b = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=2.)
67 self.assertRaises(Exception, db.addSource, source1b)
68
69 if __name__ == "__main__":
70 suite = unittest.TestSuite()
71 if 'NetCdfData' in dir():
72 suite.addTest(unittest.makeSuite(TestDomainBuilderWithNetCdf))
73 else:
74 print("Skipping tests that require netCDF.")
75 s=unittest.TextTestRunner(verbosity=2).run(suite)
76 if not s.wasSuccessful(): sys.exit(1)
77

  ViewVC Help
Powered by ViewVC 1.1.26