~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

Merge bzr.urllib.keepalive

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
 
18
import stat
 
19
import sys
18
20
 
19
 
from bzrlib import tests
 
21
from bzrlib import (
 
22
    tests,
 
23
    urlutils,
 
24
    )
20
25
from bzrlib.bzrdir import BzrDir
21
26
from bzrlib.conflicts import (DuplicateEntry, DuplicateID, MissingParent,
22
27
                              UnversionedParent, ParentLoop, DeletingParent,)
30
35
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths, 
31
36
                              resolve_conflicts, cook_conflicts, 
32
37
                              find_interesting, build_tree, get_backup_name)
33
 
import bzrlib.urlutils as urlutils
 
38
 
34
39
 
35
40
class TestTreeTransform(TestCaseInTempDir):
36
41
 
535
540
        self.assertTrue(wt.is_executable('soc'))
536
541
        self.assertTrue(wt.is_executable('sac'))
537
542
 
 
543
    def test_preserve_mode(self):
 
544
        """File mode is preserved when replacing content"""
 
545
        if sys.platform == 'win32':
 
546
            raise TestSkipped('chmod has no effect on win32')
 
547
        transform, root = self.get_transform()
 
548
        transform.new_file('file1', root, 'contents', 'file1-id', True)
 
549
        transform.apply()
 
550
        self.assertTrue(self.wt.is_executable('file1-id'))
 
551
        transform, root = self.get_transform()
 
552
        file1_id = transform.trans_id_tree_file_id('file1-id')
 
553
        transform.delete_contents(file1_id)
 
554
        transform.create_file('contents2', file1_id)
 
555
        transform.apply()
 
556
        self.assertTrue(self.wt.is_executable('file1-id'))
 
557
 
 
558
    def test__set_mode_stats_correctly(self):
 
559
        """_set_mode stats to determine file mode."""
 
560
        if sys.platform == 'win32':
 
561
            raise TestSkipped('chmod has no effect on win32')
 
562
 
 
563
        stat_paths = []
 
564
        real_stat = os.stat
 
565
        def instrumented_stat(path):
 
566
            stat_paths.append(path)
 
567
            return real_stat(path)
 
568
 
 
569
        transform, root = self.get_transform()
 
570
 
 
571
        bar1_id = transform.new_file('bar', root, 'bar contents 1\n',
 
572
                                     file_id='bar-id-1', executable=False)
 
573
        transform.apply()
 
574
 
 
575
        transform, root = self.get_transform()
 
576
        bar1_id = transform.trans_id_tree_path('bar')
 
577
        bar2_id = transform.trans_id_tree_path('bar2')
 
578
        try:
 
579
            os.stat = instrumented_stat
 
580
            transform.create_file('bar2 contents\n', bar2_id, mode_id=bar1_id)
 
581
        finally:
 
582
            os.stat = real_stat
 
583
            transform.finalize()
 
584
 
 
585
        bar1_abspath = self.wt.abspath('bar')
 
586
        self.assertEqual([bar1_abspath], stat_paths)
 
587
 
538
588
 
539
589
class TransformGroup(object):
540
590
    def __init__(self, dirname):
731
781
        self.assertIs(os.path.lexists(this.wt.abspath('b/h1.OTHER')), False)
732
782
        self.assertEqual(this.wt.id2path('i'), pathjoin('b/i1.OTHER'))
733
783
 
 
784
 
734
785
class TestBuildTree(tests.TestCaseWithTransport):
735
786
 
736
787
    def test_build_tree(self):