~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-27 01:14:33 UTC
  • mfrom: (1686.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060427011433-95634ee1da8a2049
Merge in faster joins from weave to knit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from bzrlib.trace import mutter
35
35
from bzrlib.transport import get_transport
36
36
from bzrlib.transport.memory import MemoryTransport
 
37
from bzrlib.tsort import topo_sort
37
38
import bzrlib.versionedfile as versionedfile
38
39
from bzrlib.weave import WeaveFile
39
40
from bzrlib.weavefile import read_weave, write_weave
420
421
        # and should be a list
421
422
        self.assertTrue(isinstance(f.__class__.get_suffixes(), list))
422
423
 
 
424
    def build_graph(self, file, graph):
 
425
        for node in topo_sort(graph.items()):
 
426
            file.add_lines(node, graph[node], [])
 
427
 
423
428
    def test_get_graph(self):
424
429
        f = self.get_file()
425
 
        f.add_lines('v1', [], ['hello\n'])
426
 
        f.add_lines('v2', ['v1'], ['hello\n', 'world\n'])
427
 
        f.add_lines('v3', ['v2'], ['hello\n', 'cruel\n', 'world\n'])
428
 
        self.assertEqual({'v1': [],
429
 
                          'v2': ['v1'],
430
 
                          'v3': ['v2']},
431
 
                         f.get_graph())
 
430
        graph = {
 
431
            'v1': [],
 
432
            'v2': ['v1'],
 
433
            'v3': ['v2']}
 
434
        self.build_graph(f, graph)
 
435
        self.assertEqual(graph, f.get_graph())
 
436
    
 
437
    def test_get_graph_partial(self):
 
438
        f = self.get_file()
 
439
        complex_graph = {}
 
440
        simple_a = {
 
441
            'c': [],
 
442
            'b': ['c'],
 
443
            'a': ['b'],
 
444
            }
 
445
        complex_graph.update(simple_a)
 
446
        simple_b = {
 
447
            'c': [],
 
448
            'b': ['c'],
 
449
            }
 
450
        complex_graph.update(simple_b)
 
451
        simple_gam = {
 
452
            'c': [],
 
453
            'oo': [],
 
454
            'bar': ['oo', 'c'],
 
455
            'gam': ['bar'],
 
456
            }
 
457
        complex_graph.update(simple_gam)
 
458
        simple_b_gam = {}
 
459
        simple_b_gam.update(simple_gam)
 
460
        simple_b_gam.update(simple_b)
 
461
        self.build_graph(f, complex_graph)
 
462
        self.assertEqual(simple_a, f.get_graph(['a']))
 
463
        self.assertEqual(simple_b, f.get_graph(['b']))
 
464
        self.assertEqual(simple_gam, f.get_graph(['gam']))
 
465
        self.assertEqual(simple_b_gam, f.get_graph(['b', 'gam']))
432
466
 
433
467
    def test_get_parents(self):
434
468
        f = self.get_file()