##// END OF EJS Templates
tests: add missing b prefixes in test-atomictempfile.py...
Augie Fackler -
r36634:a007db19 default
parent child Browse files
Show More
@@ -17,8 +17,8 b' if pycompat.ispy3:'
17 17
18 18 class testatomictempfile(unittest.TestCase):
19 19 def setUp(self):
20 self._testdir = tempfile.mkdtemp('atomictempfiletest')
21 self._filename = os.path.join(self._testdir, 'testfilename')
20 self._testdir = tempfile.mkdtemp(b'atomictempfiletest')
21 self._filename = os.path.join(self._testdir, b'testfilename')
22 22
23 23 def tearDown(self):
24 24 shutil.rmtree(self._testdir, True)
@@ -28,14 +28,14 b' class testatomictempfile(unittest.TestCa'
28 28 self.assertFalse(os.path.isfile(self._filename))
29 29 tempfilename = file._tempname
30 30 self.assertTrue(tempfilename in glob.glob(
31 os.path.join(self._testdir, '.testfilename-*')))
31 os.path.join(self._testdir, b'.testfilename-*')))
32 32
33 33 file.write(b'argh\n')
34 34 file.close()
35 35
36 36 self.assertTrue(os.path.isfile(self._filename))
37 37 self.assertTrue(tempfilename not in glob.glob(
38 os.path.join(self._testdir, '.testfilename-*')))
38 os.path.join(self._testdir, b'.testfilename-*')))
39 39
40 40 # discard() removes the temp file without making the write permanent
41 41 def testdiscard(self):
@@ -46,7 +46,7 b' class testatomictempfile(unittest.TestCa'
46 46 file.discard()
47 47
48 48 self.assertFalse(os.path.isfile(self._filename))
49 self.assertTrue(basename not in os.listdir('.'))
49 self.assertTrue(basename not in os.listdir(b'.'))
50 50
51 51 # if a programmer screws up and passes bad args to atomictempfile, they
52 52 # get a plain ordinary TypeError, not infinite recursion
@@ -58,7 +58,7 b' class testatomictempfile(unittest.TestCa'
58 58 def testcheckambig(self):
59 59 def atomicwrite(checkambig):
60 60 f = atomictempfile(self._filename, checkambig=checkambig)
61 f.write('FOO')
61 f.write(b'FOO')
62 62 f.close()
63 63
64 64 # try some times, because reproduction of ambiguity depends on
@@ -97,27 +97,27 b' class testatomictempfile(unittest.TestCa'
97 97 def testread(self):
98 98 with open(self._filename, 'wb') as f:
99 99 f.write(b'foobar\n')
100 file = atomictempfile(self._filename, mode='rb')
100 file = atomictempfile(self._filename, mode=b'rb')
101 101 self.assertTrue(file.read(), b'foobar\n')
102 102 file.discard()
103 103
104 104 def testcontextmanagersuccess(self):
105 105 """When the context closes, the file is closed"""
106 with atomictempfile('foo') as f:
107 self.assertFalse(os.path.isfile('foo'))
106 with atomictempfile(b'foo') as f:
107 self.assertFalse(os.path.isfile(b'foo'))
108 108 f.write(b'argh\n')
109 self.assertTrue(os.path.isfile('foo'))
109 self.assertTrue(os.path.isfile(b'foo'))
110 110
111 111 def testcontextmanagerfailure(self):
112 112 """On exception, the file is discarded"""
113 113 try:
114 with atomictempfile('foo') as f:
115 self.assertFalse(os.path.isfile('foo'))
114 with atomictempfile(b'foo') as f:
115 self.assertFalse(os.path.isfile(b'foo'))
116 116 f.write(b'argh\n')
117 117 raise ValueError
118 118 except ValueError:
119 119 pass
120 self.assertFalse(os.path.isfile('foo'))
120 self.assertFalse(os.path.isfile(b'foo'))
121 121
122 122 if __name__ == '__main__':
123 123 import silenttestrunner
General Comments 0
You need to be logged in to leave comments. Login now