summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-07-28 16:15:02 (GMT)
committerGitHub <noreply@github.com>2017-07-28 16:15:02 (GMT)
commit28ce07ae9e34c70eea6b52515c7e00001cefd41e (patch)
tree5fe91729142059d860047729ae1d9284ad5b6908 /Lib
parentcc42c121eb5346f673247f95dac575aadb77d66c (diff)
downloadcpython-28ce07ae9e34c70eea6b52515c7e00001cefd41e.zip
cpython-28ce07ae9e34c70eea6b52515c7e00001cefd41e.tar.gz
cpython-28ce07ae9e34c70eea6b52515c7e00001cefd41e.tar.bz2
bpo-31066: Fix test_httpservers.test_last_modified() (#2933)
Write the temporary file on disk and then get its modification time.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_httpservers.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index cdc5202..fb4ae19 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -335,9 +335,11 @@ class SimpleHTTPServerTestCase(BaseTestCase):
self.tempdir = tempfile.mkdtemp(dir=basetempdir)
self.tempdir_name = os.path.basename(self.tempdir)
self.base_url = '/' + self.tempdir_name
- with open(os.path.join(self.tempdir, 'test'), 'wb') as temp:
+ tempname = os.path.join(self.tempdir, 'test')
+ with open(tempname, 'wb') as temp:
temp.write(self.data)
- mtime = os.fstat(temp.fileno()).st_mtime
+ temp.flush()
+ mtime = os.stat(tempname).st_mtime
# compute last modification datetime for browser cache tests
last_modif = datetime.datetime.fromtimestamp(mtime,
datetime.timezone.utc)
@@ -471,7 +473,7 @@ class SimpleHTTPServerTestCase(BaseTestCase):
headers['If-Modified-Since'] = email.utils.format_datetime(new_dt,
usegmt=True)
response = self.request(self.base_url + '/test', headers=headers)
- self.check_status_and_reason(response, HTTPStatus.NOT_MODIFIED)
+ self.check_status_and_reason(response, HTTPStatus.NOT_MODIFIED)
def test_browser_cache_file_changed(self):
# with If-Modified-Since earlier than Last-Modified, must return 200
@@ -491,7 +493,7 @@ class SimpleHTTPServerTestCase(BaseTestCase):
headers['If-Modified-Since'] = self.last_modif_header
headers['If-None-Match'] = "*"
response = self.request(self.base_url + '/test', headers=headers)
- self.check_status_and_reason(response, HTTPStatus.OK)
+ self.check_status_and_reason(response, HTTPStatus.OK)
def test_invalid_requests(self):
response = self.request('/', method='FOO')