Mercurial > hg
view tests/test-atomictempfile.py @ 49836:3d7bf111f01e stable
packaging: add dependencies to the PyOxidizer build on macOS
Otherwise, we get a bunch of test failures for missing things like pygments, or
tests skipped entirely. The input file is a copy/paste from the equivalent
Windows file, but with dulwich, pygit2, and pytest-vcr commented out because
the build process errors out with them, flagging them as incompatible with
loading from memory. I have no idea if that's actually true or not, because
I've noticed that if I don't `make clean` after every build, the next build
flags the watchman stuff as incompatible with loading from memory.
The remaining failures are:
Failed test-alias.t: output changed
Failed test-basic.t: output changed
Failed test-check-help.t: output changed
Failed test-commit-interactive.t: output changed
Failed test-extension.t: output changed
Failed test-help.t: output changed
Failed test-i18n.t: output changed
Failed test-log.t: output changed
Failed test-qrecord.t: output changed
Failed test-share-safe.t: output changed
Most of the issues seem related to loading help for disabled extensions from
`hgext.__index__`, namely the full extension help being unavailable, not being
able to resolve what commands are provided by what extension, and not having the
command level help available.
test-log.t, test-commit-interactive.t, and test-i18n.t look like i18n (or lack
thereof) issues.
test-basic.t is just odd:
@@ -55,7 +55,7 @@
On Python 3, stdio may be None:
$ hg debuguiprompt --config ui.interactive=true 0<&-
- abort: Bad file descriptor (no-rhg !)
+ abort: response expected
abort: response expected (rhg !)
[255]
$ hg version -q 0<&-
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 06 Dec 2022 17:12:59 -0500 |
parents | 56f98406831b |
children |
line wrap: on
line source
import glob import os import shutil import stat import tempfile import unittest from mercurial import ( util, ) atomictempfile = util.atomictempfile class testatomictempfile(unittest.TestCase): def setUp(self): self._testdir = tempfile.mkdtemp(b'atomictempfiletest') self._filename = os.path.join(self._testdir, b'testfilename') def tearDown(self): shutil.rmtree(self._testdir, True) def testsimple(self): file = atomictempfile(self._filename) self.assertFalse(os.path.isfile(self._filename)) tempfilename = file._tempname self.assertTrue( tempfilename in glob.glob(os.path.join(self._testdir, b'.testfilename-*')) ) file.write(b'argh\n') file.close() self.assertTrue(os.path.isfile(self._filename)) self.assertTrue( tempfilename not in glob.glob(os.path.join(self._testdir, b'.testfilename-*')) ) # discard() removes the temp file without making the write permanent def testdiscard(self): file = atomictempfile(self._filename) (dir, basename) = os.path.split(file._tempname) file.write(b'yo\n') file.discard() self.assertFalse(os.path.isfile(self._filename)) self.assertTrue(basename not in os.listdir(b'.')) # if a programmer screws up and passes bad args to atomictempfile, they # get a plain ordinary TypeError, not infinite recursion def testoops(self): with self.assertRaises(TypeError): atomictempfile() # checkambig=True avoids ambiguity of timestamp def testcheckambig(self): def atomicwrite(checkambig): f = atomictempfile(self._filename, checkambig=checkambig) f.write(b'FOO') f.close() # try some times, because reproduction of ambiguity depends on # "filesystem time" for i in range(5): atomicwrite(False) oldstat = os.stat(self._filename) if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]: # subsequent changing never causes ambiguity continue repetition = 3 # repeat atomic write with checkambig=True, to examine # whether st_mtime is advanced multiple times as expected for j in range(repetition): atomicwrite(True) newstat = os.stat(self._filename) if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]: # timestamp ambiguity was naturally avoided while repetition continue # st_mtime should be advanced "repetition" times, because # all atomicwrite() occurred at same time (in sec) oldtime = (oldstat[stat.ST_MTIME] + repetition) & 0x7FFFFFFF self.assertTrue(newstat[stat.ST_MTIME] == oldtime) # no more examination is needed, if assumption above is true break else: # This platform seems too slow to examine anti-ambiguity # of file timestamp (or test happened to be executed at # bad timing). Exit silently in this case, because running # on other faster platforms can detect problems pass def testread(self): with open(self._filename, 'wb') as f: f.write(b'foobar\n') file = atomictempfile(self._filename, mode=b'rb') self.assertTrue(file.read(), b'foobar\n') file.discard() def testcontextmanagersuccess(self): """When the context closes, the file is closed""" with atomictempfile(b'foo') as f: self.assertFalse(os.path.isfile(b'foo')) f.write(b'argh\n') self.assertTrue(os.path.isfile(b'foo')) def testcontextmanagerfailure(self): """On exception, the file is discarded""" try: with atomictempfile(b'foo') as f: self.assertFalse(os.path.isfile(b'foo')) f.write(b'argh\n') raise ValueError except ValueError: pass self.assertFalse(os.path.isfile(b'foo')) if __name__ == '__main__': import silenttestrunner silenttestrunner.main(__name__)