'''Basic tests about save behavior'''
# coding=utf-8

# External imports
import os
import urllib2

# Internal imports
import vcr

def test_disk_saver_nowrite(tmpdir):
    '''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:
        urllib2.urlopen('http://www.iana.org/domains/reserved').read()
        assert cass.play_count == 0
    last_mod = os.path.getmtime(fname)

    with vcr.use_cassette(fname) as cass:
        urllib2.urlopen('http://www.iana.org/domains/reserved').read()
        assert cass.play_count == 1
        assert cass.dirty == False
    last_mod2 = os.path.getmtime(fname)

    assert last_mod == last_mod2

def test_disk_saver_write(tmpdir):
    '''Ensure that when you close a cassette with changing it it does rewrite the file'''
    fname = str(tmpdir.join('synopsis.yaml'))
    with vcr.use_cassette(fname) as cass:
        urllib2.urlopen('http://www.iana.org/domains/reserved').read()
        assert cass.play_count == 0
    last_mod = os.path.getmtime(fname)

    with vcr.use_cassette(fname) as cass:
        urllib2.urlopen('http://www.iana.org/domains/reserved').read()
        urllib2.urlopen('http://httpbin.org/').read()
        assert cass.play_count == 1
        assert cass.dirty
    last_mod2 = os.path.getmtime(fname)

    assert last_mod != last_mod2


@@ -90,16 +90,28 @@
  urllib2
+%0Aimport time
 %0A%0A# Inte
@@ -842,20 +842,21 @@
 assette 
-with
+after
  changin
@@ -1115,32 +1115,140 @@
 etmtime(fname)%0A%0A
+    time.sleep(1) # Make sure at least 1 second passes, otherwise sometimes%0A    # the mtime doesn't change%0A%0A
     with vcr.use

Fix intermittent test failure due to http happening too fast