1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00
Files
vcrpy/tests/integration/test_disksaver.py
Josh Peak 7caf29735a Format project with black (#467)
Format with line length 110 to match flake8

make black part of linting check

Update travis spec for updated black requirements

Add diff output for black on failure

update changelog
2019-08-24 11:36:35 +10:00

56 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
"""Basic tests about save behavior"""
# External imports
import os
import time
from six.moves.urllib.request import urlopen
# Internal imports
import vcr
def test_disk_saver_nowrite(tmpdir, httpbin):
"""
Ensure that when you close a cassette without changing it it doesn't
rewrite the file
"""
fname = str(tmpdir.join("synopsis.yaml"))
with vcr.use_cassette(fname) as cass:
urlopen(httpbin.url).read()
assert cass.play_count == 0
last_mod = os.path.getmtime(fname)
with vcr.use_cassette(fname) as cass:
urlopen(httpbin.url).read()
assert cass.play_count == 1
assert cass.dirty is False
last_mod2 = os.path.getmtime(fname)
assert last_mod == last_mod2
def test_disk_saver_write(tmpdir, httpbin):
"""
Ensure that when you close a cassette after changing it it does
rewrite the file
"""
fname = str(tmpdir.join("synopsis.yaml"))
with vcr.use_cassette(fname) as cass:
urlopen(httpbin.url).read()
assert cass.play_count == 0
last_mod = os.path.getmtime(fname)
# Make sure at least 1 second passes, otherwise sometimes
# the mtime doesn't change
time.sleep(1)
with vcr.use_cassette(fname, record_mode="any") as cass:
urlopen(httpbin.url).read()
urlopen(httpbin.url + "/get").read()
assert cass.play_count == 1
assert cass.dirty
last_mod2 = os.path.getmtime(fname)
assert last_mod != last_mod2