mock time in unit test
It's crashing now (sometimes): _StringException: Traceback (most recent call last): File "/build/python-swiftclient-2.6.0/tests/unit/test_service.py", line 1085, in test_upload_object_job_stream self.assertAlmostEqual(mtime, expected_mtime, delta=0.5) File "/usr/lib/python3/dist-packages/unittest2/case.py", line 883, in assertAlmostEqual raise self.failureException(msg) AssertionError: 1453224313.0 != 1453224312.4944572 within 0.5 delta Change-Id: Ib2eeb13cd07febcb7c8b4e1435b885c4339093e4
This commit is contained in:
parent
6d52264c30
commit
0fe02eb1c0
@ -1114,7 +1114,8 @@ class TestServiceUpload(_TestServiceBase):
|
||||
self.assertEqual(contents.read(), b'a' * 30)
|
||||
self.assertEqual(contents.get_md5sum(), md5(b'a' * 30).hexdigest())
|
||||
|
||||
def test_upload_object_job_stream(self):
|
||||
@mock.patch('swiftclient.service.time', return_value=1400000000)
|
||||
def test_upload_object_job_stream(self, time_mock):
|
||||
# Streams are wrapped as ReadableToIterable
|
||||
with tempfile.TemporaryFile() as f:
|
||||
f.write(b'a' * 30)
|
||||
@ -1132,7 +1133,7 @@ class TestServiceUpload(_TestServiceBase):
|
||||
'success': True,
|
||||
'path': None,
|
||||
}
|
||||
expected_mtime = float(time.time())
|
||||
expected_mtime = 1400000000
|
||||
|
||||
mock_conn = mock.Mock()
|
||||
mock_conn.put_object.return_value = ''
|
||||
@ -1151,7 +1152,7 @@ class TestServiceUpload(_TestServiceBase):
|
||||
'checksum': True})
|
||||
|
||||
mtime = float(r['headers']['x-object-meta-mtime'])
|
||||
self.assertAlmostEqual(mtime, expected_mtime, delta=0.5)
|
||||
self.assertEqual(mtime, expected_mtime)
|
||||
del r['headers']['x-object-meta-mtime']
|
||||
|
||||
self._assertDictEqual(r, expected_r)
|
||||
|
Loading…
x
Reference in New Issue
Block a user