# -*- coding: utf-8 -*-
from unittest import mock

from pytube import YouTube


@mock.patch("pytube.__main__.YouTube")
def test_prefetch_deferred(MockYouTube):
    instance = MockYouTube.return_value
    instance.prefetch_descramble.return_value = None
    YouTube("https://www.youtube.com/watch?v=9bZkp7q19f0", True)
    assert not instance.prefetch_descramble.called


@mock.patch("urllib.request.install_opener")
def test_install_proxy(opener):
    proxies = {"http": "http://www.example.com:3128/"}
    YouTube(
        "https://www.youtube.com/watch?v=9bZkp7q19f0",
        defer_prefetch_init=True,
        proxies=proxies,
    )
    opener.assert_called()

@@ -44,16 +44,31 @@
 t mock%0A%0A
+import pytest%0A%0A
 from pyt
@@ -86,16 +86,63 @@
 YouTube%0A
+from pytube.exceptions import VideoUnavailable%0A
 %0A%0A@mock.
@@ -718,8 +718,283 @@
 alled()%0A
+%0A%0A@mock.patch(%22pytube.request.get%22)%0Adef test_video_unavailable(get):%0A    get.return_value = None%0A    youtube = YouTube(%0A        %22https://www.youtube.com/watch?v=9bZkp7q19f0%22, defer_prefetch_init=True%0A    )%0A    with pytest.raises(VideoUnavailable):%0A        youtube.prefetch()%0A

test main raises VideoUnavailable