Mercurial > hg-stable
annotate tests/test-atomictempfile.py @ 36963:a8d540d2628c
contrib: fix a subtle bug in check-code's regex rewriting
We rewrite `\s` to `[ \t]` when preparing our regular expressions, but
we previously weren't working to avoid having nested sets. Previously,
Python let this slide without incident, but in Python 3.7 wants to
make sure you meant an actual [ in a set, and so this warns. This
appears to be fortunate for us, because `[\s(]` was getting rewritten
to be `[[ \t](]` which doesn't actually match what we expected. See
preceding changes that were revealed to be necessary after
implementing this fix.
Differential Revision: https://phab.mercurial-scm.org/D2866
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 14 Mar 2018 14:05:45 -0400 |
parents | ffa3026d4196 |
children | 2372284d9457 |
rev | line source |
---|---|
29194
3bea82dd4c4e
py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29188
diff
changeset
|
1 from __future__ import absolute_import |
3bea82dd4c4e
py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29188
diff
changeset
|
2 |
3bea82dd4c4e
py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29188
diff
changeset
|
3 import glob |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
4 import os |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
5 import shutil |
36789
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36645
diff
changeset
|
6 import stat |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
7 import tempfile |
18666
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
8 import unittest |
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
9 |
29194
3bea82dd4c4e
py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29188
diff
changeset
|
10 from mercurial import ( |
36318
3ec9afb951a0
py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32319
diff
changeset
|
11 pycompat, |
29194
3bea82dd4c4e
py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29188
diff
changeset
|
12 util, |
3bea82dd4c4e
py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29188
diff
changeset
|
13 ) |
3bea82dd4c4e
py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29188
diff
changeset
|
14 atomictempfile = util.atomictempfile |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
15 |
36318
3ec9afb951a0
py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32319
diff
changeset
|
16 if pycompat.ispy3: |
3ec9afb951a0
py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32319
diff
changeset
|
17 xrange = range |
3ec9afb951a0
py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32319
diff
changeset
|
18 |
18666
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
19 class testatomictempfile(unittest.TestCase): |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
20 def setUp(self): |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
21 self._testdir = tempfile.mkdtemp(b'atomictempfiletest') |
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
22 self._filename = os.path.join(self._testdir, b'testfilename') |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
23 |
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
24 def tearDown(self): |
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
25 shutil.rmtree(self._testdir, True) |
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
26 |
29392
f21286e48bc6
atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents:
29391
diff
changeset
|
27 def testsimple(self): |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
28 file = atomictempfile(self._filename) |
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
29 self.assertFalse(os.path.isfile(self._filename)) |
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
30 tempfilename = file._tempname |
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
31 self.assertTrue(tempfilename in glob.glob( |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
32 os.path.join(self._testdir, b'.testfilename-*'))) |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
33 |
29188
f00f1de16454
tests: mark test-atomictempfile.py write as binary
timeless <timeless@mozdev.org>
parents:
18666
diff
changeset
|
34 file.write(b'argh\n') |
18666
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
35 file.close() |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
36 |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
37 self.assertTrue(os.path.isfile(self._filename)) |
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
38 self.assertTrue(tempfilename not in glob.glob( |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
39 os.path.join(self._testdir, b'.testfilename-*'))) |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
40 |
18666
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
41 # discard() removes the temp file without making the write permanent |
29392
f21286e48bc6
atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents:
29391
diff
changeset
|
42 def testdiscard(self): |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
43 file = atomictempfile(self._filename) |
18666
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
44 (dir, basename) = os.path.split(file._tempname) |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
45 |
29188
f00f1de16454
tests: mark test-atomictempfile.py write as binary
timeless <timeless@mozdev.org>
parents:
18666
diff
changeset
|
46 file.write(b'yo\n') |
18666
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
47 file.discard() |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
48 |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
49 self.assertFalse(os.path.isfile(self._filename)) |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
50 self.assertTrue(basename not in os.listdir(b'.')) |
18666
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
51 |
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
52 # if a programmer screws up and passes bad args to atomictempfile, they |
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
53 # get a plain ordinary TypeError, not infinite recursion |
29392
f21286e48bc6
atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents:
29391
diff
changeset
|
54 def testoops(self): |
32319
68c43a416585
tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30342
diff
changeset
|
55 with self.assertRaises(TypeError): |
68c43a416585
tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30342
diff
changeset
|
56 atomictempfile() |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
57 |
29201
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
58 # checkambig=True avoids ambiguity of timestamp |
29392
f21286e48bc6
atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents:
29391
diff
changeset
|
59 def testcheckambig(self): |
29201
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
60 def atomicwrite(checkambig): |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
61 f = atomictempfile(self._filename, checkambig=checkambig) |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
62 f.write(b'FOO') |
29201
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
63 f.close() |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
64 |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
65 # try some times, because reproduction of ambiguity depends on |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
66 # "filesystem time" |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
67 for i in xrange(5): |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
68 atomicwrite(False) |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
69 oldstat = os.stat(self._filename) |
36789
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36645
diff
changeset
|
70 if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]: |
29201
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
71 # subsequent changing never causes ambiguity |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
72 continue |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
73 |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
74 repetition = 3 |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
75 |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
76 # repeat atomic write with checkambig=True, to examine |
30342
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
29394
diff
changeset
|
77 # whether st_mtime is advanced multiple times as expected |
29201
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
78 for j in xrange(repetition): |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
79 atomicwrite(True) |
29391
1acf654f0985
atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents:
29201
diff
changeset
|
80 newstat = os.stat(self._filename) |
36789
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36645
diff
changeset
|
81 if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]: |
29201
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
82 # timestamp ambiguity was naturally avoided while repetition |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
83 continue |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
84 |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
85 # st_mtime should be advanced "repetition" times, because |
30342
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
29394
diff
changeset
|
86 # all atomicwrite() occurred at same time (in sec) |
36789
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36645
diff
changeset
|
87 oldtime = (oldstat[stat.ST_MTIME] + repetition) & 0x7fffffff |
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36645
diff
changeset
|
88 self.assertTrue(newstat[stat.ST_MTIME] == oldtime) |
29201
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
89 # no more examination is needed, if assumption above is true |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
90 break |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
91 else: |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
92 # This platform seems too slow to examine anti-ambiguity |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
93 # of file timestamp (or test happened to be executed at |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
94 # bad timing). Exit silently in this case, because running |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
95 # on other faster platforms can detect problems |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
96 pass |
a109bf7e0dc2
util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29194
diff
changeset
|
97 |
29393
50269a4dce61
atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents:
29392
diff
changeset
|
98 def testread(self): |
50269a4dce61
atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents:
29392
diff
changeset
|
99 with open(self._filename, 'wb') as f: |
50269a4dce61
atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents:
29392
diff
changeset
|
100 f.write(b'foobar\n') |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
101 file = atomictempfile(self._filename, mode=b'rb') |
29393
50269a4dce61
atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents:
29392
diff
changeset
|
102 self.assertTrue(file.read(), b'foobar\n') |
50269a4dce61
atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents:
29392
diff
changeset
|
103 file.discard() |
50269a4dce61
atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents:
29392
diff
changeset
|
104 |
29394
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
105 def testcontextmanagersuccess(self): |
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
106 """When the context closes, the file is closed""" |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
107 with atomictempfile(b'foo') as f: |
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
108 self.assertFalse(os.path.isfile(b'foo')) |
29394
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
109 f.write(b'argh\n') |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
110 self.assertTrue(os.path.isfile(b'foo')) |
29394
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
111 |
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
112 def testcontextmanagerfailure(self): |
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
113 """On exception, the file is discarded""" |
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
114 try: |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
115 with atomictempfile(b'foo') as f: |
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
116 self.assertFalse(os.path.isfile(b'foo')) |
29394
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
117 f.write(b'argh\n') |
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
118 raise ValueError |
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
119 except ValueError: |
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
120 pass |
36645
a007db19dc4d
tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents:
36318
diff
changeset
|
121 self.assertFalse(os.path.isfile(b'foo')) |
29394
6d96658a22b0
atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents:
29393
diff
changeset
|
122 |
14007
d764463b433e
atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff
changeset
|
123 if __name__ == '__main__': |
29194
3bea82dd4c4e
py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29188
diff
changeset
|
124 import silenttestrunner |
18666
fb9d1c2805ff
test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents:
15057
diff
changeset
|
125 silenttestrunner.main(__name__) |