2013-06-27 11:52:36 +00:00
|
|
|
# Import python libs
|
2013-02-17 13:23:51 +00:00
|
|
|
import re
|
2013-06-27 11:52:36 +00:00
|
|
|
|
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
|
|
|
# Import salt libs
|
|
|
|
import integration
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-03-28 18:07:48 +00:00
|
|
|
|
|
|
|
class SysModuleTest(integration.ModuleCase):
|
|
|
|
'''
|
|
|
|
Validate the sys module
|
|
|
|
'''
|
|
|
|
def test_list_functions(self):
|
|
|
|
'''
|
|
|
|
sys.list_functions
|
|
|
|
'''
|
2013-06-27 22:00:55 +00:00
|
|
|
# Get all functions
|
2012-03-28 18:07:48 +00:00
|
|
|
funcs = self.run_function('sys.list_functions')
|
2013-06-27 22:00:55 +00:00
|
|
|
self.assertIn('hosts.list_hosts', funcs)
|
|
|
|
self.assertIn('pkg.install', funcs)
|
|
|
|
|
|
|
|
# Just sysctl
|
|
|
|
funcs = self.run_function('sys.list_functions', ('sysctl',))
|
|
|
|
self.assertNotIn('sys.doc', funcs)
|
|
|
|
self.assertIn('sysctl.get', funcs)
|
2012-03-28 18:07:48 +00:00
|
|
|
|
2013-06-27 22:15:36 +00:00
|
|
|
# Just sys
|
|
|
|
funcs = self.run_function('sys.list_functions', ('sys.',))
|
|
|
|
self.assertNotIn('sysctl.get', funcs)
|
|
|
|
self.assertIn('sys.doc', funcs)
|
|
|
|
|
|
|
|
# Staring with sys
|
|
|
|
funcs = self.run_function('sys.list_functions', ('sys',))
|
|
|
|
self.assertNotIn('sysctl.get', funcs)
|
|
|
|
self.assertIn('sys.doc', funcs)
|
|
|
|
|
2012-03-28 18:07:48 +00:00
|
|
|
def test_list_modules(self):
|
|
|
|
'''
|
|
|
|
sys.list_moduels
|
|
|
|
'''
|
|
|
|
mods = self.run_function('sys.list_modules')
|
|
|
|
self.assertTrue('hosts' in mods)
|
|
|
|
self.assertTrue('pkg' in mods)
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2013-02-08 18:14:00 +00:00
|
|
|
def test_valid_docs(self):
|
|
|
|
'''
|
|
|
|
Make sure no functions are exposed that don't have valid docstrings
|
|
|
|
'''
|
|
|
|
docs = self.run_function('sys.doc')
|
2013-02-17 12:52:36 +00:00
|
|
|
nodoc = set()
|
|
|
|
noexample = set()
|
2013-06-18 22:38:42 +00:00
|
|
|
allow_failure = (
|
|
|
|
'pkg.expand_repo_def',
|
|
|
|
'runtests_decorators.depends',
|
|
|
|
'runtests_decorators.depends_will_fallback',
|
|
|
|
'runtests_decorators.missing_depends',
|
|
|
|
'runtests_decorators.missing_depends_will_fallback',)
|
|
|
|
|
2013-02-08 18:14:00 +00:00
|
|
|
for fun in docs:
|
|
|
|
if fun.startswith('runtests_helpers'):
|
|
|
|
continue
|
2013-04-22 21:40:15 +00:00
|
|
|
if fun in allow_failure:
|
|
|
|
continue
|
2013-02-08 18:14:00 +00:00
|
|
|
if not isinstance(docs[fun], basestring):
|
2013-02-17 12:52:36 +00:00
|
|
|
nodoc.add(fun)
|
2013-03-09 16:07:19 +00:00
|
|
|
elif not re.search(r'([E|e]xample(?:s)?)+(?:.*)::', docs[fun]):
|
2013-02-17 12:52:36 +00:00
|
|
|
noexample.add(fun)
|
2013-02-08 18:14:00 +00:00
|
|
|
|
2013-02-17 12:52:36 +00:00
|
|
|
if not nodoc and not noexample:
|
|
|
|
return
|
|
|
|
|
|
|
|
raise AssertionError(
|
2013-04-22 21:40:15 +00:00
|
|
|
'There are some functions which do not have a doctring or do not '
|
|
|
|
'have an example:\nNo doctring:\n{0}\nNo example:\n{1}\n'.format(
|
2013-02-17 12:52:36 +00:00
|
|
|
'\n'.join([' - {0}'.format(f) for f in sorted(nodoc)]),
|
|
|
|
'\n'.join([' - {0}'.format(f) for f in sorted(noexample)]),
|
|
|
|
)
|
|
|
|
)
|
2012-07-20 06:21:01 +00:00
|
|
|
|
2013-06-27 11:52:36 +00:00
|
|
|
|
2012-07-20 06:21:01 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(SysModuleTest)
|