Пример #1
0
    def test_inheritanceExposeMore(self):
        """
        Test that expose calls in a subclass adds to the parent's exposed
        methods.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'
            expose(bar)

        class Quux(Foo):
            def smokey(self):
                return 'stover'
            def pogo(self):
                return 'kelly'
            def albert(self):
                return 'alligator'
            expose(smokey, pogo)

        self.assertEqual(set(expose.exposedMethodNames(Quux())), set(['pogo', 'smokey', 'bar']))
        self.assertEqual(expose.get(Quux(), 'bar')(), 'baz')
        self.assertEqual(expose.get(Quux(), 'smokey')(), 'stover')
        self.assertEqual(expose.get(Quux(), 'pogo')(), 'kelly')
        self.assertRaises(UnexposedMethodError, expose.get, Quux(), 'albert')
        self.assertEqual(Quux().albert(), 'alligator')
Пример #2
0
    def test_inheritanceExposeMore(self):
        """
        Test that expose calls in a subclass adds to the parent's exposed
        methods.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'

            expose(bar)

        class Quux(Foo):
            def smokey(self):
                return 'stover'

            def pogo(self):
                return 'kelly'

            def albert(self):
                return 'alligator'

            expose(smokey, pogo)

        self.assertEqual(set(expose.exposedMethodNames(Quux())),
                         set(['pogo', 'smokey', 'bar']))
        self.assertEqual(expose.get(Quux(), 'bar')(), 'baz')
        self.assertEqual(expose.get(Quux(), 'smokey')(), 'stover')
        self.assertEqual(expose.get(Quux(), 'pogo')(), 'kelly')
        self.assertRaises(UnexposedMethodError, expose.get, Quux(), 'albert')
        self.assertEqual(Quux().albert(), 'alligator')
Пример #3
0
    def test_getUnexposedWithDefault(self):
        """
        Test that a default can be supplied to Expose.get and it is returned if
        and only if the requested method is not exposed.
        """
        expose = Expose()

        class A(object):
            def foo(self):
                return 'bar'
            expose(foo)

        self.assertEqual(expose.get(A(), 'foo', None)(), 'bar')
        self.assertEqual(expose.get(A(), 'bar', None), None)
Пример #4
0
    def test_getUnexposedWithDefault(self):
        """
        Test that a default can be supplied to Expose.get and it is returned if
        and only if the requested method is not exposed.
        """
        expose = Expose()

        class A(object):
            def foo(self):
                return 'bar'

            expose(foo)

        self.assertEqual(expose.get(A(), 'foo', None)(), 'bar')
        self.assertEqual(expose.get(A(), 'bar', None), None)
Пример #5
0
    def test_multipleInheritanceExpose(self):
        """
        Test that anything exposed on the parents of a class which multiply
        inherits from several other class are all exposed on the subclass.
        """
        expose = Expose()

        class A(object):
            def foo(self):
                return 'bar'
            expose(foo)

        class B(object):
            def baz(self):
                return 'quux'
            expose(baz)

        class C(A, B):
            def quux(self):
                pass
            expose(quux)

        self.assertEqual(set(expose.exposedMethodNames(C())), set(['quux', 'foo', 'baz']))
        self.assertEqual(expose.get(C(), 'foo')(), 'bar')
        self.assertEqual(expose.get(C(), 'baz')(), 'quux')
Пример #6
0
    def test_multipleInheritanceExposeWithoutSubclassCall(self):
        """
        Test that anything exposed on the parents of a class which multiply
        inherits from several other class are all exposed on the subclass.
        """
        expose = Expose()

        class A(object):
            def foo(self):
                return 'bar'

            expose(foo)

        class B(object):
            def baz(self):
                return 'quux'

            expose(baz)

        class C(A, B):
            pass

        self.assertEqual(set(expose.exposedMethodNames(C())),
                         set(['foo', 'baz']))
        self.assertEqual(expose.get(C(), 'foo')(), 'bar')
        self.assertEqual(expose.get(C(), 'baz')(), 'quux')
Пример #7
0
    def test_multipleExposeArguments(self):
        """
        Test exposing multiple methods with a single call to an Expose
        instance.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'

            def quux(self):
                return 'fooble'

            expose(bar, quux)

        self.assertEqual(list(expose.exposedMethodNames(Foo())), ['bar', 'quux'])
        self.assertEqual(expose.get(Foo(), 'bar')(), 'baz')
        self.assertEqual(expose.get(Foo(), 'quux')(), 'fooble')
Пример #8
0
    def test_multipleExposeArguments(self):
        """
        Test exposing multiple methods with a single call to an Expose
        instance.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'

            def quux(self):
                return 'fooble'

            expose(bar, quux)

        self.assertEqual(list(expose.exposedMethodNames(Foo())),
                         ['bar', 'quux'])
        self.assertEqual(expose.get(Foo(), 'bar')(), 'baz')
        self.assertEqual(expose.get(Foo(), 'quux')(), 'fooble')
Пример #9
0
    def test_multipleExposeCalls(self):
        """
        Test exposing multiple methods, each with a call to an Expose instance.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'
            expose(bar)


            def quux(self):
                return 'fooble'
            expose(quux)


        self.assertEquals(list(expose.exposedMethodNames(Foo())), ['bar', 'quux'])
        self.assertEquals(expose.get(Foo(), 'bar')(), 'baz')
        self.assertEquals(expose.get(Foo(), 'quux')(), 'fooble')
Пример #10
0
    def test_multipleExposeCalls(self):
        """
        Test exposing multiple methods, each with a call to an Expose instance.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'

            expose(bar)

            def quux(self):
                return 'fooble'

            expose(quux)

        self.assertEquals(list(expose.exposedMethodNames(Foo())),
                          ['bar', 'quux'])
        self.assertEquals(expose.get(Foo(), 'bar')(), 'baz')
        self.assertEquals(expose.get(Foo(), 'quux')(), 'fooble')
Пример #11
0
    def test_exposedInstanceAttribute(self):
        """
        Test that exposing an instance attribute works in basically the same
        way as exposing a class method and that the two do not interfer with
        each other.
        """
        expose = Expose()

        class Foo(object):
            def __init__(self):
                # Add an exposed instance attribute
                self.bar = expose(lambda: 'baz')

            def quux(self):
                return 'quux'
            expose(quux)

        self.assertEqual(
            set(expose.exposedMethodNames(Foo())),
            set(['bar', 'quux']))
        self.assertEqual(expose.get(Foo(), 'bar')(), 'baz')
        self.assertEqual(expose.get(Foo(), 'quux')(), 'quux')
Пример #12
0
    def test_singleExpose(self):
        """
        Test exposing a single method with a single call to an Expose instance.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'
            expose(bar)

        self.assertEqual(list(expose.exposedMethodNames(Foo())), ['bar'])
        self.assertEqual(expose.get(Foo(), 'bar')(), 'baz')
Пример #13
0
    def test_exposedInstanceAttribute(self):
        """
        Test that exposing an instance attribute works in basically the same
        way as exposing a class method and that the two do not interfer with
        each other.
        """
        expose = Expose()

        class Foo(object):
            def __init__(self):
                # Add an exposed instance attribute
                self.bar = expose(lambda: 'baz')

            def quux(self):
                return 'quux'

            expose(quux)

        self.assertEqual(set(expose.exposedMethodNames(Foo())),
                         set(['bar', 'quux']))
        self.assertEqual(expose.get(Foo(), 'bar')(), 'baz')
        self.assertEqual(expose.get(Foo(), 'quux')(), 'quux')
Пример #14
0
    def test_singleExpose(self):
        """
        Test exposing a single method with a single call to an Expose instance.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'

            expose(bar)

        self.assertEqual(list(expose.exposedMethodNames(Foo())), ['bar'])
        self.assertEqual(expose.get(Foo(), 'bar')(), 'baz')
Пример #15
0
    def test_inheritanceReexpose(self):
        """
        Test that overridden methods can also be re-exposed.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'
            expose(bar)

        class Quux(object):
            def bar(self):
                return 'smokey'
            expose(bar)

        self.assertEqual(list(expose.exposedMethodNames(Quux())), ['bar'])
        self.assertEqual(expose.get(Quux(), 'bar')(), 'smokey')
Пример #16
0
    def test_inheritanceReexpose(self):
        """
        Test that overridden methods can also be re-exposed.
        """
        expose = Expose()

        class Foo(object):
            def bar(self):
                return 'baz'

            expose(bar)

        class Quux(object):
            def bar(self):
                return 'smokey'

            expose(bar)

        self.assertEqual(list(expose.exposedMethodNames(Quux())), ['bar'])
        self.assertEqual(expose.get(Quux(), 'bar')(), 'smokey')