Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$
"""
test_results_dir.py simply prints the directory that rosunit/rostest
results are stored in.
"""
from __future__ import print_function
import rospkg
print(rospkg.get_test_results_dir())
def read_all(filter_=[]):
"""
Read in the test_results and aggregate into a single Result object
@param filter_: list of packages that should be processed
@type filter_: [str]
@return: aggregated result
@rtype: L{Result}
"""
dir_ = rospkg.get_test_results_dir()
root_result = Result('ros', 0, 0, 0)
if not os.path.exists(dir_):
return root_result
for d in os.listdir(dir_):
if filter_ and d not in filter_:
continue
subdir = os.path.join(dir_, d)
if os.path.isdir(subdir):
for filename in os.listdir(subdir):
if filename.endswith('.xml'):
filename = os.path.join(subdir, filename)
result = read(filename, os.path.basename(subdir))
root_result.accumulate(result)
return root_result
def prepare_dirs(output_dir_name):
test_results_dir = rospkg.get_test_results_dir()
print('will read test results from', test_results_dir)
output_dir = os.path.join(test_results_dir, output_dir_name)
if not os.path.exists(output_dir):
print('creating directory', output_dir)
os.makedirs(output_dir)
return test_results_dir, output_dir
def xml_results_file(test_pkg, test_name, is_rostest=False, env=None):
"""
@param test_pkg: name of test's package
@type test_pkg: str
@param test_name str: name of test
@type test_name: str
@param is_rostest: True if the results file is for a rostest-generated unit instance
@type is_rostest: bool
@return: name of xml results file for specified test
@rtype: str
"""
test_dir = os.path.join(rospkg.get_test_results_dir(env=env), test_pkg)
if not os.path.exists(test_dir):
try:
makedirs_with_parent_perms(test_dir)
except OSError as error:
raise IOError('cannot create test results directory [%s]: %s' % (test_dir, str(error)))
# #576: strip out chars that would bork the filename
# this is fairly primitive, but for now just trying to catch some common cases
for c in ' "\'&$!`/\\':
if c in test_name:
test_name = test_name.replace(c, '_')
if is_rostest:
return os.path.join(test_dir, 'rostest-%s.xml' % test_name)
else:
return os.path.join(test_dir, 'rosunit-%s.xml' % test_name)