~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to read_changeset.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-07-01 02:12:45 UTC
  • mto: (0.5.85) (1185.82.1 bzr-w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: aaron.bentley@utoronto.ca-20050701021245-8826b91295a3e5f8
Implemented iteration over ids

Show diffs side-by-side

added added

removed removed

Lines of Context:
522
522
            return patch_original
523
523
        return patched_file(file_patch, patch_original)
524
524
 
 
525
    def __iter__(self):
 
526
        for file_id in self._new_id_r.iterkeys():
 
527
            yield file_id
 
528
        for file_id in self.base_tree:
 
529
            if self.id2path(file_id) is None:
 
530
                continue
 
531
            yield file_id
 
532
 
 
533
 
525
534
def patched_file(file_patch, original):
526
535
    from bzrlib.patch import patch
527
536
    from tempfile import mkdtemp
560
569
            self.ids = {}
561
570
            self.contents = {}
562
571
 
 
572
        def __iter__(self):
 
573
            return self.paths.iterkeys()
 
574
 
563
575
        def add_dir(self, file_id, path):
564
576
            self.paths[file_id] = path
565
577
            self.ids[path] = file_id
704
716
            assert ctree.id2path("c") is None
705
717
            assert ctree.path2id("grandparent/parent/file") is None
706
718
 
 
719
        def sorted_ids(self, tree):
 
720
            ids = list(tree)
 
721
            ids.sort()
 
722
            return ids
 
723
 
 
724
        def test_iteration(self):
 
725
            """Ensure that iteration through ids works properly"""
 
726
            ctree = self.make_tree_1()[0]
 
727
            assert self.sorted_ids(ctree) == ['a', 'b', 'c', 'd']
 
728
            ctree.note_deletion("grandparent/parent/file")
 
729
            ctree.note_id("e", "grandparent/alt_parent/fool")
 
730
            assert self.sorted_ids(ctree) == ['a', 'b', 'd', 'e']
 
731
            
 
732
 
707
733
    patchesTestSuite = unittest.makeSuite(CTreeTester,'test_')
708
734
    runner = unittest.TextTestRunner()
709
735
    runner.run(patchesTestSuite)