1
# Copyright (C) 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as published by
5
# the Free Software Foundation.
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
8
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
from bzrlib import osutils
28
34
from bzrlib.progress import _BaseProgressBar
29
35
from bzrlib.tests import (
39
TestCaseWithMemoryTransport,
33
40
TestCaseWithTransport,
434
441
self.assertEqual(self.test_home_dir, os.environ['HOME'])
444
class TestTestCaseWithMemoryTransport(TestCaseWithMemoryTransport):
446
def test_home_is_non_existant_dir_under_root(self):
447
"""The test_home_dir for TestCaseWithMemoryTransport is missing.
449
This is because TestCaseWithMemoryTransport is for tests that do not
450
need any disk resources: they should be hooked into bzrlib in such a
451
way that no global settings are being changed by the test (only a
452
few tests should need to do that), and having a missing dir as home is
453
an effective way to ensure that this is the case.
455
self.assertEqual(self.TEST_ROOT + "/MemoryTransportMissingHomeDir",
457
self.assertEqual(self.test_home_dir, os.environ['HOME'])
459
def test_cwd_is_TEST_ROOT(self):
460
self.assertEqual(self.test_dir, self.TEST_ROOT)
461
cwd = osutils.getcwd()
462
self.assertEqual(self.test_dir, cwd)
464
def test_make_branch_and_memory_tree(self):
465
"""In TestCaseWithMemoryTransport we should not make the branch on disk.
467
This is hard to comprehensively robustly test, so we settle for making
468
a branch and checking no directory was created at its relpath.
470
tree = self.make_branch_and_memory_tree('dir')
471
self.failIfExists('dir')
472
self.assertIsInstance(tree, memorytree.MemoryTree)
474
def test_make_branch_and_memory_tree_with_format(self):
475
"""make_branch_and_memory_tree should accept a format option."""
476
format = bzrdir.BzrDirMetaFormat1()
477
format.repository_format = repository.RepositoryFormat7()
478
tree = self.make_branch_and_memory_tree('dir', format=format)
479
self.failIfExists('dir')
480
self.assertIsInstance(tree, memorytree.MemoryTree)
481
self.assertEqual(format.repository_format.__class__,
482
tree.branch.repository._format.__class__)
437
485
class TestTestCaseWithTransport(TestCaseWithTransport):
438
486
"""Tests for the convenience functions TestCaseWithTransport introduces."""
456
504
def test_get_readonly_url_http(self):
457
505
from bzrlib.transport import get_transport
458
from bzrlib.transport.local import LocalRelpathServer
506
from bzrlib.transport.local import LocalURLServer
459
507
from bzrlib.transport.http import HttpServer, HttpTransportBase
460
self.transport_server = LocalRelpathServer
508
self.transport_server = LocalURLServer
461
509
self.transport_readonly_server = HttpServer
462
510
# calling get_readonly_transport() gives us a HTTP server instance.
463
511
url = self.get_readonly_url()
984
1032
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format,
985
1033
bzrlib.bzrdir.BzrDirFormat6)
987
def test_make_branch_and_mutable_tree(self):
1035
def test_make_branch_and_memory_tree(self):
988
1036
# we should be able to get a new branch and a mutable tree from
989
1037
# TestCaseWithTransport
990
1038
tree = self.make_branch_and_memory_tree('a')