~ipython-dev/ipython/0.10.1

« back to all changes in this revision

Viewing changes to test/test_wildcard.py

  • Committer: Fernando Perez
  • Date: 2008-06-02 01:26:30 UTC
  • mfrom: (0.1.130 ipython-local)
  • Revision ID: fernando.perez@berkeley.edu-20080602012630-m14vezrhydzvahf8
Merge in all development done in bzr since February 16 2008.

At that time, a clean bzr branch was started from the SVN tree, but
without SVN history.  That SVN history has now been used as the basis
of this branch, and the development done on the history-less BZR
branch has been added and is the content of this merge.  

This branch will be the new official main line of development in
Launchpad (equivalent to the old SVN trunk).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
 
2
import sys, unittest
 
3
sys.path.append ('..')
 
4
 
 
5
from IPython import wildcard
 
6
 
 
7
class obj_t(object):
 
8
    pass
 
9
 
 
10
root=obj_t()
 
11
l=["arna","abel","ABEL","active","bob","bark","abbot"]
 
12
q=["kate","loop","arne","vito","lucifer","koppel"]
 
13
for x in l:
 
14
    o=obj_t()
 
15
    setattr(root,x,o)
 
16
    for y in q:
 
17
        p=obj_t()
 
18
        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
 
27
 
 
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
 
36
 
 
37
class Tests (unittest.TestCase):
 
38
    def test_case(self):
 
39
        ns=root.__dict__
 
40
        tests=[
 
41
         ("a*",     ["abbot","abel","active","arna",]),
 
42
         ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop",]),
 
43
         ("_a*",    []),
 
44
         ("_*anka", ["__anka",]),
 
45
         ("_*a*",   ["__anka",]),
 
46
        ]
 
47
        for pat,res in tests:
 
48
            res.sort()
 
49
            a=wildcard.list_namespace(ns,"all",pat,ignore_case=False,show_all=False).keys()
 
50
            a.sort()
 
51
            self.assertEqual(a,res)
 
52
 
 
53
    def test_case_showall(self):
 
54
        ns=root.__dict__
 
55
        tests=[
 
56
         ("a*",     ["abbot","abel","active","arna",]),
 
57
         ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop",]),
 
58
         ("_a*",    ["_apan"]),
 
59
         ("_*anka", ["__anka",]),
 
60
         ("_*a*",   ["__anka","_apan",]),
 
61
        ]
 
62
        for pat,res in tests:
 
63
            res.sort()
 
64
            a=wildcard.list_namespace(ns,"all",pat,ignore_case=False,show_all=True).keys()
 
65
            a.sort()
 
66
            self.assertEqual(a,res)
 
67
 
 
68
 
 
69
    def test_nocase(self):
 
70
        ns=root.__dict__
 
71
        tests=[
 
72
         ("a*",     ["abbot","abel","ABEL","active","arna",]),
 
73
         ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop","ABEL.koppel","ABEL.loop",]),
 
74
         ("_a*",    []),
 
75
         ("_*anka", ["__anka","__ANKA",]),
 
76
         ("_*a*",   ["__anka","__ANKA",]),
 
77
        ]
 
78
        for pat,res in tests:
 
79
            res.sort()
 
80
            a=wildcard.list_namespace(ns,"all",pat,ignore_case=True,show_all=False).keys()
 
81
            a.sort()
 
82
            self.assertEqual(a,res)
 
83
 
 
84
    def test_nocase_showall(self):
 
85
        ns=root.__dict__
 
86
        tests=[
 
87
         ("a*",     ["abbot","abel","ABEL","active","arna",]),
 
88
         ("?b*.?o*",["abbot.koppel","abbot.loop","abel.koppel","abel.loop","ABEL.koppel","ABEL.loop",]),
 
89
         ("_a*",    ["_apan","_APAN"]),
 
90
         ("_*anka", ["__anka","__ANKA",]),
 
91
         ("_*a*",   ["__anka","__ANKA","_apan","_APAN"]),
 
92
        ]
 
93
        for pat,res in tests:
 
94
            res.sort()
 
95
            a=wildcard.list_namespace(ns,"all",pat,ignore_case=True,show_all=True).keys()
 
96
            a.sort()
 
97
            self.assertEqual(a,res)
 
98
            
 
99
if __name__ == '__main__':
 
100
    unittest.main()
 
 
b'\\ No newline at end of file'