/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 bzrlib/tests/test_graph.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-12 14:29:32 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib.tests import TestCase
 
2
from bzrlib.graph import node_distances, nodes_by_distance, Graph
 
3
 
 
4
class TestBase(TestCase):
 
5
 
 
6
    def edge_add(self, *args):
 
7
        for start, end in zip(args[:-1], args[1:]):
 
8
            if start not in self.graph:
 
9
                self.graph[start] = {}
 
10
            if end not in self.graph:
 
11
                self.graph[end] = {}
 
12
            self.graph[start][end] = 1
 
13
 
 
14
    def setUp(self):
 
15
        TestCase.setUp(self)
 
16
        self.graph = {}
 
17
        self.edge_add('A', 'B', 'C', 'D')
 
18
        self.edge_add('A', 'E', 'F', 'C')
 
19
        self.edge_add('A', 'G', 'H', 'I', 'B')
 
20
        self.edge_add('A', 'J', 'K', 'L', 'M', 'N')
 
21
        self.edge_add('O', 'N')
 
22
 
 
23
    def node_descendants(self):
 
24
        descendants = {'A':set()}
 
25
        for node in self.graph:
 
26
            for ancestor in self.graph[node]:
 
27
                if ancestor not in descendants:
 
28
                    descendants[ancestor] = set()
 
29
                descendants[ancestor].add(node)
 
30
        return descendants
 
31
    
 
32
    def test_distances(self):
 
33
        descendants = self.node_descendants()
 
34
        distances = node_distances(self.graph, descendants, 'A')
 
35
        nodes = nodes_by_distance(distances)
 
36
        self.assertEqual(nodes[0], 'D')
 
37
        self.assert_(nodes[1] in ('N', 'C'))
 
38
        self.assert_(nodes[2] in ('N', 'C'))
 
39
        self.assert_(nodes[3] in ('B', 'M'))
 
40
        self.assert_(nodes[4] in ('B', 'M'))
 
41
 
 
42
        #Ensure we don't shortcut through B when there's only a difference of
 
43
        # 1 in distance
 
44
        self.graph = {}
 
45
        self.edge_add('A', 'B', 'C')
 
46
        self.edge_add('A', 'D', 'E', 'C')
 
47
        descendants = self.node_descendants()
 
48
        distances = node_distances(self.graph, descendants, 'A')
 
49
        self.assertEqual(distances['C'], 3)
 
50
 
 
51
 
 
52
class TestGraph(TestCase):
 
53
 
 
54
    def test_get_descendants(self):
 
55
        # Graph objects let you get a descendants graph in 
 
56
        # node: {direct-children:distance} which contains
 
57
        # known children, including ghost children
 
58
        graph = Graph()
 
59
        graph.add_ghost('ghost')
 
60
        graph.add_node('rev1', ['ghost'])
 
61
        # check the result contains ghosts:
 
62
        self.assertEqual({'ghost': {'rev1': 1}, 'rev1': {}},
 
63
                         graph.get_descendants())