diff options
author | Torsten Marek <tmarek@google.com> | 2013-07-24 08:52:53 +0200 |
---|---|---|
committer | Torsten Marek <tmarek@google.com> | 2013-07-24 08:52:53 +0200 |
commit | c9c195c0b7d4029439e0e5ae6957df8d3367d264 (patch) | |
tree | 97cdae3faafd1b7a1975e0d9ea27050c9d3b5113 | |
parent | 492a32dc8743e43c9dd2db0ede8d1dc311555258 (diff) | |
download | astroid-c9c195c0b7d4029439e0e5ae6957df8d3367d264.tar.gz |
Update some function definitions in py2stdlib's hashlib stub module
and make sure AST transforms without a predicate always match.
Test all this in a new testcase.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | brain/py2stdlib.py | 8 | ||||
-rw-r--r-- | rebuilder.py | 2 | ||||
-rw-r--r-- | test/unittest_brain.py | 39 |
4 files changed, 47 insertions, 5 deletions
@@ -2,6 +2,9 @@ Change log for the astroid package (used to be astng) ===================================================== -- + * Fix some omissions in py2stdlib's version of hashlib and + add a small test for it. + * Properly recognize methods annotated with abc.abstract{property,method} as abstract. diff --git a/brain/py2stdlib.py b/brain/py2stdlib.py index cea3a79..53a9b8a 100644 --- a/brain/py2stdlib.py +++ b/brain/py2stdlib.py @@ -29,16 +29,16 @@ def hashlib_transform(module): fake = AstroidBuilder(MANAGER).string_build(''' class md5(object): - def __init__(self, value): pass - def digest(): + def __init__(self, value=''): pass + def digest(self): return u'' def update(self, value): pass def hexdigest(self): return u'' class sha1(object): - def __init__(self, value): pass - def digest(): + def __init__(self, value=''): pass + def digest(self): return u'' def update(self, value): pass def hexdigest(self): diff --git a/rebuilder.py b/rebuilder.py index cf92da0..7f4c7a7 100644 --- a/rebuilder.py +++ b/rebuilder.py @@ -136,7 +136,7 @@ class TreeRebuilder(object): return node # no transform registered for this class of node orig_node = node # copy the reference for transform_func, predicate in transforms: - if predicate is not None and predicate(node): + if predicate is None or predicate(node): ret = transform_func(node) # if the transformation function returns something, it's # expected to be a replacement for the node diff --git a/test/unittest_brain.py b/test/unittest_brain.py new file mode 100644 index 0000000..5f1da65 --- /dev/null +++ b/test/unittest_brain.py @@ -0,0 +1,39 @@ +# Copyright 2013 Google Inc. All Rights Reserved. +# +# This file is part of astroid. +# +# logilab-astng 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. +# +# logilab-astng 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 logilab-astng. If not, see <http://www.gnu.org/licenses/>. +"""Tests for basic functionality in astroid.brain.""" + +from astroid import MANAGER +from logilab.common.testlib import TestCase, unittest_main + + +class HashlibTC(TestCase): + def test_hashlib(self): + """Tests that brain extensions for hashlib work.""" + hashlib_module = MANAGER.ast_from_module_name('hashlib') + for class_name in ['md5', 'sha1']: + class_obj = hashlib_module[class_name] + self.assertIn('update', class_obj) + self.assertIn('digest', class_obj) + self.assertIn('hexdigest', class_obj) + self.assertEqual(len(class_obj['__init__'].args.args), 2) + self.assertEqual(len(class_obj['__init__'].args.defaults), 1) + self.assertEqual(len(class_obj['update'].args.args), 2) + self.assertEqual(len(class_obj['digest'].args.args), 1) + self.assertEqual(len(class_obj['hexdigest'].args.args), 1) + +if __name__ == '__main__': + unittest_main() |