Lots of code seems to be under test, but not all. I think function-level unit tests would benefit most of the more obscure code, such as authorized_key.parseoptions() ( https://github.com/ansible/ansible/blob/devel/library/system/authorized_key#L174 )
I spent some time writing unit tests for this module, but I couldn’t find an elegant way to make it work with nosetests. The problem is a hardcoded toplevel main() call, that will make a regular import call sys.exit because of the missing boilerplate code.
Some random ideas to enable module unit tests:
- Find a way to load an Ansible module without executing main(). For example, with imp.load_module and stripping the main() call before evaluation. Quite ugly.
- Refactor all modules to only call main() when name is ‘main’. Lots of work, possibly backwards incompatible.
- Before importing, preprocess the module just like hacking/test-module does, to add the missing boilerplate code. Possibly slow.
- …
What do you think?