/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_atomicfile.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import stat
21
21
import sys
22
22
 
23
 
from .. import (
 
23
from bzrlib import (
24
24
    atomicfile,
25
25
    errors,
26
26
    osutils,
 
27
    symbol_versioning,
27
28
    )
28
 
from . import TestCaseInTempDir, TestSkipped
 
29
from bzrlib.tests import TestCaseInTempDir, TestSkipped
29
30
 
30
31
 
31
32
class TestAtomicFile(TestCaseInTempDir):
33
34
    def test_commit(self):
34
35
        f = atomicfile.AtomicFile('test')
35
36
        self.assertPathDoesNotExist('test')
36
 
        f.write(b'foo\n')
 
37
        f.write('foo\n')
37
38
        f.commit()
38
39
 
39
40
        self.assertEqual(['test'], os.listdir('.'))
45
46
 
46
47
    def test_abort(self):
47
48
        f = atomicfile.AtomicFile('test')
48
 
        f.write(b'foo\n')
 
49
        f.write('foo\n')
49
50
        f.abort()
50
51
        self.assertEqual([], os.listdir('.'))
51
52
 
57
58
 
58
59
    def test_close(self):
59
60
        f = atomicfile.AtomicFile('test')
60
 
        f.write(b'foo\n')
 
61
        f.write('foo\n')
61
62
        # close on an open file is an abort
62
63
        f.close()
63
64
        self.assertEqual([], os.listdir('.'))
70
71
 
71
72
    def test_text_mode(self):
72
73
        f = atomicfile.AtomicFile('test', mode='wt')
73
 
        f.write(b'foo\n')
 
74
        f.write('foo\n')
74
75
        f.commit()
75
76
 
76
77
        contents = open('test', 'rb').read()
87
88
        if not self.can_sys_preserve_mode():
88
89
            raise TestSkipped("This test cannot be run on your platform")
89
90
        f = atomicfile.AtomicFile('test', mode='wb', new_mode=mode)
90
 
        f.write(b'foo\n')
 
91
        f.write('foo\n')
91
92
        f.commit()
92
93
        st = os.lstat('test')
93
94
        self.assertEqualMode(mode, stat.S_IMODE(st.st_mode))
94
95
 
95
96
    def test_mode_0666(self):
96
 
        self._test_mode(0o666)
 
97
        self._test_mode(0666)
97
98
 
98
99
    def test_mode_0664(self):
99
 
        self._test_mode(0o664)
100
 
 
101
 
    def test_mode_0660(self):
102
 
        self._test_mode(0o660)
103
 
 
104
 
    def test_mode_0660(self):
105
 
        self._test_mode(0o660)
 
100
        self._test_mode(0664)
 
101
 
 
102
    def test_mode_0660(self):
 
103
        self._test_mode(0660)
 
104
 
 
105
    def test_mode_0660(self):
 
106
        self._test_mode(0660)
106
107
 
107
108
    def test_mode_0640(self):
108
 
        self._test_mode(0o640)
 
109
        self._test_mode(0640)
109
110
 
110
111
    def test_mode_0600(self):
111
 
        self._test_mode(0o600)
 
112
        self._test_mode(0600)
112
113
 
113
114
    def test_mode_0400(self):
114
 
        self._test_mode(0o400)
 
115
        self._test_mode(0400)
115
116
        # Make it read-write again so cleanup doesn't complain
116
 
        os.chmod('test', 0o600)
 
117
        os.chmod('test', 0600)
117
118
 
118
119
    def test_no_mode(self):
119
120
        # The default file permissions should be based on umask
120
121
        umask = osutils.get_umask()
121
122
        f = atomicfile.AtomicFile('test', mode='wb')
122
 
        f.write(b'foo\n')
 
123
        f.write('foo\n')
123
124
        f.commit()
124
125
        st = os.lstat('test')
125
 
        self.assertEqualMode(0o666 & ~umask, stat.S_IMODE(st.st_mode))
 
126
        self.assertEqualMode(0666 & ~umask, stat.S_IMODE(st.st_mode))