diff options
| author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-01-11 11:40:03 +0200 |
|---|---|---|
| committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-01-11 11:40:03 +0200 |
| commit | b94b983211b7bd019a70e2e1ab19b9c5fffe141d (patch) | |
| tree | 1a185be1c60121e48ca8ddbef5911cc7634eebd9 | |
| parent | 6490a487a4793c2595c43ce155c33ec18b18304e (diff) | |
| download | astroid-git-b94b983211b7bd019a70e2e1ab19b9c5fffe141d.tar.gz | |
Add inference tips for nose.tools.
| -rw-r--r-- | ChangeLog | 2 | ||||
| -rw-r--r-- | astroid/brain/pynose.py | 56 |
2 files changed, 58 insertions, 0 deletions
@@ -32,6 +32,8 @@ Change log for the astroid package (used to be astng) * .slots() can contain unicode strings on Python 2. + * Add inference tips for nose.tools. + 2014-11-22 -- 1.3.2 diff --git a/astroid/brain/pynose.py b/astroid/brain/pynose.py new file mode 100644 index 00000000..a38b941a --- /dev/null +++ b/astroid/brain/pynose.py @@ -0,0 +1,56 @@ +# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This file is part of astroid. +# +# astroid is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by the +# Free Software Foundation, either version 2.1 of the License, or (at your +# option) any later version. +# +# astroid is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License +# for more details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with astroid. If not, see <http://www.gnu.org/licenses/>. + +"""Hooks for nose library.""" + +import re +import unittest + +from astroid import List, MANAGER, register_module_extender +from astroid.builder import AstroidBuilder + + +def _pep8(name, caps=re.compile('([A-Z])')): + return caps.sub(lambda m: '_' + m.groups()[0].lower(), name) + + +def nose_transform(): + """Custom transform for the nose.tools module.""" + + builder = AstroidBuilder(MANAGER) + stub = AstroidBuilder(MANAGER).string_build('''__all__ = []''') + unittest_module = builder.module_build(unittest.case) + case = unittest_module['TestCase'] + all_entries = ['ok_', 'eq_'] + + for method_name, method in case.locals.items(): + if method_name.startswith('assert') and '_' not in method_name: + pep8_name = _pep8(method_name) + all_entries.append(pep8_name) + stub[pep8_name] = method + + # Update the __all__ variable, since nose.tools + # does this manually with .append. + all_assign = stub['__all__'].parent + all_object = List(all_entries) + all_object.parent = all_assign + all_assign.value = all_object + return stub + + +register_module_extender(MANAGER, 'nose.tools.trivial', nose_transform) |
