added test_cache
Browse files- tests/test_helpers.py +19 -1
tests/test_helpers.py
CHANGED
@@ -5,7 +5,7 @@ import pytest
|
|
5 |
|
6 |
from pytube import helpers
|
7 |
from pytube.exceptions import RegexMatchError
|
8 |
-
from pytube.helpers import deprecated
|
9 |
|
10 |
|
11 |
def test_regex_search_no_match():
|
@@ -28,9 +28,27 @@ def test_deprecated(warn):
|
|
28 |
@deprecated("oh no")
|
29 |
def deprecated_function():
|
30 |
return None
|
|
|
31 |
deprecated_function()
|
32 |
warn.assert_called_with(
|
33 |
"Call to deprecated function deprecated_function (oh no).",
|
34 |
category=DeprecationWarning,
|
35 |
stacklevel=2,
|
36 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
from pytube import helpers
|
7 |
from pytube.exceptions import RegexMatchError
|
8 |
+
from pytube.helpers import deprecated, cache
|
9 |
|
10 |
|
11 |
def test_regex_search_no_match():
|
|
|
28 |
@deprecated("oh no")
|
29 |
def deprecated_function():
|
30 |
return None
|
31 |
+
|
32 |
deprecated_function()
|
33 |
warn.assert_called_with(
|
34 |
"Call to deprecated function deprecated_function (oh no).",
|
35 |
category=DeprecationWarning,
|
36 |
stacklevel=2,
|
37 |
)
|
38 |
+
|
39 |
+
|
40 |
+
def test_cache():
|
41 |
+
call_count = 0
|
42 |
+
|
43 |
+
@cache
|
44 |
+
def cached_func(stuff):
|
45 |
+
nonlocal call_count
|
46 |
+
call_count += 1
|
47 |
+
return stuff
|
48 |
+
|
49 |
+
cached_func("hi")
|
50 |
+
cached_func("hi")
|
51 |
+
cached_func("bye")
|
52 |
+
cached_func("bye")
|
53 |
+
|
54 |
+
assert call_count == 2
|