~ubuntu-branches/ubuntu/trusty/subversion/trusty-proposed

« back to all changes in this revision

Viewing changes to subversion/bindings/swig/python/tests/client.py

  • Committer: Package Import Robot
  • Author(s): Andy Whitcroft
  • Date: 2012-06-21 15:36:36 UTC
  • mfrom: (0.4.13 sid)
  • Revision ID: package-import@ubuntu.com-20120621153636-amqqmuidgwgxz1ly
Tags: 1.7.5-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Create pot file on build.
  - Build a python-subversion-dbg package.
  - Build-depend on python-dbg.
  - Build-depend on default-jre-headless/-jdk.
  - Do not apply java-build patch.
  - debian/rules: Manually create the doxygen output directory, otherwise
    we get weird build failures when running parallel builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import unittest, os, weakref, tempfile, types, setup_path
2
 
 
3
 
from svn import core, repos, fs, delta, client, wc
4
 
from svn.core import SubversionException
5
 
 
6
 
from trac.versioncontrol.tests.svn_fs import SubversionRepositoryTestSetup, \
7
 
  REPOS_PATH, REPOS_URL
8
 
from urlparse import urljoin
 
1
#
 
2
#
 
3
# Licensed to the Apache Software Foundation (ASF) under one
 
4
# or more contributor license agreements.  See the NOTICE file
 
5
# distributed with this work for additional information
 
6
# regarding copyright ownership.  The ASF licenses this file
 
7
# to you under the Apache License, Version 2.0 (the
 
8
# "License"); you may not use this file except in compliance
 
9
# with the License.  You may obtain a copy of the License at
 
10
#
 
11
#   http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
# Unless required by applicable law or agreed to in writing,
 
14
# software distributed under the License is distributed on an
 
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
16
# KIND, either express or implied.  See the License for the
 
17
# specific language governing permissions and limitations
 
18
# under the License.
 
19
#
 
20
#
 
21
import unittest, os, weakref, setup_path, utils
 
22
 
 
23
from svn import core, client, wc
 
24
 
 
25
try:
 
26
  # Python >=3.0
 
27
  from urllib.parse import urljoin
 
28
except ImportError:
 
29
  # Python <3.0
 
30
  from urlparse import urljoin
9
31
 
10
32
class SubversionClientTestCase(unittest.TestCase):
11
33
  """Test cases for the basic SWIG Subversion client layer"""
21
43
    self.change_author = author
22
44
    self.changed_paths = changed_paths
23
45
 
 
46
  def log_entry_receiver(self, log_entry, pool):
 
47
    """An implementation of svn_log_entry_receiver_t."""
 
48
    self.received_revisions.append(log_entry.revision)
 
49
 
24
50
  def setUp(self):
25
51
    """Set up authentication and client context"""
26
52
    self.client_ctx = client.svn_client_create_context()
42
68
 
43
69
    self.client_ctx.auth_baton = core.svn_auth_open(providers)
44
70
 
 
71
    self.temper = utils.Temper()
 
72
    (_, self.repos_path, self.repos_uri) = self.temper.alloc_known_repo(
 
73
      'trac/versioncontrol/tests/svnrepos.dump', suffix='-client')
 
74
 
 
75
  def tearDown(self):
 
76
    # We have to free client_ctx first, since it may be holding handles
 
77
    # to WC DBs
 
78
    del self.client_ctx
 
79
    self.temper.cleanup()
 
80
 
45
81
  def testBatonPlay(self):
46
82
    """Test playing with C batons"""
47
 
    self.client_ctx.log_msg_baton2 = self.client_ctx.auth_baton
48
 
    self.assertEquals(str(self.client_ctx.log_msg_baton2),
49
 
                      str(self.client_ctx.auth_baton))
50
 
    self.client_ctx.log_msg_baton2 = self.client_ctx.log_msg_baton2
51
 
    self.assertEquals(str(self.client_ctx.log_msg_baton2),
52
 
                      str(self.client_ctx.auth_baton))
 
83
    baton = lambda: 1
 
84
    weakref_baton = weakref.ref(baton)
 
85
    self.client_ctx.log_msg_baton2 = baton
 
86
    baton = None
 
87
    self.assertEquals(self.client_ctx.log_msg_baton2(), 1)
 
88
    self.assertEquals(weakref_baton()(), 1)
53
89
    self.client_ctx.log_msg_baton2 = None
54
90
    self.assertEquals(self.client_ctx.log_msg_baton2, None)
 
91
    self.assertEquals(weakref_baton(), None)
55
92
 
56
93
    # External objects should retain their current parent pool
57
94
    self.assertNotEquals(self.client_ctx._parent_pool,
122
159
    rev = core.svn_opt_revision_t()
123
160
    rev.kind = core.svn_opt_revision_head
124
161
 
125
 
    path = tempfile.mktemp('-checkout')
 
162
    path = self.temper.alloc_empty_dir('-checkout')
126
163
 
127
164
    self.assertRaises(ValueError, client.checkout2,
128
 
                      REPOS_URL, path, None, None, True, True,
 
165
                      self.repos_uri, path, None, None, True, True,
129
166
                      self.client_ctx)
130
167
 
131
 
    client.checkout2(REPOS_URL, path, rev, rev, True, True,
 
168
    client.checkout2(self.repos_uri, path, rev, rev, True, True,
132
169
            self.client_ctx)
133
170
 
134
171
  def test_info(self):
137
174
    # Run info
138
175
    revt = core.svn_opt_revision_t()
139
176
    revt.kind = core.svn_opt_revision_head
140
 
    client.info(REPOS_URL, revt, revt, self.info_receiver,
 
177
    client.info(self.repos_uri, revt, revt, self.info_receiver,
141
178
                False, self.client_ctx)
142
179
 
143
180
    # Check output from running info. This also serves to verify that
144
181
    # the internal 'info' object is still valid
145
 
    self.assertEqual(self.path, os.path.basename(REPOS_PATH))
 
182
    self.assertEqual(self.path, os.path.basename(self.repos_path))
146
183
    self.info.assert_valid()
147
 
    self.assertEqual(self.info.URL, REPOS_URL)
148
 
    self.assertEqual(self.info.repos_root_URL, REPOS_URL)
 
184
    self.assertEqual(self.info.URL, self.repos_uri)
 
185
    self.assertEqual(self.info.repos_root_URL, self.repos_uri)
149
186
 
150
187
  def test_mkdir_url(self):
151
188
    """Test svn_client_mkdir2 on a file:// URL"""
152
 
    dir = urljoin(REPOS_URL+"/", "dir1")
 
189
    directory = urljoin(self.repos_uri+"/", "dir1")
153
190
 
154
 
    commit_info = client.mkdir2((dir,), self.client_ctx)
 
191
    commit_info = client.mkdir2((directory,), self.client_ctx)
155
192
    self.assertEqual(commit_info.revision, 13)
156
193
    self.assertEqual(self.log_message_func_calls, 1)
157
194
 
158
195
  def test_mkdir_url_with_revprops(self):
159
196
    """Test svn_client_mkdir3 on a file:// URL, with added revprops"""
160
 
    dir = urljoin(REPOS_URL+"/", "some/deep/subdir")
 
197
    directory = urljoin(self.repos_uri+"/", "some/deep/subdir")
161
198
 
162
 
    commit_info = client.mkdir3((dir,), 1, {'customprop':'value'},
 
199
    commit_info = client.mkdir3((directory,), 1, {'customprop':'value'},
163
200
                                self.client_ctx)
164
 
    self.assertEqual(commit_info.revision, 14)
 
201
    self.assertEqual(commit_info.revision, 13)
165
202
    self.assertEqual(self.log_message_func_calls, 1)
166
203
 
167
204
  def test_log3_url(self):
168
205
    """Test svn_client_log3 on a file:// URL"""
169
 
    dir = urljoin(REPOS_URL+"/", "trunk/dir1")
 
206
    directory = urljoin(self.repos_uri+"/", "trunk/dir1")
170
207
 
171
208
    start = core.svn_opt_revision_t()
172
209
    end = core.svn_opt_revision_t()
173
210
    core.svn_opt_parse_revision(start, end, "4:0")
174
 
    client.log3((dir,), start, start, end, 1, True, False, self.log_receiver,
175
 
        self.client_ctx)
 
211
    client.log3((directory,), start, start, end, 1, True, False,
 
212
        self.log_receiver, self.client_ctx)
176
213
    self.assertEqual(self.change_author, "john")
177
214
    self.assertEqual(self.log_message, "More directories.")
178
215
    self.assertEqual(len(self.changed_paths), 3)
180
217
      self.assert_(dir in self.changed_paths)
181
218
      self.assertEqual(self.changed_paths[dir].action, 'A')
182
219
 
 
220
  def test_log5(self):
 
221
    """Test svn_client_log5."""
 
222
    start = core.svn_opt_revision_t()
 
223
    start.kind = core.svn_opt_revision_number
 
224
    start.value.number = 0
 
225
 
 
226
    end = core.svn_opt_revision_t()
 
227
    end.kind = core.svn_opt_revision_number
 
228
    end.value.number = 4
 
229
 
 
230
    rev_range = core.svn_opt_revision_range_t()
 
231
    rev_range.start = start
 
232
    rev_range.end = end
 
233
 
 
234
    self.received_revisions = []
 
235
 
 
236
    client.log5((self.repos_uri,), end, (rev_range,), 0, False, True, False, (),
 
237
        self.log_entry_receiver, self.client_ctx)
 
238
 
 
239
    self.assertEqual(self.received_revisions, range(0, 5))
 
240
 
183
241
  def test_uuid_from_url(self):
184
242
    """Test svn_client_uuid_from_url on a file:// URL"""
185
243
    self.assert_(isinstance(
186
 
                 client.uuid_from_url(REPOS_URL, self.client_ctx),
187
 
                 types.StringTypes))
 
244
                 client.uuid_from_url(self.repos_uri, self.client_ctx),
 
245
                 basestring))
188
246
 
189
247
  def test_url_from_path(self):
190
248
    """Test svn_client_url_from_path for a file:// URL"""
191
 
    self.assertEquals(client.url_from_path(REPOS_URL), REPOS_URL)
 
249
    self.assertEquals(client.url_from_path(self.repos_uri), self.repos_uri)
192
250
 
193
251
    rev = core.svn_opt_revision_t()
194
252
    rev.kind = core.svn_opt_revision_head
195
253
 
196
 
    path = tempfile.mktemp('-url_from_path')
 
254
    path = self.temper.alloc_empty_dir('-url_from_path')
197
255
 
198
 
    client.checkout2(REPOS_URL, path, rev, rev, True, True,
 
256
    client.checkout2(self.repos_uri, path, rev, rev, True, True,
199
257
                     self.client_ctx)
200
258
 
201
 
    self.assertEquals(client.url_from_path(path), REPOS_URL)
 
259
    self.assertEquals(client.url_from_path(path), self.repos_uri)
202
260
 
203
261
  def test_uuid_from_path(self):
204
262
    """Test svn_client_uuid_from_path."""
205
263
    rev = core.svn_opt_revision_t()
206
264
    rev.kind = core.svn_opt_revision_head
207
265
 
208
 
    path = tempfile.mktemp('uuid_from_path')
 
266
    path = self.temper.alloc_empty_dir('-uuid_from_path')
209
267
 
210
 
    client.checkout2(REPOS_URL, path, rev, rev, True, True,
 
268
    client.checkout2(self.repos_uri, path, rev, rev, True, True,
211
269
                     self.client_ctx)
212
270
 
213
271
    wc_adm = wc.adm_open3(None, path, False, 0, None)
214
272
 
215
273
    self.assertEquals(client.uuid_from_path(path, wc_adm, self.client_ctx),
216
 
                      client.uuid_from_url(REPOS_URL, self.client_ctx))
 
274
                      client.uuid_from_url(self.repos_uri, self.client_ctx))
217
275
 
218
276
    self.assert_(isinstance(client.uuid_from_path(path, wc_adm,
219
 
                            self.client_ctx), types.StringTypes))
 
277
                            self.client_ctx), basestring))
220
278
 
221
279
  def test_open_ra_session(self):
222
280
      """Test svn_client_open_ra_session()."""
223
 
      client.open_ra_session(REPOS_URL, self.client_ctx)
 
281
      client.open_ra_session(self.repos_uri, self.client_ctx)
224
282
 
225
283
 
226
284
  def test_info_file(self):
230
288
    # in the repository.
231
289
    rev = core.svn_opt_revision_t()
232
290
    rev.kind = core.svn_opt_revision_head
233
 
    wc_path = core.svn_path_canonicalize(tempfile.mktemp())
 
291
    wc_path = self.temper.alloc_empty_dir('-info_file')
234
292
 
235
 
    client.checkout2(REPOS_URL, wc_path, rev, rev, True, True,
 
293
    client.checkout2(self.repos_uri, wc_path, rev, rev, True, True,
236
294
                     self.client_ctx)
237
295
    adm_access = wc.adm_open3(None, wc_path, True, -1, None)
238
296
 
240
298
      # Test 1: Run info -r BASE. We expect the size value to be filled in.
241
299
      rev.kind = core.svn_opt_revision_base
242
300
      readme_path = '%s/trunk/README.txt' % wc_path
243
 
      readme_url = '%s/trunk/README.txt' % REPOS_URL
 
301
      readme_url = '%s/trunk/README.txt' % self.repos_uri
244
302
      client.info(readme_path, rev, rev, self.info_receiver,
245
303
                  False, self.client_ctx)
246
304
 
275
333
      self.assertEqual(self.info.size, 8)
276
334
    finally:
277
335
      wc.adm_close(adm_access)
278
 
      core.svn_io_remove_dir(wc_path)
 
336
 
 
337
  def test_merge_peg3(self):
 
338
    """Test svn_client_merge_peg3."""
 
339
    head = core.svn_opt_revision_t()
 
340
    head.kind = core.svn_opt_revision_head
 
341
    wc_path = self.temper.alloc_empty_dir('-merge_peg3')
 
342
 
 
343
    client.checkout3(self.repos_uri, wc_path, head, head, core.svn_depth_infinity,
 
344
                     True, False, self.client_ctx)
 
345
 
 
346
    # Let's try to backport a change from the v1x branch
 
347
    trunk_path = core.svn_dirent_join(wc_path, 'trunk')
 
348
    v1x_path = core.svn_dirent_join(wc_path, 'branches/v1x')
 
349
 
 
350
    start = core.svn_opt_revision_t()
 
351
    start.kind = core.svn_opt_revision_number
 
352
    start.value.number = 8
 
353
 
 
354
    end = core.svn_opt_revision_t()
 
355
    end.kind = core.svn_opt_revision_number
 
356
    end.value.number = 9
 
357
 
 
358
    rrange = core.svn_opt_revision_range_t()
 
359
    rrange.start = start
 
360
    rrange.end = end
 
361
 
 
362
    client.merge_peg3(v1x_path, (rrange,), end, trunk_path,
 
363
                      core.svn_depth_infinity, False, False, False, False,
 
364
                      None, self.client_ctx)
 
365
 
 
366
    # Did it take effect?
 
367
    readme_path_native = core.svn_dirent_local_style(
 
368
      core.svn_dirent_join(trunk_path, 'README.txt')
 
369
    )
 
370
 
 
371
    readme = open(readme_path_native, 'r')
 
372
    readme_text = readme.read()
 
373
    readme.close()
 
374
 
 
375
    self.assertEqual(readme_text, 'This is a test.\n')
 
376
 
 
377
  def test_platform_providers(self):
 
378
    providers = core.svn_auth_get_platform_specific_client_providers(None, None)
 
379
    # Not much more we can test in this minimal environment.
 
380
    self.assert_(isinstance(providers, list))
 
381
    self.assert_(not filter(lambda x:
 
382
                             not isinstance(x, core.svn_auth_provider_object_t),
 
383
                            providers))
279
384
 
280
385
def suite():
281
 
    return unittest.makeSuite(SubversionClientTestCase, 'test',
282
 
                              suiteClass=SubversionRepositoryTestSetup)
 
386
    return unittest.defaultTestLoader.loadTestsFromTestCase(
 
387
      SubversionClientTestCase)
283
388
 
284
389
if __name__ == '__main__':
285
390
    runner = unittest.TextTestRunner()