Show More
@@ -1,38 +1,52 b'' | |||||
1 | # -*- coding: UTF-8 -*- |
|
1 | """Some tests for the wildcard utilities.""" | |
2 | import sys, unittest |
|
|||
3 | sys.path.append ('..') |
|
|||
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 | class obj_t(object): |
|
17 | class obj_t(object): | |
8 | pass |
|
18 | pass | |
9 |
|
19 | |||
10 | root=obj_t() |
|
20 | root = obj_t() | |
11 | l=["arna","abel","ABEL","active","bob","bark","abbot"] |
|
21 | l = ["arna","abel","ABEL","active","bob","bark","abbot"] | |
12 | q=["kate","loop","arne","vito","lucifer","koppel"] |
|
22 | q = ["kate","loop","arne","vito","lucifer","koppel"] | |
13 | for x in l: |
|
23 | for x in l: | |
14 | o=obj_t() |
|
24 | o = obj_t() | |
15 | setattr(root,x,o) |
|
25 | setattr(root,x,o) | |
16 | for y in q: |
|
26 | for y in q: | |
17 | p=obj_t() |
|
27 | p = obj_t() | |
18 | setattr(o,y,p) |
|
28 | setattr(o,y,p) | |
19 | root._apan=obj_t() |
|
29 | root._apan = obj_t() | |
20 | root._apan.a=10 |
|
30 | root._apan.a = 10 | |
21 | root._apan._a=20 |
|
31 | root._apan._a = 20 | |
22 | root._apan.__a=20 |
|
32 | root._apan.__a = 20 | |
23 | root.__anka=obj_t() |
|
33 | root.__anka = obj_t() | |
24 | root.__anka.a=10 |
|
34 | root.__anka.a = 10 | |
25 | root.__anka._a=20 |
|
35 | root.__anka._a = 20 | |
26 | 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() |
|
47 | #----------------------------------------------------------------------------- | |
29 | root._APAN.a=10 |
|
48 | # Test cases | |
30 | root._APAN._a=20 |
|
49 | #----------------------------------------------------------------------------- | |
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 |
|
|||
36 |
|
50 | |||
37 | class Tests (unittest.TestCase): |
|
51 | class Tests (unittest.TestCase): | |
38 | def test_case(self): |
|
52 | def test_case(self): | |
@@ -46,7 +60,8 b' class Tests (unittest.TestCase):' | |||||
46 | ] |
|
60 | ] | |
47 | for pat,res in tests: |
|
61 | for pat,res in tests: | |
48 | res.sort() |
|
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 | a.sort() |
|
65 | a.sort() | |
51 | self.assertEqual(a,res) |
|
66 | self.assertEqual(a,res) | |
52 |
|
67 | |||
@@ -61,7 +76,8 b' class Tests (unittest.TestCase):' | |||||
61 | ] |
|
76 | ] | |
62 | for pat,res in tests: |
|
77 | for pat,res in tests: | |
63 | res.sort() |
|
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 | a.sort() |
|
81 | a.sort() | |
66 | self.assertEqual(a,res) |
|
82 | self.assertEqual(a,res) | |
67 |
|
83 | |||
@@ -70,14 +86,16 b' class Tests (unittest.TestCase):' | |||||
70 | ns=root.__dict__ |
|
86 | ns=root.__dict__ | |
71 | tests=[ |
|
87 | tests=[ | |
72 | ("a*", ["abbot","abel","ABEL","active","arna",]), |
|
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 | ("_a*", []), |
|
91 | ("_a*", []), | |
75 | ("_*anka", ["__anka","__ANKA",]), |
|
92 | ("_*anka", ["__anka","__ANKA",]), | |
76 | ("_*a*", ["__anka","__ANKA",]), |
|
93 | ("_*a*", ["__anka","__ANKA",]), | |
77 | ] |
|
94 | ] | |
78 | for pat,res in tests: |
|
95 | for pat,res in tests: | |
79 | res.sort() |
|
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 | a.sort() |
|
99 | a.sort() | |
82 | self.assertEqual(a,res) |
|
100 | self.assertEqual(a,res) | |
83 |
|
101 | |||
@@ -85,16 +103,15 b' class Tests (unittest.TestCase):' | |||||
85 | ns=root.__dict__ |
|
103 | ns=root.__dict__ | |
86 | tests=[ |
|
104 | tests=[ | |
87 | ("a*", ["abbot","abel","ABEL","active","arna",]), |
|
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 | ("_a*", ["_apan","_APAN"]), |
|
108 | ("_a*", ["_apan","_APAN"]), | |
90 | ("_*anka", ["__anka","__ANKA",]), |
|
109 | ("_*anka", ["__anka","__ANKA",]), | |
91 | ("_*a*", ["__anka","__ANKA","_apan","_APAN"]), |
|
110 | ("_*a*", ["__anka","__ANKA","_apan","_APAN"]), | |
92 | ] |
|
111 | ] | |
93 | for pat,res in tests: |
|
112 | for pat,res in tests: | |
94 | res.sort() |
|
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 | a.sort() |
|
116 | a.sort() | |
97 | self.assertEqual(a,res) |
|
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