def is_magic(member): """Checks whether given class/instance member, or its name, is "magic". Magic fields and methods have names that begin and end with double underscores, such ``__hash__`` or ``__eq__``. """ return lang.is_magic(_get_member_name(member))
def is_magic(member): """Checks whether given class/instance member, or its name, is "magic". Magic fields and methods have names that begin and end with double underscores, such ``__hash__`` or ``__eq__``. """ return lang.is_magic(_get_member_name(member))
def test_string__underscore_suffix(self): self.assertFalse(__unit__.is_magic('foo_'))
def test_string__just_letters(self): self.assertFalse(__unit__.is_magic('FooBar')) self.assertFalse(__unit__.is_magic('fooBar'))
def test_string__double_underscore_prefix(self): self.assertFalse(__unit__.is_magic('__foo')) self.assertFalse(__unit__.is_magic('__Foo'))
def test_string__empty(self): self.assertFalse(__unit__.is_magic(''))
def test_string__number(self): self.assertFalse(__unit__.is_magic('42'))
def test_string__number(self): self.assertFalse(__unit__.is_magic('42'))
def test_some_object(self): with self.assertRaises(TypeError): __unit__.is_magic(object())
def test_string__magic(self): self.assertTrue(__unit__.is_magic('__foo__')) self.assertTrue(__unit__.is_magic('__FooBar__'))
def test_string__magic(self): self.assertTrue(__unit__.is_magic('__foo__')) self.assertTrue(__unit__.is_magic('__FooBar__'))
def test_string__single_underscore(self): self.assertFalse(__unit__.is_magic('_'))
def test_string__four_underscores(self): self.assertFalse(__unit__.is_magic('____'))
def test_string__underscore_suffix(self): self.assertFalse(__unit__.is_magic('foo_'))
def test_string__double_underscore_prefix(self): self.assertFalse(__unit__.is_magic('__foo')) self.assertFalse(__unit__.is_magic('__Foo'))
def test_string__just_letters(self): self.assertFalse(__unit__.is_magic('FooBar')) self.assertFalse(__unit__.is_magic('fooBar'))
def test_string__single_underscore(self): self.assertFalse(__unit__.is_magic('_'))
def test_some_object(self): with self.assertRaises(TypeError): __unit__.is_magic(object())
def test_string__four_underscores(self): self.assertFalse(__unit__.is_magic('____'))
def test_string__empty(self): self.assertFalse(__unit__.is_magic(''))
def test_none(self): with self.assertRaises(TypeError): __unit__.is_magic(None)
def test_none(self): with self.assertRaises(TypeError): __unit__.is_magic(None)