Skip to content

Commit

Permalink
python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Oct 23, 2013
1 parent bd2b577 commit 4527703
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/genmsg/gentools.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def compute_md5_text(msg_context, spec):
sub_md5 = compute_md5(msg_context, sub_spec)
buff.write("%s %s\n"%(sub_md5, name))

return buff.getvalue().strip() # remove trailing new line
value = buff.getvalue().strip() # remove trailing new line
return value.encode()

def _compute_hash(msg_context, spec, hash):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/genmsg/template_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _generate_from_spec(input_file, output_dir, template_dir, msg_context, spec,
if not os.path.isfile(template_file):
ofile.close()
os.remove(output_file)
raise RuntimeError, "Template file %s not found in template dir %s" % (template_file_name, template_dir)
raise RuntimeError("Template file %s not found in template dir %s" % (template_file_name, template_dir))
interpreter.file(open(template_file)) #todo try
interpreter.shutdown()

Expand Down Expand Up @@ -171,7 +171,7 @@ def generate_module(package_name, output_dir, template_dir, template_dict):
if not os.path.isfile(template_file):
ofile.close()
os.remove(output_file)
raise RuntimeError, "Template file %s not found in template dir %s" % (template_file_name, template_dir)
raise RuntimeError("Template file %s not found in template dir %s" % (template_file_name, template_dir))
interpreter.file(open(template_file)) #todo try
interpreter.shutdown()

Expand Down
6 changes: 3 additions & 3 deletions test/test_genmsg_gentools.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_compute_md5_text():

tests = _load_md5_tests('md5text')
# text file #1 is the reference
for k, files in tests.iteritems():
for k, files in tests.items():
print("running tests", k)
ref_file = [f for f in files if f.endswith('%s1.txt'%k)]
if not ref_file:
Expand All @@ -124,7 +124,7 @@ def test_md5_equals():

search_path = get_search_path()
tests = _load_md5_tests('same')
for k, files in tests.iteritems():
for k, files in tests.items():
print("running tests", k)
md5sum = _compute_md5(msg_context, files[0])
for f in files[1:]:
Expand All @@ -135,7 +135,7 @@ def test_md5_not_equals():
msg_context = MsgContext.create_default()

tests = _load_md5_tests('different')
for k, files in tests.iteritems():
for k, files in tests.items():
print("running tests", k)
md5s = set()
md6md5sum = _compute_md5(msg_context, files[0])
Expand Down
2 changes: 1 addition & 1 deletion test/test_genmsg_msg_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_load_msg_from_string():
from genmsg.msg_loader import load_msg_from_string, MsgContext
context = MsgContext.create_default()
msgspec = load_msg_from_string(context, "Header header", 'test_pkg/HeaderTest')
print msgspec
print(msgspec)
assert msgspec.has_header()
assert msgspec.types == ['std_msgs/Header']
assert msgspec.names == ['header']
Expand Down
2 changes: 1 addition & 1 deletion test/test_genmsg_msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_parse_type():

def test_Constant():
import genmsg.msgs
vals = [random.randint(0, 1000) for i in xrange(0, 3)]
vals = [random.randint(0, 1000) for i in range(0, 3)]
type_, name, val = [str(x) for x in vals]
x = genmsg.msgs.Constant(type_, name, val, str(val))
assert type_ == x.type
Expand Down

0 comments on commit 4527703

Please sign in to comment.