<commit_before>import os
import urllib2
import pytest
import vcr


def test_once_record_mode(tmpdir):
    testfile = str(tmpdir.join('recordmode.yml'))
    with vcr.use_cassette(testfile, record_mode="once"):
        # cassette file doesn't exist, so create.
        response = urllib2.urlopen('http://httpbin.org/').read()

    with vcr.use_cassette(testfile, record_mode="once") as cass:
        # make the same request again
        response = urllib2.urlopen('http://httpbin.org/').read()

        # the first time, it's played from the cassette.
        # but, try to access something else from the same cassette, and an
        # exception is raised.
        with pytest.raises(Exception):
            response = urllib2.urlopen('http://httpbin.org/get').read()


def test_new_episodes_record_mode(tmpdir):
    testfile = str(tmpdir.join('recordmode.yml'))

    with vcr.use_cassette(testfile, record_mode="new_episodes"):
        # cassette file doesn't exist, so create.
        response = urllib2.urlopen('http://httpbin.org/').read()

    with vcr.use_cassette(testfile, record_mode="new_episodes") as cass:
        # make the same request again
        response = urllib2.urlopen('http://httpbin.org/').read()

        # in the "new_episodes" record mode, we can add more requests to
        # a cassette without repurcussions.
        response = urllib2.urlopen('http://httpbin.org/get').read()

        # the first interaction was not re-recorded, but the second was added
        assert cass.play_count == 1


def test_all_record_mode(tmpdir):
    testfile = str(tmpdir.join('recordmode.yml'))

    with vcr.use_cassette(testfile, record_mode="all"):
        # cassette file doesn't exist, so create.
        response = urllib2.urlopen('http://httpbin.org/').read()

    with vcr.use_cassette(testfile, record_mode="all") as cass:
        # make the same request again
        response = urllib2.urlopen('http://httpbin.org/').read()

        # in the "all" record mode, we can add more requests to
        # a cassette without repurcussions.
        response = urllib2.urlopen('http://httpbin.org/get').read()

        # The cassette was never actually played, even though it existed.
        # that's because, in "all" mode, the requests all go directly to
        # the source and bypass the cassette.
        assert cass.play_count == 0


def test_none_record_mode(tmpdir):
    # Cassette file doesn't exist, yet we are trying to make a request.
    # raise hell.
    testfile = str(tmpdir.join('recordmode.yml'))
    with vcr.use_cassette(testfile, record_mode="none"):
        with pytest.raises(Exception):
            response = urllib2.urlopen('http://httpbin.org/').read()


def test_none_record_mode_with_existing_cassette(tmpdir):
    # create a cassette file
    testfile = str(tmpdir.join('recordmode.yml'))

    with vcr.use_cassette(testfile, record_mode="all"):
        response = urllib2.urlopen('http://httpbin.org/').read()

    # play from cassette file
    with vcr.use_cassette(testfile, record_mode="none") as cass:
        response = urllib2.urlopen('http://httpbin.org/').read()
        assert cass.play_count == 1
        # but if I try to hit the net, raise an exception.
        with pytest.raises(Exception):
            response = urllib2.urlopen('http://httpbin.org/get').read()<commit_msg>Added test: accessing two times same page<commit_after>import os
import urllib2
import pytest
import vcr


def test_once_record_mode(tmpdir):
    testfile = str(tmpdir.join('recordmode.yml'))
    with vcr.use_cassette(testfile, record_mode="once"):
        # cassette file doesn't exist, so create.
        response = urllib2.urlopen('http://httpbin.org/').read()

    with vcr.use_cassette(testfile, record_mode="once") as cass:
        # make the same request again
        response = urllib2.urlopen('http://httpbin.org/').read()

        # the first time, it's played from the cassette.
        # but, try to access something else from the same cassette, and an
        # exception is raised.
        with pytest.raises(Exception):
            response = urllib2.urlopen('http://httpbin.org/get').read()

def test_once_record_mode_two_times(tmpdir):
    testfile = str(tmpdir.join('recordmode.yml'))
    with vcr.use_cassette(testfile, record_mode="once"):
	# get two same files
        response1 = urllib2.urlopen('http://httpbin.org/').read()
        response2 = urllib2.urlopen('http://httpbin.org/').read()

    with vcr.use_cassette(testfile, record_mode="once") as cass:
        # do it again
        response = urllib2.urlopen('http://httpbin.org/').read()
        response = urllib2.urlopen('http://httpbin.org/').read()

def test_new_episodes_record_mode(tmpdir):
    testfile = str(tmpdir.join('recordmode.yml'))

    with vcr.use_cassette(testfile, record_mode="new_episodes"):
        # cassette file doesn't exist, so create.
        response = urllib2.urlopen('http://httpbin.org/').read()

    with vcr.use_cassette(testfile, record_mode="new_episodes") as cass:
        # make the same request again
        response = urllib2.urlopen('http://httpbin.org/').read()

        # in the "new_episodes" record mode, we can add more requests to
        # a cassette without repurcussions.
        response = urllib2.urlopen('http://httpbin.org/get').read()

        # the first interaction was not re-recorded, but the second was added
        assert cass.play_count == 1


def test_all_record_mode(tmpdir):
    testfile = str(tmpdir.join('recordmode.yml'))

    with vcr.use_cassette(testfile, record_mode="all"):
        # cassette file doesn't exist, so create.
        response = urllib2.urlopen('http://httpbin.org/').read()

    with vcr.use_cassette(testfile, record_mode="all") as cass:
        # make the same request again
        response = urllib2.urlopen('http://httpbin.org/').read()

        # in the "all" record mode, we can add more requests to
        # a cassette without repurcussions.
        response = urllib2.urlopen('http://httpbin.org/get').read()

        # The cassette was never actually played, even though it existed.
        # that's because, in "all" mode, the requests all go directly to
        # the source and bypass the cassette.
        assert cass.play_count == 0



def test_none_record_mode(tmpdir):
    # Cassette file doesn't exist, yet we are trying to make a request.
    # raise hell.
    testfile = str(tmpdir.join('recordmode.yml'))
    with vcr.use_cassette(testfile, record_mode="none"):
        with pytest.raises(Exception):
            response = urllib2.urlopen('http://httpbin.org/').read()


def test_none_record_mode_with_existing_cassette(tmpdir):
    # create a cassette file
    testfile = str(tmpdir.join('recordmode.yml'))

    with vcr.use_cassette(testfile, record_mode="all"):
        response = urllib2.urlopen('http://httpbin.org/').read()

    # play from cassette file
    with vcr.use_cassette(testfile, record_mode="none") as cass:
        response = urllib2.urlopen('http://httpbin.org/').read()
        assert cass.play_count == 1
        # but if I try to hit the net, raise an exception.
        with pytest.raises(Exception):
            response = urllib2.urlopen('http://httpbin.org/get').read()
{'fraction_non_alphanumeric': 0.12249134948096886, 'fraction_numerical': 0.005536332179930796, 'mean_word_length': 3.0917327293318233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4639640', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2263, 'n_words': 554}