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>
This commit is contained in:
Noel Eck
2016-09-29 18:24:19 -07:00
parent 62718daf0b
commit 2f78d9f62b
203 changed files with 5890 additions and 5216 deletions

68
tests/check_pythonload.py Executable file
View File

@ -0,0 +1,68 @@
#!/usr/bin/python
import unittest
import imp
import glob
import os, sys
# Skip individual modules based on module name. For example,
# pyupm_ozw will skip pyupm_ozw.py.
blacklist = [
# OpenZwave-dependent modules
'pyupm_ozw', 'aeotecdw2e', 'tzemt400', 'aeotecdsb09104',
'aeotecss6', 'aeotecsdg2', 'ozwdump',
# Requires mraa python module
'curieimu',
# Requires modbus
'h803x', 'hwxpxx', 't3311',
# Requires bacnet
'e50hx', 'tb7300', 't8100',
# Requires PIL
'make_oled_pic'
]
class loadModule(unittest.TestCase):
''' The loadModule class loads all module which match a search string
provided via argv. If any of the target modules fails loading, this
class will assert and provide a list of failing modules.'''
def test_load_module(self):
# Python version provided on the command line
py_search_str = '../build/src/*/python2.7/*.py'
if len(self.argv) > 0:
py_search_str = self.argv[0]
# Make sure the search string has a full path
full_py_search_str = os.path.realpath(py_search_str)
# Get all python modules matching full_py_search_str
pyfiles = glob.glob(full_py_search_str)
# Fail if no modules to test
self.assertNotEqual(len(pyfiles), 0,
'Failed to find any %s modules in %s' % \
(py_search_str, full_py_search_str));
# Test load each module
failures = {}
for pyfile in pyfiles:
module = os.path.splitext(os.path.basename(pyfile))[0]
# Don't load blacklisted modules
if module in blacklist:
print('Skipping blacklisted %s ...' % pyfile)
continue
try:
pyfile = imp.load_source(module, pyfile)
except Exception as x:
failures[pyfile] = x
self.assertEqual(len(failures), 0,
'\n\nFailed to load %d modules:\n' % len(failures) +
'\n'.join(['%s: %s' % (k, ', '.join(failures[k])) for k in failures.keys()]))
if __name__ == '__main__':
# Allow passing from argv
loadModule.argv = []
for arg in sys.argv[1:]:
loadModule.argv.append(sys.argv.pop())
unittest.main()