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"
57
# contents of the file 'config'
58
config_contents = '''\
60
enable-auto-props = %s
66
foobar.lha = lhafile=da;lzhfile=niet
67
spacetest = abc = def ; ghi = ; = j
69
''' % (enable_flag and 'yes' or 'no')
71
svntest.main.create_config_dir(config_dir, config_contents)
73
#----------------------------------------------------------------------
75
def create_test_file(dir, name):
78
fd = open(os.path.join(dir, name), 'w')
79
fd.write('foo\nbar\nbaz\n')
82
#----------------------------------------------------------------------
84
def autoprops_test(sbox, cmd, cfgenable, clienable, subdir):
85
"""configurable autoprops test.
87
CMD is the subcommand to test: 'import' or 'add'
88
if CFGENABLE is true, enable autoprops in the config file, else disable
89
if CLIENABLE == 1: --auto-props is added to the command line
91
-1: --no-auto-props is added to command line
92
if string SUBDIR is not empty files are created in that subdir and the
93
directory is added/imported"""
100
tmp_dir = os.path.abspath(svntest.main.temp_dir)
101
config_dir = os.path.join(tmp_dir, 'autoprops_config')
102
repos_url = svntest.main.current_repo_url
103
svntest.main.set_config_dir(config_dir)
105
# initialize parameters
107
parameters = ['import', '--username', svntest.main.wc_author,
108
'--password', svntest.main.wc_passwd, '-m', 'bla']
114
parameters = parameters + ['--config-dir', config_dir]
116
create_config(config_dir, cfgenable)
118
# add comandline flags
120
parameters = parameters + ['--auto-props']
122
elif clienable == -1:
123
parameters = parameters + ['--no-auto-props']
126
enable_flag = cfgenable
128
# setup subdirectory if needed
130
files_dir = os.path.join(files_dir, subdir)
131
files_wc_dir = os.path.join(wc_dir, subdir)
132
os.makedirs(files_dir)
134
files_wc_dir = wc_dir
137
filenames = ['foo.h',
143
for filename in filenames:
144
create_test_file(files_dir, filename)
147
# add/import the files
148
for filename in filenames:
149
path = os.path.join(files_dir, filename)
151
tmp_params = parameters + [path, repos_url + '/' + filename]
153
tmp_params = parameters + [path]
154
svntest.main.run_svn(None, *tmp_params)
156
# add/import subdirectory
158
parameters = parameters + [files_dir, repos_url]
160
parameters = parameters + [files_wc_dir]
161
svntest.main.run_svn(None, *parameters)
163
# do an svn co if needed
165
svntest.main.run_svn(None, 'checkout', repos_url, files_wc_dir)
167
# check the properties
169
filename = os.path.join(files_wc_dir, 'foo.h')
170
check_proplist(filename, ['auto : oui'])
171
filename = os.path.join(files_wc_dir, 'foo.c')
172
check_proplist(filename, ['auto : oui', 'cfile : yes'])
173
filename = os.path.join(files_wc_dir, 'foo.jpg')
174
check_proplist(filename, ['auto : oui', 'jpgfile : ja'])
175
filename = os.path.join(files_wc_dir, 'fubar.tar')
176
check_proplist(filename, ['auto : oui', 'tarfile : si'])
177
filename = os.path.join(files_wc_dir, 'foobar.lha')
178
check_proplist(filename, ['auto : oui', 'lhafile : da', 'lzhfile : niet'])
179
filename = os.path.join(files_wc_dir, 'spacetest')
180
check_proplist(filename, ['auto : oui', 'abc : def', 'ghi :'])
182
for filename in filenames:
183
check_proplist(os.path.join(files_wc_dir, filename), [])
186
#----------------------------------------------------------------------
188
def autoprops_add_no_none(sbox):
189
"add: config=no, commandline=none"
191
autoprops_test(sbox, 'add', 0, 0, '')
193
#----------------------------------------------------------------------
195
def autoprops_add_yes_none(sbox):
196
"add: config=yes, commandline=none"
198
autoprops_test(sbox, 'add', 1, 0, '')
200
#----------------------------------------------------------------------
202
def autoprops_add_no_yes(sbox):
203
"add: config=no, commandline=yes"
205
autoprops_test(sbox, 'add', 0, 1, '')
207
#----------------------------------------------------------------------
209
def autoprops_add_yes_yes(sbox):
210
"add: config=yes, commandline=yes"
212
autoprops_test(sbox, 'add', 1, 1, '')
214
#----------------------------------------------------------------------
216
def autoprops_add_no_no(sbox):
217
"add: config=no, commandline=no"
219
autoprops_test(sbox, 'add', 0, -1, '')
221
#----------------------------------------------------------------------
223
def autoprops_add_yes_no(sbox):
224
"add: config=yes, commandline=no"
226
autoprops_test(sbox, 'add', 1, -1, '')
228
#----------------------------------------------------------------------
230
def autoprops_imp_no_none(sbox):
231
"import: config=no, commandline=none"
233
autoprops_test(sbox, 'import', 0, 0, '')
235
#----------------------------------------------------------------------
237
def autoprops_imp_yes_none(sbox):
238
"import: config=yes, commandline=none"
240
autoprops_test(sbox, 'import', 1, 0, '')
242
#----------------------------------------------------------------------
244
def autoprops_imp_no_yes(sbox):
245
"import: config=no, commandline=yes"
247
autoprops_test(sbox, 'import', 0, 1, '')
249
#----------------------------------------------------------------------
251
def autoprops_imp_yes_yes(sbox):
252
"import: config=yes, commandline=yes"
254
autoprops_test(sbox, 'import', 1, 1, '')
256
#----------------------------------------------------------------------
258
def autoprops_imp_no_no(sbox):
259
"import: config=no, commandline=no"
261
autoprops_test(sbox, 'import', 0, -1, '')
263
#----------------------------------------------------------------------
265
def autoprops_imp_yes_no(sbox):
266
"import: config=yes, commandline=no"
268
autoprops_test(sbox, 'import', 1, -1, '')
270
#----------------------------------------------------------------------
272
def autoprops_add_dir(sbox):
275
autoprops_test(sbox, 'add', 1, 0, 'autodir')
277
#----------------------------------------------------------------------
279
def autoprops_imp_dir(sbox):
282
autoprops_test(sbox, 'import', 1, 0, 'autodir')
285
########################################################################
289
# list all tests here, starting with None:
291
autoprops_add_no_none,
292
autoprops_add_yes_none,
293
autoprops_add_no_yes,
294
autoprops_add_yes_yes,
296
autoprops_add_yes_no,
297
autoprops_imp_no_none,
298
autoprops_imp_yes_none,
299
autoprops_imp_no_yes,
300
autoprops_imp_yes_yes,
302
autoprops_imp_yes_no,
307
if __name__ == '__main__':
308
svntest.main.run_tests(test_list)