forked from rootpy/rootpy
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_pythonize.py
More file actions
58 lines (43 loc) · 1.48 KB
/
Copy pathtest_pythonize.py
File metadata and controls
58 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright 2012 the rootpy developers
# distributed under the terms of the GNU General Public License
from rootpy.pythonize import SnakeMethods
from nose.tools import assert_equal, assert_true
def test_snake_case_methods():
class A(object):
def SomeMethod(self): pass
def some_method(self): pass
def OtherMethod(self): pass
def Write(self): pass
def Cd(self): pass
def cd(self): pass
def LongMethodName(self): pass
@SnakeMethods
class B(A):
def write(self): pass
assert_true(hasattr(B, 'some_method'))
assert_true(hasattr(B, 'cd'))
assert_true(hasattr(B, 'long_method_name'))
assert_true(hasattr(B, 'write'))
assert_true(hasattr(B, 'other_method'))
def test_snake_case_methods_descriptor():
def f(_): pass
class A(object):
Prop = property(f)
Sm = staticmethod(f)
Cm = classmethod(f)
M = f
class B(A):
cm = A.__dict__["Cm"]
m = A.__dict__["M"]
prop = A.__dict__["Prop"]
sm = A.__dict__["Sm"]
snakeB = SnakeMethods(True)(A)
# Ensure that no accidental descriptor dereferences happened inside
# `snake_case_methods`. This is checked by making sure that the types
# are the same between B and snakeB.
for member in dir(snakeB):
if member.startswith("_"): continue
assert_equal(type(getattr(B, member)), type(getattr(snakeB, member)))
if __name__ == "__main__":
import nose
nose.runmodule()