Skip to content

Commit

Permalink
Fixed raet to run in python 3.5 without simplejson
Browse files Browse the repository at this point in the history
Added local test runners to test directories so can run subsets of unit tests
  • Loading branch information
SmithSamuelM committed Oct 19, 2015
1 parent edfdcd5 commit 19391b5
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 23 deletions.
16 changes: 16 additions & 0 deletions raet/flo/test/__init__.py
Expand Up @@ -2,3 +2,19 @@
'''
raet.flo unit test package
'''
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import os

from ioflo import test
from ioflo.base.consoling import getConsole
console = getConsole()
console.reinit(verbosity=console.Wordage.concise)

top = os.path.dirname(os.path.abspath(sys.modules.get(__name__).__file__))

if __name__ == "__main__":
test.run(top)
9 changes: 7 additions & 2 deletions raet/keeping.py
Expand Up @@ -111,10 +111,15 @@ def dump(data, filepath):
raise raeting.KeepError("Invalid filepath '{0}' "
"contains space".format(filepath))

if hasattr(data, 'get'):
for key, val in data.items(): # P3 json.dump no encoding parameter
if isinstance(val, (bytes, bytearray)):
data[key] = val.decode('utf-8')

root, ext = os.path.splitext(filepath)
if ext == '.json':
with ocfn(filepath, "w+") as f:
json.dump(data, f, indent=2, encoding='utf-8')
json.dump(data, f, indent=2)
f.flush()
os.fsync(f.fileno())
elif ext == '.msgpack':
Expand Down Expand Up @@ -143,7 +148,7 @@ def load(filepath):
root, ext = os.path.splitext(filepath)
if ext == '.json':
with ocfn(filepath, "r") as f:
it = json.load(f, object_pairs_hook=odict, encoding='utf-8')
it = json.load(f, object_pairs_hook=odict)
elif ext == '.msgpack':
if not msgpack:
raise raeting.KeepError("Invalid filepath ext '{0}' "
Expand Down
6 changes: 2 additions & 4 deletions raet/lane/paging.py
Expand Up @@ -156,8 +156,7 @@ def pack(self):
if pk == PackKind.json:
if self.data:
self.packed = ns2b(json.dumps(self.data,
separators=(',', ':'),
encoding='utf-8'))
separators=(',', ':')))
elif pk == PackKind.pack:
if self.data:
if not msgpack:
Expand Down Expand Up @@ -194,8 +193,7 @@ def parse(self):
if pk == PackKind.json:
if self.packed:
self.data = json.loads(self.packed.decode(encoding='utf-8'),
object_pairs_hook=odict,
encoding='utf-8')
object_pairs_hook=odict)
elif pk == PackKind.pack:
if self.packed:
if not msgpack:
Expand Down
16 changes: 16 additions & 0 deletions raet/lane/test/__init__.py
Expand Up @@ -2,3 +2,19 @@
'''
raet.lane unit test package
'''
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import os

from ioflo import test
from ioflo.base.consoling import getConsole
console = getConsole()
console.reinit(verbosity=console.Wordage.concise)

top = os.path.dirname(os.path.abspath(sys.modules.get(__name__).__file__))

if __name__ == "__main__":
test.run(top)
7 changes: 2 additions & 5 deletions raet/road/packeting.py
Expand Up @@ -128,8 +128,7 @@ def pack(self):
elif data['hk'] == HeadKind.json:
kit['pl'] = '0000000' # need hex string so fixed length and jsonable
kit['hl'] = '00' # need hex string so fixed length and jsonable
packed = (ns2b(json.dumps(kit, separators=(',', ':'),
encoding='ascii',)) + raeting.JSON_END)
packed = (ns2b(json.dumps(kit, separators=(',', ':'))) + raeting.JSON_END)
hl = len(packed)
if hl > raeting.MAX_HEAD_SIZE:
emsg = "Head length of {0}, exceeds max of {1}".format(hl, MAX_HEAD_SIZE)
Expand Down Expand Up @@ -216,7 +215,6 @@ def parse(self):
front, sep, back = packed.partition(raeting.JSON_END)
self.packed = front + sep
kit = json.loads(front.decode(encoding='ascii'),
encoding='ascii',
object_pairs_hook=odict)
data.update(kit)
if 'fg' in data:
Expand Down Expand Up @@ -278,8 +276,7 @@ def pack(self):
if bk == BodyKind.json:
if self.data:
self.packed = ns2b(json.dumps(self.data,
separators=(',', ':'),
encoding='utf-8'))
separators=(',', ':')))
elif bk == BodyKind.msgpack:
if self.data:
if not msgpack:
Expand Down
16 changes: 16 additions & 0 deletions raet/road/test/__init__.py
Expand Up @@ -2,3 +2,19 @@
'''
raet.road unit test package
'''
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import os

from ioflo import test
from ioflo.base.consoling import getConsole
console = getConsole()
console.reinit(verbosity=console.Wordage.concise)

top = os.path.dirname(os.path.abspath(sys.modules.get(__name__).__file__))

if __name__ == "__main__":
test.run(top)
21 changes: 11 additions & 10 deletions raet/road/test/test_joining.py
Expand Up @@ -11313,8 +11313,8 @@ def testJoinerAcceptMissingMode(self):
('mode', None),
('kind', alpha.kind),
('uid', remote.uid),
('verhex', alpha.local.signer.verhex),
('pubhex', alpha.local.priver.pubhex),
('verhex', str(alpha.local.signer.verhex.decode('ISO-8859-1'))),
('pubhex', str(alpha.local.priver.pubhex.decode('ISO-8859-1'))),
('role', alpha.local.role)])
packet = packeting.TxPacket(stack=alpha,
kind=raeting.PcktKind.response.value,
Expand Down Expand Up @@ -11379,8 +11379,8 @@ def testJoinerAcceptMissingKind(self):
('mode', operation),
('kind', None),
('uid', remote.uid),
('verhex', alpha.local.signer.verhex),
('pubhex', alpha.local.priver.pubhex),
('verhex', str(alpha.local.signer.verhex.decode('ISO-8859-1'))),
('pubhex', str(alpha.local.priver.pubhex.decode('ISO-8859-1'))),
('role', alpha.local.role)])
packet = packeting.TxPacket(stack=alpha,
kind=raeting.PcktKind.response.value,
Expand Down Expand Up @@ -11445,8 +11445,8 @@ def testJoinerAcceptMissingUid(self):
('mode', operation),
('kind', alpha.kind),
('uid', None),
('verhex', alpha.local.signer.verhex),
('pubhex', alpha.local.priver.pubhex),
('verhex', str(alpha.local.signer.verhex.decode('ISO-8859-1'))),
('pubhex', str(alpha.local.priver.pubhex.decode('ISO-8859-1'))),
('role', alpha.local.role)])
packet = packeting.TxPacket(stack=alpha,
kind=raeting.PcktKind.response.value,
Expand Down Expand Up @@ -12422,8 +12422,8 @@ def testJoinentJoinMissingMode(self):
body = odict([('name', beta.local.name),
('mode', None),
('kind', beta.kind),
('verhex', beta.local.signer.verhex),
('pubhex', beta.local.priver.pubhex),
('verhex', str(beta.local.signer.verhex.decode('ISO-8859-1'))),
('pubhex', str(beta.local.priver.pubhex.decode('ISO-8859-1'))),
('role', beta.local.role)])
packet = packeting.TxPacket(stack=beta,
kind=raeting.PcktKind.request.value,
Expand Down Expand Up @@ -12475,8 +12475,8 @@ def testJoinentJoinMissingKind(self):
body = odict([('name', beta.local.name),
('mode', operation),
('kind', None),
('verhex', beta.local.signer.verhex),
('pubhex', beta.local.priver.pubhex),
('verhex', str(beta.local.signer.verhex.decode('ISO-8859-1'))),
('pubhex', str(beta.local.priver.pubhex.decode('ISO-8859-1'))),
('role', beta.local.role)])
packet = packeting.TxPacket(stack=beta,
kind=raeting.PcktKind.request.value,
Expand Down Expand Up @@ -14057,3 +14057,4 @@ def runAll():
runSome()#only run some

#runOne('testAllJoinAcceptDropped')
#runOne('testJoinerAcceptMissingMode')
4 changes: 2 additions & 2 deletions raet/road/test/test_packeting.py
Expand Up @@ -709,8 +709,8 @@ def runAll():

#runAll() #run all unittests

runSome()#only run some
#runSome()#only run some

#runOneBasic('testBasicJson')

#runOneStack('testSign')
runOneStack('testSign')

0 comments on commit 19391b5

Please sign in to comment.