|
| 1 | +# F3AT - Flumotion Asynchronous Autonomous Agent Toolkit |
| 2 | +# Copyright (C) 2010,2011 Flumotion Services, S.A. |
| 3 | +# All rights reserved. |
| 4 | + |
| 5 | +# This program is free software; you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation; either version 2 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License along |
| 16 | +# with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + |
| 19 | +# See 'LICENSE.GPL' in the source distribution for more information. |
| 20 | + |
| 21 | +# Headers in this file shall remain intact. |
| 22 | +# -*- coding: utf-8 -*- |
| 23 | +# -*- Mode: Python -*- |
| 24 | +# vi:si:et:sw=4:sts=4:ts=4 |
| 25 | + |
| 26 | +import pytest |
| 27 | +from serialization import reflect |
| 28 | +from six.moves import builtins |
| 29 | +from zope.interface import Interface |
| 30 | + |
| 31 | + |
| 32 | +class DummyInterface(Interface): |
| 33 | + pass |
| 34 | + |
| 35 | + |
| 36 | +class Dummy(object): |
| 37 | + |
| 38 | + def spam(self): |
| 39 | + pass |
| 40 | + |
| 41 | + |
| 42 | +def bacon(): |
| 43 | + pass |
| 44 | + |
| 45 | + |
| 46 | +class Meta(type): |
| 47 | + pass |
| 48 | + |
| 49 | + |
| 50 | +class MetaDummy(object): |
| 51 | + __metaclass__ = Meta |
| 52 | + |
| 53 | + |
| 54 | +class TestIntrospection(object): |
| 55 | + |
| 56 | + @pytest.fixture(scope='session') |
| 57 | + def builtin_module(self): |
| 58 | + return builtins.__name__ |
| 59 | + |
| 60 | + def test_interface(self): |
| 61 | + assert ( |
| 62 | + 'tests.test_reflect.DummyInterface' == |
| 63 | + reflect.canonical_name(DummyInterface)) |
| 64 | + |
| 65 | + def test_class(self, builtin_module): |
| 66 | + assert 'tests.test_reflect.Dummy' == reflect.canonical_name(Dummy) |
| 67 | + assert 'tests.test_reflect.Dummy' == reflect.canonical_name(Dummy()) |
| 68 | + assert builtin_module + '.int' == reflect.canonical_name(int) |
| 69 | + assert builtin_module + '.str' == reflect.canonical_name('some string') |
| 70 | + |
| 71 | + def test_class_with_meta(self): |
| 72 | + assert ( |
| 73 | + 'tests.test_reflect.MetaDummy' == |
| 74 | + reflect.canonical_name(MetaDummy)) |
| 75 | + |
| 76 | + def test_method(self, builtin_module): |
| 77 | + assert ( |
| 78 | + 'tests.test_reflect.Dummy.spam' == |
| 79 | + reflect.canonical_name(Dummy.spam)) |
| 80 | + assert ( |
| 81 | + 'tests.test_reflect.Dummy.spam' == |
| 82 | + reflect.canonical_name(Dummy().spam)) |
| 83 | + assert ( |
| 84 | + builtin_module + '.split' == |
| 85 | + reflect.canonical_name('test'.split)) |
| 86 | + |
| 87 | + def test_function(self, builtin_module): |
| 88 | + assert 'tests.test_reflect.bacon' == reflect.canonical_name(bacon) |
| 89 | + assert builtin_module + '.getattr' == reflect.canonical_name(getattr) |
| 90 | + |
| 91 | + def test_none(self): |
| 92 | + assert None == reflect.canonical_name(None) |
| 93 | + |
| 94 | + def test_class_locals_not_from_class(self): |
| 95 | + with pytest.raises(TypeError): |
| 96 | + reflect.class_locals(depth=2) |
| 97 | + |
| 98 | + |
| 99 | +def simple(a, b): |
| 100 | + pass |
| 101 | + |
| 102 | + |
| 103 | +def defaults(a, b=3): |
| 104 | + pass |
| 105 | + |
| 106 | + |
| 107 | +def varargs(a, b=None, *args): |
| 108 | + pass |
| 109 | + |
| 110 | + |
| 111 | +def kwargs(a=None, b=3, *args, **kwargs): |
| 112 | + pass |
0 commit comments