/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 breezy/tests/test_atomicfile.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-04 19:17:13 UTC
  • mfrom: (0.193.10 trunk)
  • mto: This revision was merged to the branch mainline in revision 6778.
  • Revision ID: jelmer@jelmer.uk-20170604191713-hau7dfsqsl035slm
Bundle the cvs plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import stat
21
21
import sys
22
22
 
23
 
from bzrlib import (
 
23
from .. import (
24
24
    atomicfile,
25
25
    errors,
26
26
    osutils,
27
 
    symbol_versioning,
28
27
    )
29
 
from bzrlib.tests import TestCaseInTempDir, TestSkipped
 
28
from . import TestCaseInTempDir, TestSkipped
30
29
 
31
30
 
32
31
class TestAtomicFile(TestCaseInTempDir):
33
32
 
34
33
    def test_commit(self):
35
34
        f = atomicfile.AtomicFile('test')
36
 
        self.failIfExists('test')
 
35
        self.assertPathDoesNotExist('test')
37
36
        f.write('foo\n')
38
37
        f.commit()
39
38
 
94
93
        self.assertEqualMode(mode, stat.S_IMODE(st.st_mode))
95
94
 
96
95
    def test_mode_0666(self):
97
 
        self._test_mode(0666)
 
96
        self._test_mode(0o666)
98
97
 
99
98
    def test_mode_0664(self):
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)
 
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)
107
106
 
108
107
    def test_mode_0640(self):
109
 
        self._test_mode(0640)
 
108
        self._test_mode(0o640)
110
109
 
111
110
    def test_mode_0600(self):
112
 
        self._test_mode(0600)
 
111
        self._test_mode(0o600)
113
112
 
114
113
    def test_mode_0400(self):
115
 
        self._test_mode(0400)
 
114
        self._test_mode(0o400)
116
115
        # Make it read-write again so cleanup doesn't complain
117
 
        os.chmod('test', 0600)
 
116
        os.chmod('test', 0o600)
118
117
 
119
118
    def test_no_mode(self):
120
119
        # The default file permissions should be based on umask
123
122
        f.write('foo\n')
124
123
        f.commit()
125
124
        st = os.lstat('test')
126
 
        self.assertEqualMode(0666 & ~umask, stat.S_IMODE(st.st_mode))
127
 
 
128
 
    def test_closed(self):
129
 
        local_warnings = []
130
 
        def capture_warnings(msg, cls, stacklevel=None):
131
 
            self.assertEqual(cls, DeprecationWarning)
132
 
            local_warnings.append(msg)
133
 
 
134
 
        method = symbol_versioning.warn
135
 
        try:
136
 
            symbol_versioning.set_warning_method(capture_warnings)
137
 
            f = atomicfile.AtomicFile('test', mode='wb')
138
 
            self.assertEqual(False, f.closed)
139
 
            f.abort()
140
 
            self.assertEqual(True, f.closed)
141
 
 
142
 
            f = atomicfile.AtomicFile('test', mode='wb')
143
 
            f.close()
144
 
            self.assertEqual(True, f.closed)
145
 
 
146
 
            f = atomicfile.AtomicFile('test', mode='wb')
147
 
            f.commit()
148
 
            self.assertEqual(True, f.closed)
149
 
        finally:
150
 
            symbol_versioning.set_warning_method(method)
151
 
 
152
 
        txt = 'AtomicFile.closed deprecated in bzr 0.10'
153
 
        self.assertEqual([txt]*4, local_warnings)
 
125
        self.assertEqualMode(0o666 & ~umask, stat.S_IMODE(st.st_mode))