##// END OF EJS Templates
tests: vcs: remove duplicated base class in test_inmemchangesets...
Thomas De Schampheleire -
r7141:d8f820ac default
parent child Browse files
Show More
@@ -20,36 +20,27 b' from kallithea.lib.vcs.nodes import DirN'
20 from kallithea.lib.vcs.nodes import FileNode
20 from kallithea.lib.vcs.nodes import FileNode
21 from kallithea.lib.vcs.utils import safe_unicode
21 from kallithea.lib.vcs.utils import safe_unicode
22
22
23 from kallithea.tests.vcs.conf import get_new_dir
23 from kallithea.tests.vcs.base import _BackendTestMixin
24
24
25
25
26 class InMemoryChangesetTestMixin(object):
26 class InMemoryChangesetTestMixin(_BackendTestMixin):
27 """
28 This is a backend independent test case class which should be created
29 with ``type`` method.
30
27
31 It is required to set following attributes at subclass:
28 recreate_repo_per_test = True
32
29
33 - ``backend_alias``: alias of used backend (see ``vcs.BACKENDS``)
30 @classmethod
34 - ``repo_path``: path to the repository which would be created for set of
31 def _get_commits(cls):
35 tests
32 # Note: this is slightly different than the regular _get_commits methods
36 """
33 # as we don't actually return any commits. The creation of commits is
37
34 # handled in the tests themselves.
38 def get_backend(self):
35 cls.nodes = [
39 return vcs.get_backend(self.backend_alias)
40
41 def setup_method(self):
42 Backend = self.get_backend()
43 self.repo_path = get_new_dir(str(time.time()))
44 self.repo = Backend(self.repo_path, create=True)
45 self.imc = self.repo.in_memory_changeset
46 self.nodes = [
47 FileNode('foobar', content='Foo & bar'),
36 FileNode('foobar', content='Foo & bar'),
48 FileNode('foobar2', content='Foo & bar, doubled!'),
37 FileNode('foobar2', content='Foo & bar, doubled!'),
49 FileNode('foo bar with spaces', content=''),
38 FileNode('foo bar with spaces', content=''),
50 FileNode('foo/bar/baz', content='Inside'),
39 FileNode('foo/bar/baz', content='Inside'),
51 FileNode('foo/bar/file.bin', content='\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00;\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'),
40 FileNode('foo/bar/file.bin', content='\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00;\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'),
52 ]
41 ]
42 commits = []
43 return commits
53
44
54 def test_add(self):
45 def test_add(self):
55 rev_count = len(self.repo.revisions)
46 rev_count = len(self.repo.revisions)
@@ -333,9 +324,7 b' class InMemoryChangesetTestMixin(object)'
333 assert len(self.repo.revisions) == N
324 assert len(self.repo.revisions) == N
334
325
335 # Check commit number for recreated repo
326 # Check commit number for recreated repo
336 backend = self.get_backend()
327 assert len(self.repo.revisions) == N
337 repo = backend(self.repo_path)
338 assert len(repo.revisions) == N
339
328
340 def test_date_attr(self):
329 def test_date_attr(self):
341 node = FileNode('foobar.txt', content='Foobared!')
330 node = FileNode('foobar.txt', content='Foobared!')
@@ -347,63 +336,6 b' class InMemoryChangesetTestMixin(object)'
347 assert commit.date == date
336 assert commit.date == date
348
337
349
338
350 class BackendBaseTestCase(object):
351 """
352 Base test class for tests which requires repository.
353 """
354 backend_alias = 'hg'
355 commits = [
356 {
357 'message': 'Initial commit',
358 'author': 'Joe Doe <joe.doe@example.com>',
359 'date': datetime.datetime(2010, 1, 1, 20),
360 'added': [
361 FileNode('foobar', content='Foobar'),
362 FileNode('foobar2', content='Foobar II'),
363 FileNode('foo/bar/baz', content='baz here!'),
364 ],
365 },
366 ]
367
368 def get_backend(self):
369 return vcs.get_backend(self.backend_alias)
370
371 def get_commits(self):
372 """
373 Returns list of commits which builds repository for each tests.
374 """
375 if hasattr(self, 'commits'):
376 return self.commits
377
378 def get_new_repo_path(self):
379 """
380 Returns newly created repository's directory.
381 """
382 key = '%s-%s' % (self.backend_alias, str(time.time()))
383 repo_path = get_new_dir(key)
384 return repo_path
385
386 def setup_method(self):
387 Backend = self.get_backend()
388 self.backend_class = Backend
389 self.repo_path = self.get_new_repo_path()
390 self.repo = Backend(self.repo_path, create=True)
391 self.imc = self.repo.in_memory_changeset
392
393 for commit in self.get_commits():
394 for node in commit.get('added', []):
395 self.imc.add(FileNode(node.path, content=node.content))
396 for node in commit.get('changed', []):
397 self.imc.change(FileNode(node.path, content=node.content))
398 for node in commit.get('removed', []):
399 self.imc.remove(FileNode(node.path))
400 self.imc.commit(message=unicode(commit['message']),
401 author=unicode(commit['author']),
402 date=commit['date'])
403
404 self.tip = self.repo.get_changeset()
405
406
407 class TestGitInMemoryChangeset(InMemoryChangesetTestMixin):
339 class TestGitInMemoryChangeset(InMemoryChangesetTestMixin):
408 backend_alias = 'git'
340 backend_alias = 'git'
409
341
General Comments 0
You need to be logged in to leave comments. Login now