Added the ability to specify the name of the package that contains the
test file. This is needed when the test file is a compiled program (e.g., gtest) that lives in the build tree, where rospkg's package-name-inference strategy doesn't behave as expected. The new stuff is optional; when not given, the old behavior persists.
This commit is contained in:
parent
a0d795ef94
commit
d97be9ae15
|
@ -62,7 +62,7 @@ class TestTimeoutException(Exception): pass
|
||||||
|
|
||||||
class BareTestCase(unittest.TestCase):
|
class BareTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def __init__(self, exe, args, retry=0, time_limit=None, test_name=None, text_mode=False):
|
def __init__(self, exe, args, retry=0, time_limit=None, test_name=None, text_mode=False, package_name=None):
|
||||||
"""
|
"""
|
||||||
@param exe: path to executable to run
|
@param exe: path to executable to run
|
||||||
@type exe: str
|
@type exe: str
|
||||||
|
@ -73,9 +73,14 @@ class BareTestCase(unittest.TestCase):
|
||||||
@type time_limit: float
|
@type time_limit: float
|
||||||
@param test_name: (optional) override automatically generated test name
|
@param test_name: (optional) override automatically generated test name
|
||||||
@type test_name: str
|
@type test_name: str
|
||||||
|
@param package_name: (optional) override automatically inferred package name
|
||||||
|
@type package_name: str
|
||||||
"""
|
"""
|
||||||
super(BareTestCase, self).__init__()
|
super(BareTestCase, self).__init__()
|
||||||
self.text_mode = text_mode
|
self.text_mode = text_mode
|
||||||
|
if package_name:
|
||||||
|
self.package = package_name
|
||||||
|
else:
|
||||||
self.package = rospkg.get_package_name(exe)
|
self.package = rospkg.get_package_name(exe)
|
||||||
self.exe = os.path.abspath(exe)
|
self.exe = os.path.abspath(exe)
|
||||||
if test_name is None:
|
if test_name is None:
|
||||||
|
|
|
@ -63,6 +63,9 @@ def rosunitmain():
|
||||||
parser.add_option("--name", metavar="TEST_NAME",
|
parser.add_option("--name", metavar="TEST_NAME",
|
||||||
dest="test_name", default=None,
|
dest="test_name", default=None,
|
||||||
help="Test name")
|
help="Test name")
|
||||||
|
parser.add_option("--package", metavar="PACKAGE_NAME",
|
||||||
|
dest="pkg", default=None,
|
||||||
|
help="Package name (optional)")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
|
@ -78,8 +81,14 @@ def rosunitmain():
|
||||||
test_name = test_name[:test_name.rfind('.')]
|
test_name = test_name[:test_name.rfind('.')]
|
||||||
time_limit = float(options.time_limit) if options.time_limit else None
|
time_limit = float(options.time_limit) if options.time_limit else None
|
||||||
|
|
||||||
|
# If the caller didn't tell us the package name, we'll try to infer it.
|
||||||
# compute some common names we'll be using to generate test names and files
|
# compute some common names we'll be using to generate test names and files
|
||||||
|
pkg = options.pkg
|
||||||
|
if not pkg:
|
||||||
pkg = rospkg.get_package_name(test_file)
|
pkg = rospkg.get_package_name(test_file)
|
||||||
|
if not pkg:
|
||||||
|
print "Error: failed to determine package name for file '%s'; maybe you should supply the --package argument to rosunit?"%(test_file)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
runner_result = None
|
runner_result = None
|
||||||
|
@ -87,7 +96,7 @@ def rosunitmain():
|
||||||
|
|
||||||
test_case = BareTestCase(test_file, args[1:], \
|
test_case = BareTestCase(test_file, args[1:], \
|
||||||
retry=0, time_limit=time_limit, \
|
retry=0, time_limit=time_limit, \
|
||||||
test_name=test_name, text_mode=options.text_mode)
|
test_name=test_name, text_mode=options.text_mode, package_name=pkg)
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTest(test_case)
|
suite.addTest(test_case)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue