tests/test-atomictempfile.py
author pacien <pacien.trangirard@pacien.net>
Thu, 17 Mar 2022 11:00:05 +0100
changeset 49055 f64bbba2ee59
parent 48966 6000f5b25c9b
child 49293 56f98406831b
permissions -rw-r--r--
tests: fix glob pattern for dynamic timer alignment The number of space characters varies depending on the number of digits of the timer, making some tests fail on slow machines in an unintended way: ```diff --- /build/mercurial-6.1/tests/test-merge-halt.t +++ /build/mercurial-6.1/tests/test-merge-halt.t.err @@ -210,6 +210,6 @@ merge halted after failed merge (see hg resolve) [240] $ hg shelve --list - default (* ago) changes to: foo (glob) + default (11s ago) changes to: foo $ hg unshelve --abort unshelve of 'default' aborted ERROR: test-merge-halt.t output changed ``` Differential Revision: https://phab.mercurial-scm.org/D12381
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29194
3bea82dd4c4e py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29188
diff changeset
     1
import glob
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
     2
import os
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
     3
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
     4
import stat
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
     5
import tempfile
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
     6
import unittest
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
     7
29194
3bea82dd4c4e py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29188
diff changeset
     8
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
     9
    pycompat,
29194
3bea82dd4c4e py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29188
diff changeset
    10
    util,
3bea82dd4c4e py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29188
diff changeset
    11
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    12
29194
3bea82dd4c4e py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29188
diff changeset
    13
atomictempfile = util.atomictempfile
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    14
36318
3ec9afb951a0 py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32319
diff changeset
    15
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
    16
    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
    17
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
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
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    31
        self.assertTrue(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    32
            tempfilename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    33
            in glob.glob(os.path.join(self._testdir, b'.testfilename-*'))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    34
        )
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    35
29188
f00f1de16454 tests: mark test-atomictempfile.py write as binary
timeless <timeless@mozdev.org>
parents: 18666
diff changeset
    36
        file.write(b'argh\n')
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    37
        file.close()
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    38
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    39
        self.assertTrue(os.path.isfile(self._filename))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    40
        self.assertTrue(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    41
            tempfilename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    42
            not in glob.glob(os.path.join(self._testdir, b'.testfilename-*'))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    43
        )
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    44
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    45
    # 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
    46
    def testdiscard(self):
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    47
        file = atomictempfile(self._filename)
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    48
        (dir, basename) = os.path.split(file._tempname)
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    49
29188
f00f1de16454 tests: mark test-atomictempfile.py write as binary
timeless <timeless@mozdev.org>
parents: 18666
diff changeset
    50
        file.write(b'yo\n')
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    51
        file.discard()
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    52
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    53
        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
    54
        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
    55
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    56
    # 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
    57
    # get a plain ordinary TypeError, not infinite recursion
29392
f21286e48bc6 atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents: 29391
diff changeset
    58
    def testoops(self):
32319
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30342
diff changeset
    59
        with self.assertRaises(TypeError):
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30342
diff changeset
    60
            atomictempfile()
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    61
29201
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    62
    # checkambig=True avoids ambiguity of timestamp
29392
f21286e48bc6 atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents: 29391
diff changeset
    63
    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
    64
        def atomicwrite(checkambig):
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    65
            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
    66
            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
    67
            f.close()
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    68
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    69
        # 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
    70
        # "filesystem time"
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    71
        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
    72
            atomicwrite(False)
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    73
            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
    74
            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
    75
                # 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
    76
                continue
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    77
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    78
            repetition = 3
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    79
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    80
            # 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
    81
            # 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
    82
            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
    83
                atomicwrite(True)
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    84
            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
    85
            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
    86
                # 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
    87
                continue
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    88
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    89
            # 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
    90
            # all atomicwrite() occurred at same time (in sec)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
    91
            oldtime = (oldstat[stat.ST_MTIME] + repetition) & 0x7FFFFFFF
36789
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36645
diff changeset
    92
            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
    93
            # 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
    94
            break
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    95
        else:
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    96
            # 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
    97
            # 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
    98
            # 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
    99
            # 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
   100
            pass
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
   101
29393
50269a4dce61 atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents: 29392
diff changeset
   102
    def testread(self):
50269a4dce61 atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents: 29392
diff changeset
   103
        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
   104
            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
   105
        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
   106
        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
   107
        file.discard()
50269a4dce61 atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents: 29392
diff changeset
   108
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   109
    def testcontextmanagersuccess(self):
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   110
        """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
   111
        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
   112
            self.assertFalse(os.path.isfile(b'foo'))
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   113
            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
   114
        self.assertTrue(os.path.isfile(b'foo'))
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   115
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   116
    def testcontextmanagerfailure(self):
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   117
        """On exception, the file is discarded"""
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   118
        try:
36645
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36318
diff changeset
   119
            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
   120
                self.assertFalse(os.path.isfile(b'foo'))
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   121
                f.write(b'argh\n')
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   122
                raise ValueError
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   123
        except ValueError:
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   124
            pass
36645
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36318
diff changeset
   125
        self.assertFalse(os.path.isfile(b'foo'))
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   126
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
   127
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
   128
if __name__ == '__main__':
29194
3bea82dd4c4e py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29188
diff changeset
   129
    import silenttestrunner
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36789
diff changeset
   130
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
   131
    silenttestrunner.main(__name__)