# Path: pytube/request.py
# def _execute_request(
#     url,
#     method=None,
#     headers=None,
#     data=None,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT
# ):
# def get(url, extra_headers=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# def post(url, extra_headers=None, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# def seq_stream(
#     url,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
#     max_retries=0
# ):
# def stream(
#     url,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
#     max_retries=0
# ):
# def filesize(url):
# def seq_filesize(url):
# def head(url):
# 
# Path: pytube/exceptions.py
# class MaxRetriesExceeded(PytubeError):
#     """Maximum number of retries exceeded."""


import socket
import os
import pytest
from unittest import mock
from urllib.error import URLError
from pytube import request
from pytube.exceptions import MaxRetriesExceeded



@mock.patch("pytube.request.urlopen")
def test_streaming(mock_urlopen):
    # Given
    fake_stream_binary = [
        os.urandom(8 * 1024),
        os.urandom(8 * 1024),
        os.urandom(8 * 1024),
        None,
    ]
    mock_response = mock.Mock()
    mock_response.read.side_effect = fake_stream_binary
    mock_response.info.return_value = {"Content-Range": "bytes 200-1000/24576"}
    mock_urlopen.return_value = mock_response
    # When

# Path: pytube/request.py
# def _execute_request(
#     url,
#     method=None,
#     headers=None,
#     data=None,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT
# ):
# def get(url, extra_headers=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# def post(url, extra_headers=None, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# def seq_stream(
#     url,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
#     max_retries=0
# ):
# def stream(
#     url,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
#     max_retries=0
# ):
# def filesize(url):
# def seq_filesize(url):
# def head(url):
# 
# Path: pytube/exceptions.py
# class MaxRetriesExceeded(PytubeError):
#     """Maximum number of retries exceeded."""


# Path: tests/test_request.py
import socket
import os
import pytest
from unittest import mock
from urllib.error import URLError
from pytube import request
from pytube.exceptions import MaxRetriesExceeded




@mock.patch("pytube.request.urlopen")
def test_streaming(mock_urlopen):
    # Given
    fake_stream_binary = [
        os.urandom(8 * 1024),
        os.urandom(8 * 1024),
        os.urandom(8 * 1024),
        None,
    ]
    mock_response = mock.Mock()
    mock_response.read.side_effect = fake_stream_binary
    mock_response.info.return_value = {"Content-Range": "bytes 200-1000/24576"}
    mock_urlopen.return_value = mock_response
    # When

    response = request.stream("http://fakeassurl.gov/streaming_test")