From 8ffc0c7a67532a5e51ad19aa8c93edd9abf4a2dc Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Sat, 3 Oct 2015 15:26:33 +0300 Subject: Add a test for issue #188, which was triggered because the transforms weren't executed in a separated step. Closes issue #188. --- astroid/tests/unittest_transforms.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/astroid/tests/unittest_transforms.py b/astroid/tests/unittest_transforms.py index 9c1e806..29a8b8d 100644 --- a/astroid/tests/unittest_transforms.py +++ b/astroid/tests/unittest_transforms.py @@ -215,6 +215,31 @@ class TestTransforms(unittest.TestCase): # The transform wasn't applied. self.assertIsInstance(module.body[0], nodes.FunctionDef) + def test_transform_crashes_on_is_subtype_of(self): + # Test that we don't crash when having is_subtype_of + # in a transform, as per issue #188. This happened + # before, when the transforms weren't in their own step. + def transform_class(cls): + if cls.is_subtype_of('django.db.models.base.Model'): + return cls + return cls + + self.transformer.register_transform(nodes.ClassDef, + transform_class) + + self.parse_transform(''' + # Change environ to automatically call putenv() if it exists + import os + putenv = os.putenv + try: + # This will fail if there's no putenv + putenv + except NameError: + pass + else: + import UserDict + ''') + if __name__ == '__main__': unittest.main() -- cgit v1.2.1