tests/test-atomictempfile.py
author Joerg Sonnenberger <joerg@bec.de>
Fri, 15 Jan 2021 01:58:59 +0100
changeset 46372 3e91d9978bec
parent 43076 2372284d9457
child 48875 6000f5b25c9b
permissions -rw-r--r--
branchmap: update rev-branch-cache incrementally Historically, the revision to branch mapping cache was updated on demand and shared via bundle2 to avoid the cost of rebuilding on first use. Use the new `register_changeset` callback and update rbc directly on every change. Make the transfer of the bundle part redundant, but keep it for the moment to avoid the test churn. Over all, "hg unbundle" for large bundles is less than 1.8% slower for different larger repositories and that seems to a reasonable trade off. Differential Revision: https://phab.mercurial-scm.org/D9781
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
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
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36616
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 (
36285
3ec9afb951a0 py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32279
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
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    14
29194
3bea82dd4c4e py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29188
diff changeset
    15
atomictempfile = util.atomictempfile
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    16
36285
3ec9afb951a0 py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32279
diff changeset
    17
if pycompat.ispy3:
3ec9afb951a0 py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32279
diff changeset
    18
    xrange = range
3ec9afb951a0 py3: use range instead on xrange on py3 in tests/test-atomictempfile.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32279
diff changeset
    19
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    20
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    21
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
    22
    def setUp(self):
36616
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
    23
        self._testdir = tempfile.mkdtemp(b'atomictempfiletest')
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
    24
        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
    25
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    26
    def tearDown(self):
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    27
        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
    28
29392
f21286e48bc6 atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents: 29391
diff changeset
    29
    def testsimple(self):
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    30
        file = atomictempfile(self._filename)
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    31
        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
    32
        tempfilename = file._tempname
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    33
        self.assertTrue(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    34
            tempfilename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    35
            in glob.glob(os.path.join(self._testdir, b'.testfilename-*'))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    36
        )
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    37
29188
f00f1de16454 tests: mark test-atomictempfile.py write as binary
timeless <timeless@mozdev.org>
parents: 18666
diff changeset
    38
        file.write(b'argh\n')
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    39
        file.close()
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    40
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    41
        self.assertTrue(os.path.isfile(self._filename))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    42
        self.assertTrue(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    43
            tempfilename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    44
            not in glob.glob(os.path.join(self._testdir, b'.testfilename-*'))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    45
        )
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    46
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    47
    # 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
    48
    def testdiscard(self):
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    49
        file = atomictempfile(self._filename)
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    50
        (dir, basename) = os.path.split(file._tempname)
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    51
29188
f00f1de16454 tests: mark test-atomictempfile.py write as binary
timeless <timeless@mozdev.org>
parents: 18666
diff changeset
    52
        file.write(b'yo\n')
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    53
        file.discard()
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    54
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    55
        self.assertFalse(os.path.isfile(self._filename))
36616
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
    56
        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
    57
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
    58
    # 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
    59
    # get a plain ordinary TypeError, not infinite recursion
29392
f21286e48bc6 atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents: 29391
diff changeset
    60
    def testoops(self):
32279
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30332
diff changeset
    61
        with self.assertRaises(TypeError):
68c43a416585 tests: use context manager form of assertRaises
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30332
diff changeset
    62
            atomictempfile()
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
    63
29201
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    64
    # checkambig=True avoids ambiguity of timestamp
29392
f21286e48bc6 atomictempfile: remove test ordering
Martijn Pieters <mjpieters@fb.com>
parents: 29391
diff changeset
    65
    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
    66
        def atomicwrite(checkambig):
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    67
            f = atomictempfile(self._filename, checkambig=checkambig)
36616
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
    68
            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
    69
            f.close()
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    70
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    71
        # 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
    72
        # "filesystem time"
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    73
        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
    74
            atomicwrite(False)
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    75
            oldstat = os.stat(self._filename)
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36616
diff changeset
    76
            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
    77
                # 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
    78
                continue
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
            repetition = 3
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    81
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    82
            # repeat atomic write with checkambig=True, to examine
30332
318a24b52eeb spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents: 29394
diff changeset
    83
            # 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
    84
            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
    85
                atomicwrite(True)
29391
1acf654f0985 atomictempfile: use a tempdir to keep the test environment clean
Martijn Pieters <mjpieters@fb.com>
parents: 29201
diff changeset
    86
            newstat = os.stat(self._filename)
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36616
diff changeset
    87
            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
    88
                # 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
    89
                continue
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    90
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    91
            # st_mtime should be advanced "repetition" times, because
30332
318a24b52eeb spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents: 29394
diff changeset
    92
            # all atomicwrite() occurred at same time (in sec)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
    93
            oldtime = (oldstat[stat.ST_MTIME] + repetition) & 0x7FFFFFFF
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36616
diff changeset
    94
            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
    95
            # 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
    96
            break
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    97
        else:
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
    98
            # 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
    99
            # 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
   100
            # 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
   101
            # 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
   102
            pass
a109bf7e0dc2 util: make atomictempfile avoid ambiguity of file stat if needed
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29194
diff changeset
   103
29393
50269a4dce61 atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents: 29392
diff changeset
   104
    def testread(self):
50269a4dce61 atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents: 29392
diff changeset
   105
        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
   106
            f.write(b'foobar\n')
36616
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
   107
        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
   108
        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
   109
        file.discard()
50269a4dce61 atomictempfile: add read to the supported file operations
Martijn Pieters <mjpieters@fb.com>
parents: 29392
diff changeset
   110
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   111
    def testcontextmanagersuccess(self):
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   112
        """When the context closes, the file is closed"""
36616
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
   113
        with atomictempfile(b'foo') as f:
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
   114
            self.assertFalse(os.path.isfile(b'foo'))
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   115
            f.write(b'argh\n')
36616
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
   116
        self.assertTrue(os.path.isfile(b'foo'))
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   117
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   118
    def testcontextmanagerfailure(self):
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   119
        """On exception, the file is discarded"""
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   120
        try:
36616
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
   121
            with atomictempfile(b'foo') as f:
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
   122
                self.assertFalse(os.path.isfile(b'foo'))
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   123
                f.write(b'argh\n')
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   124
                raise ValueError
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   125
        except ValueError:
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   126
            pass
36616
a007db19dc4d tests: add missing b prefixes in test-atomictempfile.py
Augie Fackler <augie@google.com>
parents: 36285
diff changeset
   127
        self.assertFalse(os.path.isfile(b'foo'))
29394
6d96658a22b0 atomictempfile: add context manager support
Martijn Pieters <mjpieters@fb.com>
parents: 29393
diff changeset
   128
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
   129
14007
d764463b433e atomictempfile: avoid infinite recursion in __del__().
Greg Ward <greg@gerg.ca>
parents:
diff changeset
   130
if __name__ == '__main__':
29194
3bea82dd4c4e py3: make tests/test-atomictempfile.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29188
diff changeset
   131
    import silenttestrunner
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36781
diff changeset
   132
18666
fb9d1c2805ff test-atomictempfile: convert to unit test
Idan Kamara <idankk86@gmail.com>
parents: 15057
diff changeset
   133
    silenttestrunner.main(__name__)