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')
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')
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')
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')
def test_inheritanceExpose(self): """ Test that overridden methods are not exposed. """ expose = Expose() class Foo(object): def bar(self): return 'baz' expose(bar) class Quux(Foo): def bar(self): return 'BAZ' self.assertEqual(list(expose.exposedMethodNames(Quux())), []) self.assertRaises(UnexposedMethodError, expose.get, Quux(), 'bar')
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')
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')
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')
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')
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')