<commit_before>'''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

<commit_msg>Fix intermittent test failure due to http happening too fast<commit_after>'''Basic tests about save behavior'''
# coding=utf-8

# External imports
import os
import urllib2
import time

# 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 after 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)

    time.sleep(1) # Make sure at least 1 second passes, otherwise sometimes
    # the mtime doesn't change

    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


{'fraction_non_alphanumeric': 0.1197780678851175, 'fraction_numerical': 0.010443864229765013, 'mean_word_length': 3.316901408450704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6628518', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1017, 'n_words': 237}