test/unittest_repositories.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Nov 2011 18:04:25 +0100
branchstable
changeset 791 5ac76ce656dd
parent 727 f865240f4ea7
child 1202 8807cd7adc32
permissions -rw-r--r--
update to cw 3.14 api. Closes #2063529

"""unit tests for apycot.repositories"""

from logilab.common import testlib

import os
from copy import copy

from utils import MockVCSFile as VCSFile

from apycotlib.repositories import *

def setUpModule():
    os.environ['APYCOT_ROOT'] = ''

def tearDownModule():
    del os.environ['APYCOT_ROOT']

class GetRepositoryTC(testlib.TestCase):
    def test(self):
        vcsfile = VCSFile('mercurial', source_url='http://www.labas.org')
        repo = get_repository({'repository': vcsfile, 'path': 'toto'})
        self.assert_(isinstance(repo, HGRepository))
        vcsfile = VCSFile('subversion', source_url='file://toto')
        repo = get_repository({'repository': vcsfile})
        self.assert_(isinstance(repo, SVNRepository))

class SVNRepositoryTC(testlib.TestCase):
    _tested_class = SVNRepository
    name = 'subversion'

    def test_co_command(self):
        vcsfile = VCSFile('subversion', source_url='file://test')
        repo_def = {'repository':vcsfile, 'path': 'path'}
        repo = SVNRepository(repo_def)
        self.assertEqual(repo_def, {})
        self.assertEqual(repo.co_command(),
                          'svn checkout --non-interactive -q file://test/path')
        repo_def = {'repository': vcsfile, 'path': 'path', 'branch':'branch'}
        repo = SVNRepository(repo_def)
        self.assertEqual(repo_def, {})
        self.assertEqual(repo.co_command(),
                          'svn checkout --non-interactive -q file://test/branch/path')

    def test_co_path(self):
        vcsfile = VCSFile('subversion', source_url='http://test.logilab.org/svn')
        repo = SVNRepository({'repository':vcsfile, 'path':'toto/path'})
        self.assertEqual(repo.co_path, 'path')

    def test_specials(self):
        vcsfile = VCSFile('subversion', source_url='test')
        repo = SVNRepository({'repository':vcsfile, 'path': 'toto/path'})
        self.assertEqual(repr(repo), 'subversion:test/toto/path')
        self.assert_(repo == copy(repo))
        vcsfile = VCSFile('subversion', source_url='test')
        repo2 = SVNRepository({'repository':vcsfile, 'path': 'tutu/path'})
        self.assert_(not repo == repo2)

class HGRepositoryTC(testlib.TestCase):
    def test_co_path(self):
        vcsfile = VCSFile('mercurial', path=os.path.join(self.datadir, 'badsyntax'))
        repo = HGRepository({'repository': vcsfile, 'path': 'common'})
        self.assertEqual(repo.co_path, 'badsyntax/common')
        repo = HGRepository({'repository': vcsfile, 'path': 'common/sub'})
        self.assertEqual(repo.co_path, 'badsyntax/common/sub')

if __name__ == '__main__':
    testlib.unittest_main()