def test_method__magic(self): class Class(object): def __foo__(self): pass def __Bar__(self): pass def __foo_bar__(self): pass def __FooBar__(self): pass self.assertTrue(__unit__.is_magic(Class.__foo__)) self.assertTrue(__unit__.is_magic(Class.__Bar__)) self.assertTrue(__unit__.is_magic(Class.__foo_bar__)) self.assertTrue(__unit__.is_magic(Class.__FooBar__))
def test_method__public(self): class Class(object): def foo(self): pass def Bar(self): pass def foo_bar(self): pass def FooBar(self): pass self.assertFalse(__unit__.is_magic(Class.foo)) self.assertFalse(__unit__.is_magic(Class.Bar)) self.assertFalse(__unit__.is_magic(Class.foo_bar)) self.assertFalse(__unit__.is_magic(Class.FooBar))
def test_method__internal(self): class Class(object): def _foo(self): pass def _Bar(self): pass def _foo_bar(self): pass def _FooBar(self): pass self.assertFalse(__unit__.is_magic(Class._foo)) self.assertFalse(__unit__.is_magic(Class._Bar)) self.assertFalse(__unit__.is_magic(Class._foo_bar)) self.assertFalse(__unit__.is_magic(Class._FooBar))
def test_method__magic(self): class Class(object): def __foo__(self): pass def __Bar__(self): pass def __foo_bar__(self): pass def __FooBar__(self): pass self.assertTrue(__unit__.is_magic(Class.__foo__)) self.assertTrue(__unit__.is_magic(Class.__Bar__)) self.assertTrue(__unit__.is_magic(Class.__foo_bar__)) self.assertTrue(__unit__.is_magic(Class.__FooBar__))
def test_method__public(self): class Class(object): def foo(self): pass def Bar(self): pass def foo_bar(self): pass def FooBar(self): pass self.assertFalse(__unit__.is_magic(Class.foo)) self.assertFalse(__unit__.is_magic(Class.Bar)) self.assertFalse(__unit__.is_magic(Class.foo_bar)) self.assertFalse(__unit__.is_magic(Class.FooBar))
def test_method__internal(self): class Class(object): def _foo(self): pass def _Bar(self): pass def _foo_bar(self): pass def _FooBar(self): pass self.assertFalse(__unit__.is_magic(Class._foo)) self.assertFalse(__unit__.is_magic(Class._Bar)) self.assertFalse(__unit__.is_magic(Class._foo_bar)) self.assertFalse(__unit__.is_magic(Class._FooBar))
def __call__(self, class_): for name, method in get_methods(class_): if is_internal(name) or is_magic(name): continue # TODO(xion): warn about terminator method names # that haven't been encountered in the decorated ``class_`` if not self._is_terminator(name, method): fluent_method = self._make_fluent(method) setattr(class_, name, fluent_method) return class_
def __call__(self, class_): for name, method in get_methods(class_): if is_internal(name) or is_magic(name): continue # TODO(xion): warn about terminator method names # that haven't been encountered in the decorated ``class_`` if not self._is_terminator(name, method): fluent_method = self._make_fluent(method) setattr(class_, name, fluent_method) return class_
def test_some_object(self): with self.assertRaises(TypeError): __unit__.is_magic(object())
def test_none(self): with self.assertRaises(TypeError): __unit__.is_magic(None)
def test_string__empty(self): self.assertFalse(__unit__.is_magic(''))
def test_none(self): with self.assertRaises(TypeError): __unit__.is_magic(None)
def test_string__magic_identifiers(self): self.assertTrue(__unit__.is_magic('__foo__')) self.assertTrue(__unit__.is_magic('__Bar__')) self.assertTrue(__unit__.is_magic('__foo_bar__')) self.assertTrue(__unit__.is_magic('__FooBar__'))
def test_string__internal_identifiers(self): self.assertFalse(__unit__.is_magic('_foo')) self.assertFalse(__unit__.is_magic('_Bar')) self.assertFalse(__unit__.is_magic('_foo_bar')) self.assertFalse(__unit__.is_magic('_FooBar'))
def test_string__public_identifiers(self): self.assertFalse(__unit__.is_magic('foo')) self.assertFalse(__unit__.is_magic('Bar')) self.assertFalse(__unit__.is_magic('foo_bar')) self.assertFalse(__unit__.is_magic('FooBar'))
def test_string__empty(self): self.assertFalse(__unit__.is_magic(''))
def test_string__public_identifiers(self): self.assertFalse(__unit__.is_magic('foo')) self.assertFalse(__unit__.is_magic('Bar')) self.assertFalse(__unit__.is_magic('foo_bar')) self.assertFalse(__unit__.is_magic('FooBar'))
def test_string__internal_identifiers(self): self.assertFalse(__unit__.is_magic('_foo')) self.assertFalse(__unit__.is_magic('_Bar')) self.assertFalse(__unit__.is_magic('_foo_bar')) self.assertFalse(__unit__.is_magic('_FooBar'))
def test_string__magic_identifiers(self): self.assertTrue(__unit__.is_magic('__foo__')) self.assertTrue(__unit__.is_magic('__Bar__')) self.assertTrue(__unit__.is_magic('__foo_bar__')) self.assertTrue(__unit__.is_magic('__FooBar__'))
def test_some_object(self): with self.assertRaises(TypeError): __unit__.is_magic(object())