3 # autoprop_tests.py: testing automatic properties
5 # Subversion is a tool for revision control.
6 # See http://subversion.tigris.org for more information.
8 # ====================================================================
9 # Copyright (c) 2000-2004 CollabNet. All rights reserved.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://subversion.tigris.org/license-1.html.
14 # If newer versions of this license are posted there, you may use a
15 # newer version instead, at your option.
17 ######################################################################
27 Skip
= svntest
.testcase
.Skip
28 XFail
= svntest
.testcase
.XFail
29 Item
= svntest
.wc
.StateItem
33 def check_proplist(path
, exp_out
, config_dir
):
34 """Verify that property list on PATH has a value of EXP_OUT"""
36 out
, err
= svntest
.main
.run_svn(None, 'proplist', '--verbose', path
,
37 '--config-dir', config_dir
)
41 out2
= out2
+ [line
.strip()]
45 print "Expected properties:", exp_out
46 print "Actual properties: ", out2
47 print "Actual proplist output:", out
51 ######################################################################
54 #----------------------------------------------------------------------
56 def create_config(config_dir
, enable_flag
):
57 "create config directories and files"
59 # contents of the file 'config'
60 config_contents
= '''\
62 enable-auto-props = %s
68 foobar.lha = lhafile=da;lzhfile=niet
69 spacetest = abc = def ; ghi = ; = j
71 ''' % (enable_flag
and 'yes' or 'no')
73 svntest
.main
.create_config_dir(config_dir
, config_contents
)
75 #----------------------------------------------------------------------
77 def autoprops_test(sbox
, cmd
, cfgenable
, clienable
, subdir
):
78 """configurable autoprops test.
80 CMD is the subcommand to test: 'import' or 'add'
81 if CFGENABLE is true, enable autoprops in the config file, else disable
82 if CLIENABLE == 1: --auto-props is added to the command line
84 -1: --no-auto-props is added to command line
85 if string SUBDIR is not empty files are created in that subdir and the
86 directory is added/imported"""
93 tmp_dir
= os
.path
.abspath(svntest
.main
.temp_dir
)
94 config_dir
= os
.path
.join(tmp_dir
, 'autoprops_config_' + sbox
.name
)
95 repos_url
= sbox
.repo_url
97 # initialize parameters
99 parameters
= ['import', '-m', 'bla']
105 parameters
= parameters
+ ['--config-dir', config_dir
]
107 create_config(config_dir
, cfgenable
)
109 # add comandline flags
111 parameters
= parameters
+ ['--auto-props']
113 elif clienable
== -1:
114 parameters
= parameters
+ ['--no-auto-props']
117 enable_flag
= cfgenable
119 # setup subdirectory if needed
121 files_dir
= os
.path
.join(files_dir
, subdir
)
122 files_wc_dir
= os
.path
.join(wc_dir
, subdir
)
123 os
.makedirs(files_dir
)
125 files_wc_dir
= wc_dir
128 filenames
= ['foo.h',
134 for filename
in filenames
:
135 svntest
.main
.file_write(os
.path
.join(files_dir
, filename
),
139 # add/import the files
140 for filename
in filenames
:
141 path
= os
.path
.join(files_dir
, filename
)
143 tmp_params
= parameters
+ [path
, repos_url
+ '/' + filename
]
145 tmp_params
= parameters
+ [path
]
146 svntest
.main
.run_svn(None, *tmp_params
)
148 # add/import subdirectory
150 parameters
= parameters
+ [files_dir
, repos_url
]
152 parameters
= parameters
+ [files_wc_dir
]
153 svntest
.main
.run_svn(None, *parameters
)
155 # do an svn co if needed
157 svntest
.main
.run_svn(None, 'checkout', repos_url
, files_wc_dir
,
158 '--config-dir', config_dir
)
160 # check the properties
162 filename
= os
.path
.join(files_wc_dir
, 'foo.h')
163 check_proplist(filename
, ['auto : oui'], config_dir
)
164 filename
= os
.path
.join(files_wc_dir
, 'foo.c')
165 check_proplist(filename
, ['auto : oui', 'cfile : yes'], config_dir
)
166 filename
= os
.path
.join(files_wc_dir
, 'foo.jpg')
167 check_proplist(filename
, ['auto : oui', 'jpgfile : ja'], config_dir
)
168 filename
= os
.path
.join(files_wc_dir
, 'fubar.tar')
169 check_proplist(filename
, ['auto : oui', 'tarfile : si'], config_dir
)
170 filename
= os
.path
.join(files_wc_dir
, 'foobar.lha')
171 check_proplist(filename
, ['auto : oui', 'lhafile : da', 'lzhfile : niet'],
173 filename
= os
.path
.join(files_wc_dir
, 'spacetest')
174 check_proplist(filename
, ['auto : oui', 'abc : def', 'ghi :'], config_dir
)
176 for filename
in filenames
:
177 check_proplist(os
.path
.join(files_wc_dir
, filename
), [], config_dir
)
180 #----------------------------------------------------------------------
182 def autoprops_add_no_none(sbox
):
183 "add: config=no, commandline=none"
185 autoprops_test(sbox
, 'add', 0, 0, '')
187 #----------------------------------------------------------------------
189 def autoprops_add_yes_none(sbox
):
190 "add: config=yes, commandline=none"
192 autoprops_test(sbox
, 'add', 1, 0, '')
194 #----------------------------------------------------------------------
196 def autoprops_add_no_yes(sbox
):
197 "add: config=no, commandline=yes"
199 autoprops_test(sbox
, 'add', 0, 1, '')
201 #----------------------------------------------------------------------
203 def autoprops_add_yes_yes(sbox
):
204 "add: config=yes, commandline=yes"
206 autoprops_test(sbox
, 'add', 1, 1, '')
208 #----------------------------------------------------------------------
210 def autoprops_add_no_no(sbox
):
211 "add: config=no, commandline=no"
213 autoprops_test(sbox
, 'add', 0, -1, '')
215 #----------------------------------------------------------------------
217 def autoprops_add_yes_no(sbox
):
218 "add: config=yes, commandline=no"
220 autoprops_test(sbox
, 'add', 1, -1, '')
222 #----------------------------------------------------------------------
224 def autoprops_imp_no_none(sbox
):
225 "import: config=no, commandline=none"
227 autoprops_test(sbox
, 'import', 0, 0, '')
229 #----------------------------------------------------------------------
231 def autoprops_imp_yes_none(sbox
):
232 "import: config=yes, commandline=none"
234 autoprops_test(sbox
, 'import', 1, 0, '')
236 #----------------------------------------------------------------------
238 def autoprops_imp_no_yes(sbox
):
239 "import: config=no, commandline=yes"
241 autoprops_test(sbox
, 'import', 0, 1, '')
243 #----------------------------------------------------------------------
245 def autoprops_imp_yes_yes(sbox
):
246 "import: config=yes, commandline=yes"
248 autoprops_test(sbox
, 'import', 1, 1, '')
250 #----------------------------------------------------------------------
252 def autoprops_imp_no_no(sbox
):
253 "import: config=no, commandline=no"
255 autoprops_test(sbox
, 'import', 0, -1, '')
257 #----------------------------------------------------------------------
259 def autoprops_imp_yes_no(sbox
):
260 "import: config=yes, commandline=no"
262 autoprops_test(sbox
, 'import', 1, -1, '')
264 #----------------------------------------------------------------------
266 def autoprops_add_dir(sbox
):
269 autoprops_test(sbox
, 'add', 1, 0, 'autodir')
271 #----------------------------------------------------------------------
273 def autoprops_imp_dir(sbox
):
276 autoprops_test(sbox
, 'import', 1, 0, 'autodir')
279 ########################################################################
283 # list all tests here, starting with None:
285 autoprops_add_no_none
,
286 autoprops_add_yes_none
,
287 autoprops_add_no_yes
,
288 autoprops_add_yes_yes
,
290 autoprops_add_yes_no
,
291 autoprops_imp_no_none
,
292 autoprops_imp_yes_none
,
293 autoprops_imp_no_yes
,
294 autoprops_imp_yes_yes
,
296 autoprops_imp_yes_no
,
301 if __name__
== '__main__':
302 svntest
.main
.run_tests(test_list
)