Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parser.add_option("-o", "--output-file",
dest="output_file", default=None,
help="file to store test results in", metavar="FILE")
options, args = parser.parse_args()
if not args:
parser.error('please specify a file or directory for roslaunch files to test')
roslaunch_path = args[0]
# #2590: implementing this quick and dirty as this script should only be used by higher level tools
env_vars = args[1:]
for e in env_vars:
var, val = e.split('=')
os.environ[var] = val
pkg = rospkg.get_package_name(roslaunch_path)
r = rospkg.RosPack()
pkg_dir = r.get_path(pkg)
if os.path.isfile(roslaunch_path):
error_msg = check_roslaunch_file(roslaunch_path)
outname = os.path.basename(roslaunch_path).replace('.', '_')
else:
print("checking *.launch in directory", roslaunch_path)
error_msg = check_roslaunch_dir(roslaunch_path)
abspath = os.path.abspath
relpath = abspath(roslaunch_path)[len(abspath(pkg_dir))+1:]
outname = relpath.replace(os.sep, '_')
if outname == '.':
outname = '_pkg'
import rostest.rostestutil
def go(argv):
if len(argv) != 2:
print('wrong number args')
sys.exit(1)
d=rospkg.distro.load_distro(argv[1])
ri=rospkg.distro.distro_to_rosinstall(d, 'release')
print(ri)
def __init__(self):
rospack = rospkg.RosPack()
pkgDir = rospack.get_path('rapp_testing_tools')
audioFile = path.join(pkgDir, 'test_data', 'deutera.wav')
self.msg = SpeechRecognitionSphinx(
language='el',
audio_source='headset',
words=[u'Δευτέρα'],
sentences=[u'Δευτέρα'],
grammar=[u'Δευτέρα'],
audiofile=audioFile)
self.svc = RappPlatformService(self.msg)
self.valid_words_found = [u'Δευτέρα']
def __init__(self):
rospack = rospkg.RosPack()
pkgDir = rospack.get_path('rapp_testing_tools')
imagepath = path.join(pkgDir, 'test_data','qr_samples', 'hardMediumQr.jpg')
self.msg = QrDetection(imageFilepath=imagepath)
self.svc = RappPlatformService(msg=self.msg)
self.valid_results = {
'qr_centers': [{'y': 543, 'x': 661}],
'qr_messages': ['This QR will be used to check the algorithmic robustness as it is quite small'],
'error': ''
}
# pass in config to class as a property so that test_parent can be initialized
classdict = { 'setUp': setUp, 'tearDown': tearDown, 'config': config,
'test_parent': None, 'test_file': test_file,
'reuse_master': reuse_master, 'clear': clear }
# add in the tests
testNames = []
for test in config.tests:
# #1989: find test first to make sure it exists and is executable
err_msg = None
try:
rp = rospkg.RosPack()
cmd = roslib.packages.find_node(test.package, test.type, rp)
if not cmd:
err_msg = "Test node [%s/%s] does not exist or is not executable"%(test.package, test.type)
except rospkg.ResourceNotFound as e:
err_msg = "Package [%s] for test node [%s/%s] does not exist"%(test.package, test.package, test.type)
testName = 'test%s'%(test.test_name)
if err_msg:
classdict[testName] = failRunner(test.test_name, err_msg)
elif testName in testNames:
classdict[testName] = failDuplicateRunner(test.test_name)
else:
classdict[testName] = rostestRunner(test, pkg, results_base_dir=results_base_dir)
testNames.append(testName)
# instantiate the TestCase instance with our magically-created tests
return type('RosTest',(unittest.TestCase,),classdict)
roslaunch.core.add_printerrlog_handler(logger.error)
logger.info('rostest starting with options %s, args %s'%(options, args))
if len(args) == 0:
parser.error("You must supply a test file argument to rostest.")
if len(args) != 1:
parser.error("rostest only accepts a single test file")
# compute some common names we'll be using to generate test names and files
test_file = args[0]
if options.pkg_dir and options.package:
# rosbuild2: the build system knows what package and directory, so let it tell us,
# instead of shelling back out to rospack
pkg_dir, pkg = options.pkg_dir, options.package
else:
pkg = rospkg.get_package_name(test_file)
r = rospkg.RosPack()
pkg_dir = r.get_path(pkg)
if options.results_filename:
outname = options.results_filename
if '.' in outname:
outname = outname[:outname.rfind('.')]
else:
outname = rostest_name_from_path(pkg_dir, test_file)
env = None
if options.results_base_dir:
env = {ROS_TEST_RESULTS_DIR: options.results_base_dir}
# #1140
if not os.path.isfile(test_file):
def check_main():
if len(sys.argv) < 2:
usage()
if '--rostest' in sys.argv[1:]:
if len(sys.argv) != 4:
usage()
test_pkg, test_file = [a for a in sys.argv[1:] if a != '--rostest']
# this logic derives the output filename that rostest uses
r = rospkg.RosPack()
pkg_name = rospkg.get_package_name(test_file)
pkg_dir = r.get_path(pkg_name)
# compute test name for friendlier reporting
outname = rosunit.rostest_name_from_path(pkg_dir, test_file)
test_file = rosunit.xml_results_file(test_pkg, outname, is_rostest=True)
else:
if len(sys.argv) != 2:
usage()
test_file = sys.argv[1]
print('Checking for test results in %s' % test_file)
if not os.path.exists(test_file):
if not os.path.exists(os.path.dirname(test_file)):
os.makedirs(os.path.dirname(test_file))
def get_rospkg():
# configure inside of the test tree
test_dir = get_test_dir()
ros_root = os.path.join(test_dir, 'ros')
ros_package_path = os.path.join(test_dir, 'stacks')
ros_paths = [ros_root, ros_package_path]
rospack = RosPack(ros_paths=ros_paths)
rosstack = RosStack(ros_paths=ros_paths)
return rospack, rosstack
def test_check(self):
sources_cache = get_cache_dir()
cmd_extras = ['-c', sources_cache]
with fakeout() as b:
try:
rosdep_main(['check', 'python_dep'] + cmd_extras)
except SystemExit:
assert False, 'system exit occurred: %s\n%s' % (b[0].getvalue(), b[1].getvalue())
stdout, stderr = b
assert stdout.getvalue().strip() == 'All system dependencies have been satisfied', stdout.getvalue()
assert not stderr.getvalue(), stderr.getvalue()
try:
osd = rospkg.os_detect.OsDetect()
override = '%s:%s' % (osd.get_name(), osd.get_codename())
with fakeout() as b:
rosdep_main(['check', 'python_dep', '--os', override] + cmd_extras)
stdout, stderr = b
assert stdout.getvalue().strip() == 'All system dependencies have been satisfied'
assert not stderr.getvalue(), stderr.getvalue()
except SystemExit:
assert False, 'system exit occurred'
# this used to abort, but now rosdep assumes validity for even empty stack args
try:
with fakeout() as b:
rosdep_main(['check', 'packageless'] + cmd_extras)
stdout, stderr = b
assert stdout.getvalue().strip() == 'All system dependencies have been satisfied'
assert not stderr.getvalue(), stderr.getvalue()
def test_InstallerContext_ctor():
from rosdep2.installers import InstallerContext
from rospkg.os_detect import OsDetect
context = InstallerContext()
assert context.get_os_detect() is not None
assert isinstance(context.get_os_detect(), OsDetect)
detect = OsDetect()
context = InstallerContext(detect)
assert context.get_os_detect() == detect
assert len(context.get_installer_keys()) == 0
assert len(context.get_os_keys()) == 0
context.verbose = True
assert context.get_os_detect() == detect
assert len(context.get_installer_keys()) == 0
assert len(context.get_os_keys()) == 0