/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_dir.py

  • Committer: Jelmer Vernooij
  • Date: 2018-04-02 14:59:43 UTC
  • mto: (0.200.1913 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180402145943-s5jmpbvvf1x42pao
Just don't touch the URL if it's already a valid URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
2
# Copyright (C) 2007 Canonical Ltd
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
"""Test the GitDir class"""
 
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
from dulwich.repo import Repo as GitRepo
 
23
import os
 
24
 
 
25
from .... import (
 
26
    controldir,
 
27
    errors,
 
28
    urlutils,
 
29
    )
 
30
from ....tests import TestSkipped
 
31
 
 
32
from .. import (
 
33
    dir,
 
34
    tests,
 
35
    workingtree,
 
36
    )
 
37
 
 
38
 
 
39
class TestGitDir(tests.TestCaseInTempDir):
 
40
 
 
41
    def test_get_head_branch_reference(self):
 
42
        GitRepo.init(".")
 
43
 
 
44
        gd = controldir.ControlDir.open('.')
 
45
        self.assertEquals(
 
46
            "%s,branch=master" %
 
47
                urlutils.local_path_to_url(os.path.abspath(".")),
 
48
            gd.get_branch_reference())
 
49
 
 
50
    def test_open_existing(self):
 
51
        GitRepo.init(".")
 
52
 
 
53
        gd = controldir.ControlDir.open('.')
 
54
        self.assertIsInstance(gd, dir.LocalGitDir)
 
55
 
 
56
    def test_open_workingtree(self):
 
57
        GitRepo.init(".")
 
58
 
 
59
        gd = controldir.ControlDir.open('.')
 
60
        raise TestSkipped
 
61
        wt = gd.open_workingtree()
 
62
        self.assertIsInstance(wt, workingtree.GitWorkingTree)
 
63
 
 
64
    def test_open_workingtree_bare(self):
 
65
        GitRepo.init_bare(".")
 
66
 
 
67
        gd = controldir.ControlDir.open('.')
 
68
        self.assertRaises(errors.NoWorkingTree, gd.open_workingtree)
 
69
 
 
70
    def test_git_file(self):
 
71
        gitrepo = GitRepo.init("blah", mkdir=True)
 
72
        self.build_tree_contents([('foo/', ), ('foo/.git', 'gitdir: ../blah/.git\n')])
 
73
 
 
74
        gd = controldir.ControlDir.open('foo')
 
75
        self.assertEqual(gd.control_url.rstrip('/'),
 
76
                         urlutils.local_path_to_url(os.path.abspath(gitrepo.controldir())))
 
77
 
 
78
 
 
79
class TestGitDirFormat(tests.TestCase):
 
80
 
 
81
    def setUp(self):
 
82
        super(TestGitDirFormat, self).setUp()
 
83
        self.format = dir.LocalGitControlDirFormat()
 
84
 
 
85
    def test_get_format_description(self):
 
86
        self.assertEquals("Local Git Repository",
 
87
                          self.format.get_format_description())
 
88
 
 
89
    def test_eq(self):
 
90
        format2 = dir.LocalGitControlDirFormat()
 
91
        self.assertEquals(self.format, format2)
 
92
        self.assertEquals(self.format, self.format)
 
93
        bzr_format = controldir.format_registry.make_controldir("default")
 
94
        self.assertNotEquals(self.format, bzr_format)
 
95