source: trunk/lang/python/Rappture/unittest_library.py @ 4346

Last change on this file since 4346 was 3177, checked in by mmc, 9 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 22.0 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: library unit test - provides tests for Rappture Library
3#
4#  Unit tests for the python bindings of Rappture's Library module
5# ======================================================================
6#  AUTHOR:  Derrick S. Kearney, Purdue University
7#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
8#
9#  See the file "license.terms" for information on usage and
10#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11# ======================================================================
12
13import unittest
14import Rappture
15
16class CopyTests(unittest.TestCase):
17
18    def setUp(self):
19        self.lib  = Rappture.library("test.xml")
20        self.lib2 = Rappture.library("test.xml")
21        # self.lib3 = Rappture.library()
22
23    def tearDown(self):
24        return
25
26    # def testArguments_UninitializedLib(self):
27    #     print self.lib3.xml()
28    #     self.assertRaises(RuntimeError,self.lib.copy,"input","output",self.lib3)
29
30    def testArguments_TooMaryArgs(self):
31        self.assertRaises(TypeError,self.lib.copy,1,2,3,4)
32
33    def testArguments_NotEnoughArgs(self):
34        self.assertRaises(TypeError,self.lib.copy,1)
35
36    def testArguments_ArgsWrongType2(self):
37        self.assertRaises(TypeError,self.lib.copy,1,2)
38
39    def testArguments_ArgsWrongType3(self):
40        self.assertRaises(RuntimeError,self.lib.copy,"input","output",3)
41
42    def testArguments_ToPathRootCopyElement(self):
43        self.lib.copy("","input")
44        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
45<run>
46    <string id="test">
47        <current>&lt;sdfsfs&gt;sdfs</current>
48    </string>
49    <time>Thu Mar 15 02:03:39 2007 EDT</time>
50    <image>
51        <current>@@RP-ENC:b64
52R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
53ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
54RQEAOw==</current>
55    </image>
56</run>
57''')
58
59    def testArguments_ToPathRootCopyContents(self):
60        self.lib.copy("","input.time")
61        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
62<run>Thu Mar 15 02:03:39 2007 EDT</run>
63''')
64
65    def testArguments_ToPathElementCopyContents(self):
66        self.lib.copy("output","input.time")
67        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
68<run>
69    <tool>
70        <repository>
71            <rappture>
72                <date>$Date: 2007-03-08 15:27:02 -0500 (Thu, 08 Mar 2007) $</date>
73                <revision>$Rev: 613 $</revision>
74                <url>$URL: https://kearneyd@repo.nanohub.org/svn/rappture/trunk/src/core/RpLibrary.cc $</url>
75            </rappture>
76        </repository>
77    </tool>
78    <input>
79        <string id="test">
80            <current>&lt;sdfsfs&gt;sdfs</current>
81        </string>
82        <time>Thu Mar 15 02:03:39 2007 EDT</time>
83        <image>
84            <current>@@RP-ENC:b64
85R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
86ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
87RQEAOw==</current>
88        </image>
89    </input>
90    <output>Thu Mar 15 02:03:39 2007 EDT</output>
91</run>
92''')
93
94    def testArguments_ToPathElementCopyElementsFromLib2(self):
95        self.lib.copy("lib2input","input",self.lib2)
96        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
97<run>
98    <tool>
99        <repository>
100            <rappture>
101                <date>$Date: 2007-03-08 15:27:02 -0500 (Thu, 08 Mar 2007) $</date>
102                <revision>$Rev: 613 $</revision>
103                <url>$URL: https://kearneyd@repo.nanohub.org/svn/rappture/trunk/src/core/RpLibrary.cc $</url>
104            </rappture>
105        </repository>
106    </tool>
107    <input>
108        <string id="test">
109            <current>&lt;sdfsfs&gt;sdfs</current>
110        </string>
111        <time>Thu Mar 15 02:03:39 2007 EDT</time>
112        <image>
113            <current>@@RP-ENC:b64
114R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
115ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
116RQEAOw==</current>
117        </image>
118    </input>
119    <lib2input>
120        <string id="test">
121            <current>&lt;sdfsfs&gt;sdfs</current>
122        </string>
123        <time>Thu Mar 15 02:03:39 2007 EDT</time>
124        <image>
125            <current>@@RP-ENC:b64
126R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
127ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
128RQEAOw==</current>
129        </image>
130    </lib2input>
131</run>
132''')
133
134#    def testToPathRootCopyElementsFromElementObj(self):
135#        e = self.lib.element("input.string",as="object")
136#        self.lib.copy("","",e)
137#        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
138#<run>
139#    <current>&lt;sdfsfs&gt;sdfs</current>
140#</run>
141#''')
142
143#    def testToPathRootIdCopyElementsFromElementObj(self):
144#        e = self.lib.element("input.string",as="object")
145#        self.lib.copy("(qqq)","",e)
146#        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
147#<run>
148#    <current>&lt;sdfsfs&gt;sdfs</current>
149#</run>
150#''')
151
152    def testToPathId(self):
153        e = self.lib.element("input.string",as="object")
154        self.lib.copy("estring(qqq)","",e)
155        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
156<run>
157    <tool>
158        <repository>
159            <rappture>
160                <date>$Date: 2007-03-08 15:27:02 -0500 (Thu, 08 Mar 2007) $</date>
161                <revision>$Rev: 613 $</revision>
162                <url>$URL: https://kearneyd@repo.nanohub.org/svn/rappture/trunk/src/core/RpLibrary.cc $</url>
163            </rappture>
164        </repository>
165    </tool>
166    <input>
167        <string id="test">
168            <current>&lt;sdfsfs&gt;sdfs</current>
169        </string>
170        <time>Thu Mar 15 02:03:39 2007 EDT</time>
171        <image>
172            <current>@@RP-ENC:b64
173R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
174ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
175RQEAOw==</current>
176        </image>
177    </input>
178    <estring id="qqq">
179        <current>&lt;sdfsfs&gt;sdfs</current>
180    </estring>
181</run>
182''')
183
184    def testToPathNoIdFromPathId(self):
185        e = self.lib.element("input.string",as="object")
186        self.lib.copy("estring","",e)
187        self.assertEqual(self.lib.xml(),'''<?xml version="1.0"?>
188<run>
189    <tool>
190        <repository>
191            <rappture>
192                <date>$Date: 2007-03-08 15:27:02 -0500 (Thu, 08 Mar 2007) $</date>
193                <revision>$Rev: 613 $</revision>
194                <url>$URL: https://kearneyd@repo.nanohub.org/svn/rappture/trunk/src/core/RpLibrary.cc $</url>
195            </rappture>
196        </repository>
197    </tool>
198    <input>
199        <string id="test">
200            <current>&lt;sdfsfs&gt;sdfs</current>
201        </string>
202        <time>Thu Mar 15 02:03:39 2007 EDT</time>
203        <image>
204            <current>@@RP-ENC:b64
205R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
206ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
207RQEAOw==</current>
208        </image>
209    </input>
210    <estring>
211        <current>&lt;sdfsfs&gt;sdfs</current>
212    </estring>
213</run>
214''')
215
216class ElementTests(unittest.TestCase):
217
218    def setUp(self):
219        self.lib = Rappture.library("test.xml")
220
221    def tearDown(self):
222        return
223
224    def testArguments_TooMaryArgs(self):
225        self.assertRaises(TypeError,self.lib.element,1,2,3,4)
226
227    def testArguments_ArgsWrongType2(self):
228        self.assertRaises(TypeError,self.lib.element,1,2)
229
230    def testArguments_NoArgs(self):
231        ele = self.lib.element()
232        self.assertEqual(type(ele),type(self.lib))
233
234    def testArguments_PathArg(self):
235        ele = self.lib.element("tool.repository")
236        self.assertEqual(type(ele),type(self.lib))
237
238    def testArguments_TwoArgs(self):
239        ele = self.lib.element("input.string","component")
240        self.assertEqual(ele,"string(test)")
241
242    def testArguments_TwoKeywordArgs(self):
243        ele = self.lib.element(path="input.string",as="path")
244        self.assertEqual(ele,"input.string(test)")
245
246    def testArguments_AsKeywordArgs(self):
247        ele = self.lib.element("input.string",as="type")
248        self.assertEqual(ele,"string")
249
250    def testArguments_AsId(self):
251        ele = self.lib.element(path="input.string",as="id")
252        self.assertEqual(ele,"test")
253
254    def testArguments_UnrecognizedAs(self):
255        self.assertRaises(ValueError,self.lib.element,"input.string","blahh")
256
257class GetTests(unittest.TestCase):
258
259    def setUp(self):
260        self.lib = Rappture.library("test.xml")
261
262    def tearDown(self):
263        return
264
265    def testArguments_TooMaryArgs(self):
266        self.assertRaises(TypeError,self.lib.get,1,2,3,4)
267
268    def testArguments_ArgsWrongType2(self):
269        self.assertRaises(TypeError,self.lib.get,1,2)
270
271    def testArgumentBlank(self):
272        self.assertEqual(self.lib.get(),"")
273
274    def testArgumentPath(self):
275        self.assertEqual(self.lib.get("input.time"),"Thu Mar 15 02:03:39 2007 EDT")
276
277    def testArgumentDecode(self):
278        # grabs the decoded binary data
279        self.assertEqual(self.lib.get("input.image.current"),"\x47\x49\x46\x38\x39\x61\x1a\x00\x12\x00\xa1\x01\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x21\xfe\x15\x43\x72\x65\x61\x74\x65\x64\x20\x77\x69\x74\x68\x20\x54\x68\x65\x20\x47\x49\x4d\x50\x00\x21\xf9\x04\x01\x0a\x00\x01\x00\x2c\x00\x00\x00\x00\x1a\x00\x12\x00\x00\x02\x2e\x8c\x8f\xa9\xcb\xed\x0f\xc0\x91\x8f\xc5\x59\xad\x8c\x3c\x87\xfb\x51\x9f\x67\x80\xe0\x48\x9a\xa2\xc6\xb5\xaa\xdb\x42\xd4\x49\x96\xf3\x5a\xab\xb5\xb6\x2f\x74\x6f\x03\x0a\x87\x44\x45\x01\x00\x3b")
280
281    def testArgumentDecodeYes(self):
282        # grabs the decoded binary data
283        self.assertEqual(self.lib.get("input.image.current", decode="yes"),"\x47\x49\x46\x38\x39\x61\x1a\x00\x12\x00\xa1\x01\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x21\xfe\x15\x43\x72\x65\x61\x74\x65\x64\x20\x77\x69\x74\x68\x20\x54\x68\x65\x20\x47\x49\x4d\x50\x00\x21\xf9\x04\x01\x0a\x00\x01\x00\x2c\x00\x00\x00\x00\x1a\x00\x12\x00\x00\x02\x2e\x8c\x8f\xa9\xcb\xed\x0f\xc0\x91\x8f\xc5\x59\xad\x8c\x3c\x87\xfb\x51\x9f\x67\x80\xe0\x48\x9a\xa2\xc6\xb5\xaa\xdb\x42\xd4\x49\x96\xf3\x5a\xab\xb5\xb6\x2f\x74\x6f\x03\x0a\x87\x44\x45\x01\x00\x3b")
284
285    def testArgumentDecodeTrue(self):
286        # grabs the decoded binary data
287        self.assertEqual(self.lib.get("input.image.current", decode="true"),"\x47\x49\x46\x38\x39\x61\x1a\x00\x12\x00\xa1\x01\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x21\xfe\x15\x43\x72\x65\x61\x74\x65\x64\x20\x77\x69\x74\x68\x20\x54\x68\x65\x20\x47\x49\x4d\x50\x00\x21\xf9\x04\x01\x0a\x00\x01\x00\x2c\x00\x00\x00\x00\x1a\x00\x12\x00\x00\x02\x2e\x8c\x8f\xa9\xcb\xed\x0f\xc0\x91\x8f\xc5\x59\xad\x8c\x3c\x87\xfb\x51\x9f\x67\x80\xe0\x48\x9a\xa2\xc6\xb5\xaa\xdb\x42\xd4\x49\x96\xf3\x5a\xab\xb5\xb6\x2f\x74\x6f\x03\x0a\x87\x44\x45\x01\x00\x3b")
288
289    def testArgumentDecodeOn(self):
290        # grabs the decoded binary data
291        self.assertEqual(self.lib.get("input.image.current", decode="on"),"\x47\x49\x46\x38\x39\x61\x1a\x00\x12\x00\xa1\x01\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x21\xfe\x15\x43\x72\x65\x61\x74\x65\x64\x20\x77\x69\x74\x68\x20\x54\x68\x65\x20\x47\x49\x4d\x50\x00\x21\xf9\x04\x01\x0a\x00\x01\x00\x2c\x00\x00\x00\x00\x1a\x00\x12\x00\x00\x02\x2e\x8c\x8f\xa9\xcb\xed\x0f\xc0\x91\x8f\xc5\x59\xad\x8c\x3c\x87\xfb\x51\x9f\x67\x80\xe0\x48\x9a\xa2\xc6\xb5\xaa\xdb\x42\xd4\x49\x96\xf3\x5a\xab\xb5\xb6\x2f\x74\x6f\x03\x0a\x87\x44\x45\x01\x00\x3b")
292
293    def testArgumentDecode1Str(self):
294        # grabs the decoded binary data
295        self.assertEqual(self.lib.get("input.image.current", decode="1"),"\x47\x49\x46\x38\x39\x61\x1a\x00\x12\x00\xa1\x01\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x21\xfe\x15\x43\x72\x65\x61\x74\x65\x64\x20\x77\x69\x74\x68\x20\x54\x68\x65\x20\x47\x49\x4d\x50\x00\x21\xf9\x04\x01\x0a\x00\x01\x00\x2c\x00\x00\x00\x00\x1a\x00\x12\x00\x00\x02\x2e\x8c\x8f\xa9\xcb\xed\x0f\xc0\x91\x8f\xc5\x59\xad\x8c\x3c\x87\xfb\x51\x9f\x67\x80\xe0\x48\x9a\xa2\xc6\xb5\xaa\xdb\x42\xd4\x49\x96\xf3\x5a\xab\xb5\xb6\x2f\x74\x6f\x03\x0a\x87\x44\x45\x01\x00\x3b")
296
297    def testArgumentDecode1Int(self):
298        # grabs the decoded binary data
299        self.assertEqual(self.lib.get("input.image.current", decode=1),"\x47\x49\x46\x38\x39\x61\x1a\x00\x12\x00\xa1\x01\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x21\xfe\x15\x43\x72\x65\x61\x74\x65\x64\x20\x77\x69\x74\x68\x20\x54\x68\x65\x20\x47\x49\x4d\x50\x00\x21\xf9\x04\x01\x0a\x00\x01\x00\x2c\x00\x00\x00\x00\x1a\x00\x12\x00\x00\x02\x2e\x8c\x8f\xa9\xcb\xed\x0f\xc0\x91\x8f\xc5\x59\xad\x8c\x3c\x87\xfb\x51\x9f\x67\x80\xe0\x48\x9a\xa2\xc6\xb5\xaa\xdb\x42\xd4\x49\x96\xf3\x5a\xab\xb5\xb6\x2f\x74\x6f\x03\x0a\x87\x44\x45\x01\x00\x3b")
300
301    def testArgumentNoDecodeNo(self):
302        # grabs the undecoded data
303        self.assertEqual(self.lib.get("input.image.current", decode="no"),"""@@RP-ENC:b64
304R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
305ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
306RQEAOw==""")
307
308    def testArgumentNoDecodeFalse(self):
309        # grabs the undecoded data
310        self.assertEqual(self.lib.get("input.image.current", decode="FalSe"),"""@@RP-ENC:b64
311R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
312ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
313RQEAOw==""")
314
315    def testArgumentNoDecodeOff(self):
316        # grabs the undecoded data
317        self.assertEqual(self.lib.get("input.image.current", decode="OFF"),"""@@RP-ENC:b64
318R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
319ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
320RQEAOw==""")
321
322    def testArgumentNoDecode0Str(self):
323        # grabs the undecoded data
324        self.assertEqual(self.lib.get("input.image.current", decode="0"),"""@@RP-ENC:b64
325R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
326ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
327RQEAOw==""")
328
329    def testArgumentNoDecode0Int(self):
330        # grabs the undecoded data
331        self.assertEqual(self.lib.get("input.image.current", decode=0),"""@@RP-ENC:b64
332R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
333ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
334RQEAOw==""")
335
336    def testArgumentDecodeError(self):
337        self.assertRaises(ValueError,self.lib.get,"input.image.current","blahh")
338
339#    def testGetEncodedData(self):
340#
341#        self.assertEqual()
342
343class PutTests(unittest.TestCase):
344
345    def setUp(self):
346        self.lib = Rappture.library("test.xml")
347
348    def tearDown(self):
349        return
350
351    def testArguments_TooMaryArgs(self):
352        self.assertRaises(TypeError,self.lib.put,1,2,3,4,5,6,7)
353
354    def testArguments_NotEnoughArgs(self):
355        self.assertRaises(TypeError,self.lib.put,1)
356
357    def testArguments_ArgsWrongType2(self):
358        self.assertRaises(TypeError,self.lib.put,1,2)
359
360    def testArguments_ValueIsNone(self):
361        self.lib.put("input.none",None)
362        self.assertEqual(self.lib.get("input.none"),"None")
363
364    def testArgumentAppendValError(self):
365        self.assertRaises(ValueError,self.lib.put,"output.blah","val","","blahhhh")
366
367    def testArgumentCompressValError(self):
368        self.assertRaises(ValueError,self.lib.put,"output.blah","vl","","no","","blh")
369
370    def testArgumentBlank(self):
371        self.assertRaises(TypeError,self.lib.put,None)
372
373    def testArgumentPathValue(self):
374        self.lib.put("output.string","43eV")
375        self.assertEqual(self.lib.get("output.string"),"43eV")
376
377    def testArgumentPathValueIdAppendTypeCompress(self):
378        self.lib.put("output.string","43eV","id",0,"string",0)
379        self.assertEqual(self.lib.get("output.string"),"43eV")
380
381    def testArgumentCheckId(self):
382        # this test checks that the id argument is no longer in use
383        self.lib.put("output.string","43eV","id",0,"string",0)
384        self.assertEqual(self.lib.get("output.string(id)"),"")
385
386    def testArgumentAllNamedArgs(self):
387        self.lib.put(path="output.string",value="43eV",id="id",append=0,type="string",compress=0)
388        self.assertEqual(self.lib.get("output.string"),"43eV")
389
390    def testArgumentCheckAppend(self):
391        self.lib.put("input.string.current","43eV",append=1)
392        self.assertEqual(self.lib.get("input.string.current"),"&lt;sdfsfs&gt;sdfs43eV")
393
394    def testArgumentCheckAppendYes(self):
395        self.lib.put("input.string.current","43eV",append="yes")
396        self.assertEqual(self.lib.get("input.string.current"),"&lt;sdfsfs&gt;sdfs43eV")
397
398    def testArgumentCheckTypeStringCompressYes(self):
399        self.lib.put("input.string.current","43eV",type="string",compress="yes")
400        self.assertEqual(self.lib.get("input.string.current",decode=False),\
401"""@@RP-ENC:zb64
402H4sIAAAAAAAAAzMxTg0DAACAouIEAAAA
403""")
404
405    def testArgumentCheckTypeFile(self):
406        self.lib.put("output.file","test.xml",type="file")
407        self.assertEqual(self.lib.get("output.file"),"""<?xml version="1.0"?>
408<run>
409    <tool>
410        <repository>
411            <rappture>
412                <date>$Date: 2007-03-08 15:27:02 -0500 (Thu, 08 Mar 2007) $</date>
413                <revision>$Rev: 613 $</revision>
414                <url>$URL: https://kearneyd@repo.nanohub.org/svn/rappture/trunk/src/core/RpLibrary.cc $</url>
415            </rappture>
416        </repository>
417    </tool>
418    <input>
419        <string id="test">
420            <current>&lt;sdfsfs&gt;sdfs</current>
421        </string>
422        <time>Thu Mar 15 02:03:39 2007 EDT</time>
423        <image>
424            <current>@@RP-ENC:b64
425R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
426ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
427RQEAOw==</current>
428        </image>
429    </input>
430</run>
431""")
432
433    def testArgumentCheckTypeFileCompressTrue(self):
434        self.lib.put("output.file","test.xml",type="file",compress=True)
435        self.assertEqual(self.lib.get("output.file"),"""<?xml version="1.0"?>
436<run>
437    <tool>
438        <repository>
439            <rappture>
440                <date>$Date: 2007-03-08 15:27:02 -0500 (Thu, 08 Mar 2007) $</date>
441                <revision>$Rev: 613 $</revision>
442                <url>$URL: https://kearneyd@repo.nanohub.org/svn/rappture/trunk/src/core/RpLibrary.cc $</url>
443            </rappture>
444        </repository>
445    </tool>
446    <input>
447        <string id="test">
448            <current><sdfsfs>sdfs</current>
449        </string>
450        <time>Thu Mar 15 02:03:39 2007 EDT</time>
451        <image>
452            <current>@@RP-ENC:b64
453R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
454ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
455RQEAOw==</current>
456        </image>
457    </input>
458</run>
459""")
460
461    def testArgumentCheckTypeFileCompressTrueNoDecode(self):
462        self.lib.put("output.file","test.xml",type="file",compress=True)
463        self.assertEqual(self.lib.get("output.file",decode=False),"""@@RP-ENC:zb64
464H4sIAAAAAAAAA3VTXW/aMBR951dYCFWbOrATSptlIcUkKZXGKGTNUHkziZtkDXGwnbD8++VD
465HTC2+2D5nnvP/TiWjftfuwQUlIuYpeOuMkDde7Nj8Dw1O6AyQzKWtNfG5TRjIpaMl0ewDZAs
466kzmn53ATCoikZs+uTh2oCN310bCPNKCMdPVORyrooxFC4MNzlH8CFf6N8CbtI+gZsOFeluS0
467iOuJzZ5LCx3cKsM6+Q96Sch5YvY8d66DSMpM6BC+UcJTWgaTeqVBSlIW5dsB4yEURQrf14Gy
468kuINCu5Dn1Wum83jLSe8HPh+3bKuey4EvFSinuxcNgMedTXiNMvlSbaQPE5DEAfjrqRCdv9q
4694Oec01SaV4n8IoJX8SquwvZmwPfYSeu22gki4x01K7EboZURQKqOhvrwcyM6cOznarg65ciI
470dySk/5liMnGXfWdh6dvbm46LktmTnUSzEH/HX50prm0Jj1Y+Xj94i3KzfkCb9SoM1AQRa+qR
471mRdW3IWHcXS9Wk2tEE872Do0/KYYxtaclcu9X0hbs9yf2o8NfzloEZRuqlJ848SECaLspbQU
472Z7fWlD2X25cimGm2xQKn464c/HQYj/8p0cl+ldO+RvVm9R/4DWcyEdUgAwAA
473""")
474
475    def testArgumentCheckTypeError(self):
476        self.assertRaises(ValueError,self.lib.put,"output.file","vl","","","type","")
477
478    def testPutObject(self):
479        e = self.lib.element("input.string",as="object")
480        self.lib.put("output.estring(qqq)",e)
481        self.assertEqual(self.lib.get("output.estring(qqq).current"),'<sdfsfs>sdfs')
482
483class XmlTests(unittest.TestCase):
484
485    def setUp(self):
486        self.lib = Rappture.library("test.xml")
487
488    def tearDown(self):
489        return
490
491    def testArguments_NoArgs(self):
492        xml = self.lib.xml()
493        self.assertEqual(xml,'''<?xml version="1.0"?>
494<run>
495    <tool>
496        <repository>
497            <rappture>
498                <date>$Date: 2007-03-08 15:27:02 -0500 (Thu, 08 Mar 2007) $</date>
499                <revision>$Rev: 613 $</revision>
500                <url>$URL: https://kearneyd@repo.nanohub.org/svn/rappture/trunk/src/core/RpLibrary.cc $</url>
501            </rappture>
502        </repository>
503    </tool>
504    <input>
505        <string id="test">
506            <current>&lt;sdfsfs&gt;sdfs</current>
507        </string>
508        <time>Thu Mar 15 02:03:39 2007 EDT</time>
509        <image>
510            <current>@@RP-ENC:b64
511R0lGODlhGgASAKEBAAAAAP///////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAB
512ACwAAAAAGgASAAACLoyPqcvtD8CRj8VZrYw8h/tRn2eA4Eiaosa1qttC1EmW81qrtbYvdG8DCodE
513RQEAOw==</current>
514        </image>
515    </input>
516</run>
517''')
518
519    def testArguments_Args(self):
520        self.assertRaises(TypeError,self.lib.xml,"arg1")
521
522class ResultTests(unittest.TestCase):
523
524    class redirectedOutput:
525        # this class doesn't work yet
526        # the stdout from the c++ result function is not
527        # sent through python's sys.stdout
528        def write(self,text):
529            import re
530            pattern = re.compile('run\d+\.xml')
531            match = pattern.search(text)
532            if not match == None:
533                checkFile(match.group())
534        def checkFile(filename):
535            lib2 = Rappture.library(filename)
536            self.assertEqual(self.lib.xml(),lib2.xml())
537
538    def setUp(self):
539        self.lib = Rappture.library("test.xml")
540
541    def tearDown(self):
542        return
543
544# tests commented out because i dont like to keep deleting the files they create
545#    def testArguments_NoArgs(self):
546#        import sys
547#        sys.stdout = self.redirectedOutput()
548#        self.lib.result()
549#
550#    def testArguments_ValidStatusArg(self):
551#        import sys
552#        sys.stdout = self.redirectedOutput()
553#        self.lib.result(status=0)
554
555    def testArguments_InvalidStatusArg(self):
556        self.assertRaises(TypeError,self.lib.result,"0")
557
558if __name__ == '__main__':
559    unittest.main()
Note: See TracBrowser for help on using the repository browser.