upm/tests/check_examplenames.py
Noel Eck 2f78d9f62b python_examples: Reformatted, self-checking, executable
* Moved body of each python example to main.  This allows for basic
      load module testing for CI
    * General cleanup of python modules (crlf/tabs/prints/etc)
    * Chmod'ed to 755 to allow running examples without specifying the
      python interpreter
    * Added ctest for loading python2/3 modules
    * Added jniclasscode pragma for java swig interface files.
    * Updated check_examplenames.py module to check all languages vs. a
      cxx example name
    * Added tests for checking python module and test loading
    * Added 'make test' to travis-ci run (run ctests)
    * Print a more meaningful message when not building cxx docs into
      python modules
    * Updated check_clean.py to only check java wrapper files
    * ENABLED ctests for UPM
    * Deleted using_carrays.py python example - this is covered by other
      examples

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-10-04 16:10:17 -07:00

76 lines
2.5 KiB
Python
Executable File

#!/usr/bin/python
import unittest
import re, fnmatch, os, sys
# Example name map
sampleMappingFile = '../doxy/samples.mapping.txt'
# Example directories
sampledir = {}
sampledir['cxx'] = '../examples/c++/'
sampledir['java'] = '../examples/java/'
sampledir['js'] = '../examples/javascript/'
sampledir['py'] = '../examples/python/'
# Default to all targets
test_targets = ['java', 'js', 'py']
class SampleNames(unittest.TestCase):
def test_existing_samples(self):
# Dictionary for missing examples
missing = {}
# If test target/s were provided on the command line, use them
if len(self.argv) > 0:
test_targets = self.argv
# Iterate over the mapping file and check for per-language examples
with open (sampleMappingFile, "r") as f:
for line in f:
matched = {}
fullpaths = {}
# Split out the example names per target
for target in test_targets:
match = re.match('(.*.cxx).*\t(\S+.%s)' % target, line)
if match:
matched['cxx'] = match.group(1)
matched[target] = match.group(2)
# Need at least two target files to check
if len(matched) < 2: continue
# Fail if NO .cxx file to compare against
self.assertTrue('cxx' in matched)
# Update the full path to each sample file
for k,v in matched.items():
fullpaths[k] = os.path.join(sampledir[k], v)
# Use cxx base filename as testname
basename = os.path.splitext(matched['cxx'])[0]
missing[basename] = []
# Check for all example filenames
for target, filename in fullpaths.items():
if not os.path.exists(filename):
missing[basename] += [os.path.split(filename)[-1]]
# Prune out tests with no missing files
for k in missing.keys():
if len(missing[k]) == 0: del missing[k]
# Print sorted missing example filenames
sk_missing = missing.keys()
sk_missing.sort()
self.assertEqual(len(missing), 0,
'\n\nMissing examples:\n' +
'\n'.join(['%s: %s' % (k, ', '.join(missing[k])) for k in sk_missing]))
if __name__ == '__main__':
# Allow passing from argv
SampleNames.argv = []
for arg in sys.argv[1:]:
SampleNames.argv.append(sys.argv.pop())
unittest.main()