MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_reread

Method test_reread

Lib/test/test_mailbox.py:1003–1041  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1001 self.assertFalse((perms & 0o111)) # Execute bits should all be off.
1002
1003 def test_reread(self):
1004 # Do an initial unconditional refresh
1005 self._box._refresh()
1006
1007 # Put the last modified times more than two seconds into the past
1008 # (because mtime may have a two second granularity)
1009 for subdir in ('cur', 'new'):
1010 os.utime(os.path.join(self._box._path, subdir),
1011 (time.time()-5,)*2)
1012
1013 # Because mtime has a two second granularity in worst case (FAT), a
1014 # refresh is done unconditionally if called for within
1015 # two-second-plus-a-bit of the last one, just in case the mbox has
1016 # changed; so now we have to wait for that interval to expire.
1017 #
1018 # Because this is a test, emulate sleeping. Instead of
1019 # sleeping for 2 seconds, use the skew factor to make _refresh
1020 # think that 2 seconds have passed and re-reading the _toc is
1021 # only required if mtimes differ.
1022 self._box._skewfactor = -3
1023
1024 # Re-reading causes the ._toc attribute to be assigned a new dictionary
1025 # object, so we'll check that the ._toc attribute isn't a different
1026 # object.
1027 orig_toc = self._box._toc
1028 def refreshed():
1029 return self._box._toc is not orig_toc
1030
1031 self._box._refresh()
1032 self.assertFalse(refreshed())
1033
1034 # Now, write something into cur and remove it. This changes
1035 # the mtime and should cause a re-read. Note that "sleep
1036 # emulation" is still in effect, as skewfactor is -3.
1037 filename = os.path.join(self._path, 'cur', 'stray-file')
1038 os_helper.create_empty_file(filename)
1039 os.unlink(filename)
1040 self._box._refresh()
1041 self.assertTrue(refreshed())
1042
1043
1044class _TestSingleFile(TestMailbox):

Callers

nothing calls this directly

Calls 7

_refreshMethod · 0.80
utimeMethod · 0.80
assertFalseMethod · 0.80
assertTrueMethod · 0.80
joinMethod · 0.45
timeMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected