source: TI02-CSML/trunk/newparser/test.py @ 654

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/newparser/test.py@654
Revision 654, 3.2 KB checked in by domlowe, 14 years ago (diff)

Feature Member done. PointFeature? mostly supported, to do: rangeSet, parameter, coverageFunction

Line 
1"""Test for GML/CSML parsing code
2"""
3
4from cElementTree import *
5from Parser import *
6from xml.dom.minidom import parseString
7import elementtree.ElementTree as etree
8import sys
9
10
11#this is a fix to the  ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc.
12etree._namespace_map.update({
13    'http://www.opengis.net/om': 'om',  'http://www.opengis.net/gml': 'gml','http://ndg.nerc.ac.uk/csml' : 'csml', 'http://www.w3.org/1999/xlink':'xlink'})
14
15
16
17##############################################################################
18# ElementTree-based parser test
19##############################################################################
20# 1. Test parsing from CSML file
21tree = ElementTree(file='example.xml')
22dataset = Dataset()
23dataset.fromXML(tree.getroot())
24#csml = dataset.toXML(Element('Dataset'))
25csml = dataset.toXML()
26print parseString(tostring(csml)).toprettyxml()
27sys.exit() # stop here.
28
29##############################################################################
30#2. Test construction of objects from scratch
31
32# AW changes made to DL code:
33#  (NB: all these derive from the underlying UML model)
34#  * AbstractFileExtract.arraySize is an array []
35#  * Dataset.metaDataProperty is an array []
36#  * Omit empty attributes entirely
37#  * Dataset.arrayDescriptors is an array holding all file extract objects
38
39#MetaDataProperty Object
40md = MetaDataProperty()
41setattr(md, 'href', 'http://ndg.nerc.ac.uk/Metadata/home/users/domlowe/CSML/demodata')
42
43#An empty list to hold a collection of NASAAmesExtracts:
44nalist=[]
45
46#Create a NASAAmesExtract
47na1 = NASAAmesExtract()
48#set attributes:
49setattr(na1, 'id', 'naextract_one')
50setattr(na1, 'variableName', 'temp')
51setattr(na1, 'index', '1')
52setattr(na1, 'fileName', '/blah/testfile.na')
53setattr(na1, 'arraySize', [50])
54setattr(na1, 'uom', 'celsius')
55#setattr(na1, 'numericType', None)
56#setattr(na1, 'numericTransform', None)
57#setattr(na1,'regExpTransform',None)
58#append NASAAmesExtract to list
59nalist.append(na1)
60
61#Create a second NASAAmesExtract
62na2 = NASAAmesExtract()
63#set attributes:
64setattr(na2, 'id', 'naextract_two')
65setattr(na2, 'variableName', 'pressure')
66setattr(na2, 'index', '1')
67setattr(na2, 'fileName', '/blah/testfile2.na')
68setattr(na2, 'arraySize', [50])
69setattr(na2, 'uom', 'mb')
70#setattr(na2, 'numericType', None)
71#setattr(na2, 'numericTransform', None)
72#setattr(na2,'regExpTransform',None)
73#append second NASAAmesExtract to list
74nalist.append(na2)
75
76#An empty list to hold a collection of NetCDFExtracts:
77nclist=[]
78
79#Create a NetCDFExtract
80nc1 = NetCDFExtract()
81#set attributes:
82setattr(nc1, 'id', 'ncextract_one')
83setattr(nc1, 'variableName', 'temp2')
84setattr(nc1, 'fileName', '/blah/testfile.nc')
85setattr(nc1, 'arraySize', [100])
86setattr(nc1, 'uom', 'celsius')
87#setattr(nc1, 'numericType', None)
88#setattr(nc1, 'numericTransform', None)
89#setattr(nc1,'regExpTransform',None)
90#append NetCDFExtract to list
91nclist.append(nc1)
92
93
94
95#Create an Empty Dataset
96ds = Dataset()
97#Set objects as attributes of dataset
98setattr(ds, 'metaDataProperty', [md])
99setattr(ds, 'arrayDescriptors', nalist+nclist)
100
101
102csml = ds.toXML()
103print parseString(tostring(csml)).toprettyxml()
Note: See TracBrowser for help on using the repository browser.