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
######################################################################
20
import string, sys, re, os, os.path, shutil
27
Skip = svntest.testcase.Skip
28
XFail = svntest.testcase.XFail
29
Item = svntest.wc.StateItem
33
def check_proplist(path, exp_out):
34
"""Verify that property list on PATH has a value of EXP_OUT"""
35
out, err = svntest.main.run_svn(None, 'proplist', '--verbose', path)
39
out2 = out2 + [string.strip(line)]
43
print "Expected properties:", exp_out
44
print "Actual properties: ", out2
45
print "Actual proplist output:", out
49
######################################################################
52
#----------------------------------------------------------------------
54
def create_config(config_dir, enable_flag):
55
"create config directories and files"
58
cfgfile_cfg = os.path.join(config_dir, 'config')
59
cfgfile_srv = os.path.join(config_dir, 'server')
61
# create the directory
62
if not os.path.isdir(config_dir):
63
os.makedirs(config_dir)
65
# create the file 'config'
66
fd = open(cfgfile_cfg, 'w')
67
fd.write('[miscellany]\n')
69
fd.write('enable-auto-props = yes\n')
71
fd.write('enable-auto-props = no\n')
73
fd.write('[auto-props]\n')
74
fd.write('*.c = cfile=yes\n')
75
fd.write('*.jpg = jpgfile=ja\n')
76
fd.write('fubar* = tarfile=si\n')
77
fd.write('foobar.lha = lhafile=da;lzhfile=niet\n')
78
fd.write('spacetest = abc = def ; ghi = ; = j \n')
79
fd.write('* = auto=oui\n')
83
# create the file 'server'
84
fd = open(cfgfile_srv, 'w')
89
#----------------------------------------------------------------------
91
def create_test_file(dir, name):
94
fd = open(os.path.join(dir, name), 'w')
95
fd.write('foo\nbar\nbaz\n')
98
#----------------------------------------------------------------------
100
def autoprops_test(sbox, cmd, cfgenable, clienable, subdir):
101
"""configurable autoprops test.
103
CMD is the subcommand to test: 'import' or 'add'
104
if CFGENABLE is true, enable autoprops in the config file, else disable
105
if CLIENABLE == 1: --auto-props is added to the command line
107
-1: --no-auto-props is added to command line
108
if string SUBDIR is not empty files are created in that subdir and the
109
directory is added/imported"""
116
tmp_dir = os.path.abspath(svntest.main.temp_dir)
117
config_dir = os.path.join(tmp_dir, 'autoprops_config')
118
repos_url = svntest.main.current_repo_url
119
svntest.main.set_config_dir(config_dir)
121
# initialize parameters
123
parameters = ['import', '--username', svntest.main.wc_author,
124
'--password', svntest.main.wc_passwd, '-m', 'bla']
130
parameters = parameters + ['--config-dir', config_dir]
132
create_config(config_dir, cfgenable)
134
# add comandline flags
136
parameters = parameters + ['--auto-props']
138
elif clienable == -1:
139
parameters = parameters + ['--no-auto-props']
142
enable_flag = cfgenable
144
# setup subdirectory if needed
146
files_dir = os.path.join(files_dir, subdir)
147
files_wc_dir = os.path.join(wc_dir, subdir)
148
os.makedirs(files_dir)
150
files_wc_dir = wc_dir
153
filenames = ['foo.h',
159
for filename in filenames:
160
create_test_file(files_dir, filename)
163
# add/import the files
164
for filename in filenames:
165
path = os.path.join(files_dir, filename)
167
tmp_params = parameters + [path, repos_url + '/' + filename]
169
tmp_params = parameters + [path]
170
svntest.main.run_svn(None, *tmp_params)
172
# add/import subdirectory
174
parameters = parameters + [files_dir, repos_url]
176
parameters = parameters + [files_wc_dir]
177
svntest.main.run_svn(None, *parameters)
179
# do an svn co if needed
181
svntest.main.run_svn(None, 'checkout', repos_url, files_wc_dir)
183
# check the properties
185
filename = os.path.join(files_wc_dir, 'foo.h')
186
check_proplist(filename, ['auto : oui'])
187
filename = os.path.join(files_wc_dir, 'foo.c')
188
check_proplist(filename, ['auto : oui', 'cfile : yes'])
189
filename = os.path.join(files_wc_dir, 'foo.jpg')
190
check_proplist(filename, ['auto : oui', 'jpgfile : ja'])
191
filename = os.path.join(files_wc_dir, 'fubar.tar')
192
check_proplist(filename, ['auto : oui', 'tarfile : si'])
193
filename = os.path.join(files_wc_dir, 'foobar.lha')
194
check_proplist(filename, ['auto : oui', 'lhafile : da', 'lzhfile : niet'])
195
filename = os.path.join(files_wc_dir, 'spacetest')
196
check_proplist(filename, ['auto : oui', 'abc : def', 'ghi :'])
198
for filename in filenames:
199
check_proplist(os.path.join(files_wc_dir, filename), [])
202
#----------------------------------------------------------------------
204
def autoprops_add_no_none(sbox):
205
"add: config=no, commandline=none"
207
autoprops_test(sbox, 'add', 0, 0, '')
209
#----------------------------------------------------------------------
211
def autoprops_add_yes_none(sbox):
212
"add: config=yes, commandline=none"
214
autoprops_test(sbox, 'add', 1, 0, '')
216
#----------------------------------------------------------------------
218
def autoprops_add_no_yes(sbox):
219
"add: config=no, commandline=yes"
221
autoprops_test(sbox, 'add', 0, 1, '')
223
#----------------------------------------------------------------------
225
def autoprops_add_yes_yes(sbox):
226
"add: config=yes, commandline=yes"
228
autoprops_test(sbox, 'add', 1, 1, '')
230
#----------------------------------------------------------------------
232
def autoprops_add_no_no(sbox):
233
"add: config=no, commandline=no"
235
autoprops_test(sbox, 'add', 0, -1, '')
237
#----------------------------------------------------------------------
239
def autoprops_add_yes_no(sbox):
240
"add: config=yes, commandline=no"
242
autoprops_test(sbox, 'add', 1, -1, '')
244
#----------------------------------------------------------------------
246
def autoprops_imp_no_none(sbox):
247
"import: config=no, commandline=none"
249
autoprops_test(sbox, 'import', 0, 0, '')
251
#----------------------------------------------------------------------
253
def autoprops_imp_yes_none(sbox):
254
"import: config=yes, commandline=none"
256
autoprops_test(sbox, 'import', 1, 0, '')
258
#----------------------------------------------------------------------
260
def autoprops_imp_no_yes(sbox):
261
"import: config=no, commandline=yes"
263
autoprops_test(sbox, 'import', 0, 1, '')
265
#----------------------------------------------------------------------
267
def autoprops_imp_yes_yes(sbox):
268
"import: config=yes, commandline=yes"
270
autoprops_test(sbox, 'import', 1, 1, '')
272
#----------------------------------------------------------------------
274
def autoprops_imp_no_no(sbox):
275
"import: config=no, commandline=no"
277
autoprops_test(sbox, 'import', 0, -1, '')
279
#----------------------------------------------------------------------
281
def autoprops_imp_yes_no(sbox):
282
"import: config=yes, commandline=no"
284
autoprops_test(sbox, 'import', 1, -1, '')
286
#----------------------------------------------------------------------
288
def autoprops_add_dir(sbox):
291
autoprops_test(sbox, 'add', 1, 0, 'autodir')
293
#----------------------------------------------------------------------
295
def autoprops_imp_dir(sbox):
298
autoprops_test(sbox, 'import', 1, 0, 'autodir')
301
########################################################################
305
# list all tests here, starting with None:
307
autoprops_add_no_none,
308
autoprops_add_yes_none,
309
autoprops_add_no_yes,
310
autoprops_add_yes_yes,
312
autoprops_add_yes_no,
313
autoprops_imp_no_none,
314
autoprops_imp_yes_none,
315
autoprops_imp_no_yes,
316
autoprops_imp_yes_yes,
318
autoprops_imp_yes_no,
323
if __name__ == '__main__':
324
svntest.main.run_tests(test_list)