Skip to content

Commit fe0837b

Browse files
author
Daniel Kinzler
committed
ported test cases for meta-vars to python
git-svn-id: https://svn.toolserver.org/svnroot/daniel/duesenstuff/trunk/gpClient@571 9f2c43bc-b3c0-43f4-b155-41619b16f219
1 parent db5bc40 commit fe0837b

File tree

3 files changed

+108
-25
lines changed

3 files changed

+108
-25
lines changed

php/test/gpCore.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function testSetMeta() { #TODO: port to python
135135
}
136136

137137
try {
138-
$ok = $this->gp->try_set_meta("x y", 1234);
138+
$this->gp->set_meta("x y", 1234);
139139
$this->fail( "exception expected" );
140140
} catch ( gpException $ex ) {
141141
// ok

python/gp/client.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,8 @@ def __init__( self, transport=None, graphname = None ):
11261126
self.debug = False
11271127
"""Debug mode enables lots of output to stdout."""
11281128
self.graphname = graphname #TODO: port this to PHP
1129+
1130+
self._protocol_version = None
11291131

11301132
def connect(self):
11311133
""" Connect to the peer.
@@ -1293,9 +1295,9 @@ def setDebug(self, debug): #OK
12931295
def getProtocolVersion(self):
12941296
"""Return the protocol version reported by the peer."""
12951297

1296-
if not _protocol_version:
1297-
self.protocol_version()
1298-
_protocol_version = self.statusMessage.strip()
1298+
if not self._protocol_version:
1299+
self.protocol_version()
1300+
self._protocol_version = self.statusMessage.strip()
12991301

13001302
return self._protocol_version
13011303

@@ -1386,15 +1388,14 @@ def exec_command(*arguments):
13861388
else:
13871389
map_it = False
13881390

1389-
if re.search( '-value$', cmd ):
1390-
if capture:
1391-
raise gpUsageException( "using the _value suffix together with the capture_ prefix is meaningless" )
1392-
1393-
cmd = cmd[:-6]
1394-
val = True
1395-
} else {
1396-
val = False
1397-
}
1391+
if re.search( '-value$', cmd ):
1392+
if capture:
1393+
raise gpUsageException( "using the _value suffix together with the capture_ prefix is meaningless" )
1394+
1395+
cmd = cmd[:-6]
1396+
val = True
1397+
else:
1398+
val = False
13981399

13991400
result = None
14001401

@@ -1508,12 +1509,12 @@ def exec_command(*arguments):
15081509
if result:
15091510
status = result # from handler
15101511

1511-
if val:
1512-
if status == "VALUE" or status == "OK":
1513-
return self.statusMessage; #XXX: not so pretty
1514-
else:
1515-
raise gpUsageException( "Can't apply _value modifier: command " + command + " did not return a VALUE or OK status, but this: " + status )
1516-
1512+
if val:
1513+
if status == "VALUE" or status == "OK":
1514+
return self.statusMessage; #XXX: not so pretty
1515+
else:
1516+
raise gpUsageException( "Can't apply _value modifier: command " + command + " did not return a VALUE or OK status, but this: " + status )
1517+
15171518
return status
15181519

15191520
setattr(self, name, exec_command) #re-use closure!
@@ -1586,9 +1587,9 @@ def execute(self, command, source=None, sink=None, row_munger=None):
15861587

15871588
strictArgs = self.strictArguments
15881589

1589-
if c == "set-meta" or c == "authorize": #XXX: ugly hack for wellknown commands
1590-
strictArgs = False
1591-
1590+
if c == "set-meta" or c == "authorize": #XXX: ugly hack for wellknown commands
1591+
strictArgs = False
1592+
15921593
for c in command:
15931594
if not isinstance(c, (str, unicode, int, long)):
15941595
raise gpUsageException(
@@ -1791,8 +1792,8 @@ def isValidCommandArgument(arg, strict=True): #static #OK
17911792
if strict:
17921793
return re.match('^\w[-\w]*$', str(arg))
17931794
else:
1794-
return not re.search('[\s\0-\x1F\x80-\xFF|<>!&#]', str(arg))
1795-
# low chars, high chars, and operators.
1795+
return not re.search('[\s\0-\x1F\x80-\xFF|<>!&#]', str(arg))
1796+
# low chars, high chars, and operators.
17961797

17971798
@staticmethod
17981799
def splitRow(s):

python/gp/tests/core_test.py

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,93 @@ def test_traverseSuccessorsWithout(self):
120120

121121
self.assertEquals( [ (11,), (112,), (1121,), ], succ )
122122

123+
def test_setMeta(self):
124+
#define var
125+
self.gp.set_meta("foo", 1234)
126+
val = self.gp.get_meta_value("foo")
127+
self.assertEquals( "1234", val )
128+
129+
#redefine var
130+
self.gp.set_meta("foo", "bla/bla")
131+
val = self.gp.get_meta_value("foo")
132+
self.assertEquals( "bla/bla", val )
133+
134+
# test bad -----------------------------------------
135+
try:
136+
self.gp.set_meta("...", 1234)
137+
self.fail( "exception expected" )
138+
except gpException as ex:
139+
pass
140+
141+
try:
142+
self.gp.set_meta("x y", 1234)
143+
self.fail( "exception expected" )
144+
except gpException as ex:
145+
pass
146+
147+
try:
148+
self.gp._set_meta(" ", 1234)
149+
self.fail( "exception expected" )
150+
except gpException as ex:
151+
pass
152+
153+
try:
154+
self.gp.set_meta("foo", "bla bla")
155+
self.fail( "exception expected" )
156+
except gpException as ex:
157+
pass
158+
159+
try:
160+
self.gp.set_meta("foo", "2<3")
161+
self.fail( "exception expected" )
162+
except gpException as ex:
163+
pass
164+
165+
def test_getMeta(self):
166+
#get undefined
167+
val = self.gp.try_get_meta_value("foo")
168+
self.assertEquals( False, val )
169+
170+
#set var, and get value
171+
self.gp.set_meta("foo", "xxx")
172+
val = self.gp.get_meta_value("foo")
173+
self.assertEquals( "xxx", val )
174+
175+
#remove var, then get value
176+
self.gp.remove_meta("foo")
177+
val = self.gp.try_get_meta_value("foo")
178+
self.assertEquals( False, val )
179+
180+
def test_removeMeta(self):
181+
#remove undefined
182+
ok = self.gp.try_remove_meta("foo")
183+
self.assertEquals( False, ok )
184+
185+
#set var, then remove it
186+
self.gp.set_meta("foo", "xxx")
187+
ok = self.gp.try_remove_meta("foo")
188+
self.assertEquals( "OK", ok )
189+
190+
def test_listMeta(self):
191+
# assert empty
192+
meta = self.gp.capture_list_meta()
193+
self.assertEmpty( meta )
194+
195+
# add one, assert list
196+
self.gp.set_meta("foo", 1234)
197+
meta = self.gp.capture_list_meta_map()
198+
self.assertEquals( { "foo": 1234}, meta )
199+
200+
# remove one, assert empty
201+
self.gp.remove_meta("foo")
202+
meta = self.gp.capture_list_meta()
203+
self.assertEmpty( meta )
204+
123205

124206
#TODO: add all the tests we have in the talkback test suit
125207

126208

127209
if __name__ == '__main__':
128-
unittest.main()
210+
unittest.main()
129211

130212

0 commit comments

Comments
 (0)