| Trees | Indices | Help |
|
|---|
|
|
1 #-*- coding: utf8 -*
2 #
3 # Max E. Kuznecov ~syhpoon <mek@mek.uz.ua> 2008-2009
4 #
5 # This file is part of XYZCommander.
6 # XYZCommander is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 # XYZCommander is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser Public License for more details.
14 # You should have received a copy of the GNU Lesser Public License
15 # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>.
16
17 # Core tests
18
19 import __builtin__
20 import locale
21 import tempfile
22 import os
23
24 import libxyz.core as core
25
26
27 from nose.tools import raises
28 from libxyz.exceptions import *
29 from libxyz.vfs.vfsobj import VFSFile
30
31 # Global data
32 xyz = None
33 files = {}
36 global xyz, filesw
37
38 xyz = core.XYZData()
39 __builtin__._ = lambda x: x
40 __builtin__.xyzenc = locale.getpreferredencoding()
41
42 # Setup files
43 files["actions_good"], files["actions_bad"] = setup_actions()
44
47 fd_good, path_good = tempfile.mkstemp(text=True)
48 fd_bad, path_bad = tempfile.mkstemp(text=True)
49 os.write(fd_good, """action(r'iname{".*\.pdf$"}', lambda obj: obj)""")
50 os.write(fd_bad, ":(")
51
52 return path_good, path_bad
53
61
65 """
66 libxyz.core.Queue tests
67 """
68
71
72 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73
74 @raises(XYZValueError)
77
78 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79
80 @raises(IndexError)
82 self.q.pop()
83
84 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85
87 assert self.q.tail() is None
88
89 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90
94
95 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96
111
115 """
116 libxyz.core.ActionManager tests
117 """
118
122
123 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124
125 @raises(XYZRuntimeError)
127 self.am.register("WRONG", lambda: None)
128
129 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130
132 assert self.am.register("size{100}", lambda: None) is None
133
134 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135
136 @raises(XYZRuntimeError)
138 global files
139 xyz = core.XYZData()
140
141 am = core.ActionManager(xyz, [files["actions_bad"], "none"])
142 xyz.am = am
143
144 am.parse_configs()
145
146 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147
149 global files
150 xyz = core.XYZData()
151
152 am = core.ActionManager(xyz, [files["actions_good"], "none"])
153 xyz.am = am
154
155 assert am.parse_configs() is None
156
157 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158
160 vfs_size = VFSFile("/tmp/test_size")
161 vfs_size.size = 100
162 vfs_name = VFSFile("/tmp/test_name")
163 vfs_owner = VFSFile("/tmp/test_owner")
164 vfs_owner.uid = 500
165 vfs_owner.gid = 501
166
167 self.am.register("size{100}", lambda: "size")
168 self.am.register("name{test_name}", lambda: "name")
169 self.am.register("owner{500:501}", lambda: "owner")
170
171 assert self.am.match(vfs_size)() == "size"
172 assert self.am.match(vfs_name)() == "name"
173 assert self.am.match(vfs_owner)() == "owner"
174
175 #++++++++++++++++++++++++++++++++++++++++++++++++
176
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Aug 3 02:02:16 2009 | http://epydoc.sourceforge.net |