34 from __future__
import print_function
42 import roslib.packages
44 TEST_CTX =
'rosgraph_msgs' 47 PKG=
'test_roslib_comm' 55 test_dir = os.path.join(roslib.packages.get_pkg_dir(PKG),
'test',
'md5tests', dir)
57 for f
in os.listdir(test_dir):
58 path = os.path.join(test_dir, f)
59 if not f.endswith(
'.txt'):
62 while name
and name[-1].isdigit():
66 tests[name].append(path)
72 from roslib.gentools
import compute_md5, get_dependencies
73 from roslib.msgs
import load_from_string
75 text = open(f,
'r').read() 76 spec = load_from_string(text, package_context=TEST_CTX) 77 get_deps_dict = get_dependencies(spec, TEST_CTX, compute_files=False)
78 return compute_md5(get_deps_dict)
81 from roslib.gentools
import compute_md5_text, get_dependencies
82 from roslib.msgs
import load_from_string
84 text = open(f,
'r').read() 85 spec = load_from_string(text, package_context=TEST_CTX) 86 get_deps_dict = get_dependencies(spec, TEST_CTX, compute_files=False)
87 return compute_md5_text(get_deps_dict, spec)
90 from std_msgs.msg
import Header
91 Header_md5 = Header._md5sum
92 rg_msg_dir = os.path.join(roslib.packages.get_pkg_dir(TEST_CTX),
'msg')
93 clock_msg = os.path.join(rg_msg_dir,
'Clock.msg')
96 log_msg = os.path.join(rg_msg_dir,
'Log.msg')
97 self.assertEquals(
"byte DEBUG=1\nbyte INFO=2\nbyte WARN=4\nbyte ERROR=8\nbyte FATAL=16\n%s header\nbyte level\nstring name\nstring msg\nstring file\nstring function\nuint32 line\nstring[] topics"%Header_md5, self.
_compute_md5_text(log_msg))
101 for k, files
in tests.items():
102 print(
"running tests", k)
103 ref_file = [f
for f
in files
if f.endswith(
'%s1.txt'%k)]
105 self.fail(
"failed to load %s"%k)
106 ref_file = ref_file[0]
107 ref_text = open(ref_file,
'r').read().strip() 109 files = [f
for f
in files
if not f.endswith(
'%s1.txt'%k)]
112 self.assertEquals(ref_text, f_text,
"failed on %s\n%s\n%s: \n[%s]\nvs.\n[%s]\n"%(k, ref_file, f, ref_text, f_text))
116 for k, files
in tests.items():
117 print(
"running tests", k)
124 for k, files
in tests.items():
125 print(
"running tests", k)
131 self.assertEquals(len(md5s), len(files))