Show More
@@ -1,100 +1,117 b'' | |||
|
1 | # -*- coding: UTF-8 -*- | |
|
2 | import sys, unittest | |
|
3 | sys.path.append ('..') | |
|
1 | """Some tests for the wildcard utilities.""" | |
|
4 | 2 | |
|
5 | from IPython import wildcard | |
|
3 | #----------------------------------------------------------------------------- | |
|
4 | # Library imports | |
|
5 | #----------------------------------------------------------------------------- | |
|
6 | # Stdlib | |
|
7 | import sys | |
|
8 | import unittest | |
|
9 | ||
|
10 | # Our own | |
|
11 | from IPython.utils import wildcard | |
|
12 | ||
|
13 | #----------------------------------------------------------------------------- | |
|
14 | # Globals for test | |
|
15 | #----------------------------------------------------------------------------- | |
|
6 | 16 | |
|
7 | 17 | class obj_t(object): |
|
8 | 18 | pass |
|
9 | 19 | |
|
10 | root=obj_t() | |
|
11 | l=["arna","abel","ABEL","active","bob","bark","abbot"] | |
|
12 | q=["kate","loop","arne","vito","lucifer","koppel"] | |
|
20 | root = obj_t() | |
|
21 | l = ["arna","abel","ABEL","active","bob","bark","abbot"] | |
|
22 | q = ["kate","loop","arne","vito","lucifer","koppel"] | |
|
13 | 23 | for x in l: |
|
14 | o=obj_t() | |
|
24 | o = obj_t() | |
|
15 | 25 | setattr(root,x,o) |
|
16 | 26 | for y in q: |
|
17 | p=obj_t() | |
|
27 | p = obj_t() | |
|
18 | 28 | setattr(o,y,p) |
|
19 | root._apan=obj_t() | |
|
20 | root._apan.a=10 | |
|
21 | root._apan._a=20 | |
|
22 | root._apan.__a=20 | |
|
23 | root.__anka=obj_t() | |
|
24 | root.__anka.a=10 | |
|
25 | root.__anka._a=20 | |
|
26 | root.__anka.__a=20 | |
|
29 | root._apan = obj_t() | |
|
30 | root._apan.a = 10 | |
|
31 | root._apan._a = 20 | |
|
32 | root._apan.__a = 20 | |
|
33 | root.__anka = obj_t() | |
|
34 | root.__anka.a = 10 | |
|
35 | root.__anka._a = 20 | |
|
36 | root.__anka.__a = 20 | |
|
37 | ||
|
38 | root._APAN = obj_t() | |
|
39 | root._APAN.a = 10 | |
|
40 | root._APAN._a = 20 | |
|
41 | root._APAN.__a = 20 | |
|
42 | root.__ANKA = obj_t() | |
|
43 | root.__ANKA.a = 10 | |
|
44 | root.__ANKA._a = 20 | |
|
45 | root.__ANKA.__a = 20 | |
|
27 | 46 | |
|
28 | root._APAN=obj_t() | |
|
29 | root._APAN.a=10 | |
|
30 | root._APAN._a=20 | |
|
31 | root._APAN.__a=20 | |
|
32 | root.__ANKA=obj_t() | |
|
33 | root.__ANKA.a=10 | |
|
34 | root.__ANKA._a=20 | |
|
35 | root.__ANKA.__a=20 | |
|
47 | #----------------------------------------------------------------------------- | |
|
48 | # Test cases | |
|
49 | #----------------------------------------------------------------------------- | |
|
36 | 50 | |
|
37 | 51 | class Tests (unittest.TestCase): |
|
38 | 52 | def test_case(self): |
|
39 | 53 | ns=root.__dict__ |
|
40 | 54 | tests=[ |
|
41 | 55 | ("a*", ["abbot","abel","active","arna",]), |
|
42 | 56 | ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop",]), |
|
43 | 57 | ("_a*", []), |
|
44 | 58 | ("_*anka", ["__anka",]), |
|
45 | 59 | ("_*a*", ["__anka",]), |
|
46 | 60 | ] |
|
47 | 61 | for pat,res in tests: |
|
48 | 62 | res.sort() |
|
49 |
a=wildcard.list_namespace(ns,"all",pat,ignore_case=False, |
|
|
63 | a=wildcard.list_namespace(ns,"all",pat,ignore_case=False, | |
|
64 | show_all=False).keys() | |
|
50 | 65 | a.sort() |
|
51 | 66 | self.assertEqual(a,res) |
|
52 | 67 | |
|
53 | 68 | def test_case_showall(self): |
|
54 | 69 | ns=root.__dict__ |
|
55 | 70 | tests=[ |
|
56 | 71 | ("a*", ["abbot","abel","active","arna",]), |
|
57 | 72 | ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop",]), |
|
58 | 73 | ("_a*", ["_apan"]), |
|
59 | 74 | ("_*anka", ["__anka",]), |
|
60 | 75 | ("_*a*", ["__anka","_apan",]), |
|
61 | 76 | ] |
|
62 | 77 | for pat,res in tests: |
|
63 | 78 | res.sort() |
|
64 |
a=wildcard.list_namespace(ns,"all",pat,ignore_case=False, |
|
|
79 | a=wildcard.list_namespace(ns,"all",pat,ignore_case=False, | |
|
80 | show_all=True).keys() | |
|
65 | 81 | a.sort() |
|
66 | 82 | self.assertEqual(a,res) |
|
67 | 83 | |
|
68 | 84 | |
|
69 | 85 | def test_nocase(self): |
|
70 | 86 | ns=root.__dict__ |
|
71 | 87 | tests=[ |
|
72 | 88 | ("a*", ["abbot","abel","ABEL","active","arna",]), |
|
73 |
("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop", |
|
|
89 | ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop", | |
|
90 | "ABEL.koppel","ABEL.loop",]), | |
|
74 | 91 | ("_a*", []), |
|
75 | 92 | ("_*anka", ["__anka","__ANKA",]), |
|
76 | 93 | ("_*a*", ["__anka","__ANKA",]), |
|
77 | 94 | ] |
|
78 | 95 | for pat,res in tests: |
|
79 | 96 | res.sort() |
|
80 |
a=wildcard.list_namespace(ns,"all",pat,ignore_case=True, |
|
|
97 | a=wildcard.list_namespace(ns,"all",pat,ignore_case=True, | |
|
98 | show_all=False).keys() | |
|
81 | 99 | a.sort() |
|
82 | 100 | self.assertEqual(a,res) |
|
83 | 101 | |
|
84 | 102 | def test_nocase_showall(self): |
|
85 | 103 | ns=root.__dict__ |
|
86 | 104 | tests=[ |
|
87 | 105 | ("a*", ["abbot","abel","ABEL","active","arna",]), |
|
88 |
("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop", |
|
|
106 | ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop", | |
|
107 | "ABEL.koppel","ABEL.loop",]), | |
|
89 | 108 | ("_a*", ["_apan","_APAN"]), |
|
90 | 109 | ("_*anka", ["__anka","__ANKA",]), |
|
91 | 110 | ("_*a*", ["__anka","__ANKA","_apan","_APAN"]), |
|
92 | 111 | ] |
|
93 | 112 | for pat,res in tests: |
|
94 | 113 | res.sort() |
|
95 |
a=wildcard.list_namespace(ns,"all",pat,ignore_case=True, |
|
|
114 | a=wildcard.list_namespace(ns,"all",pat,ignore_case=True, | |
|
115 | show_all=True).keys() | |
|
96 | 116 | a.sort() |
|
97 | 117 | self.assertEqual(a,res) |
|
98 | ||
|
99 | if __name__ == '__main__': | |
|
100 | unittest.main() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now