-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_pycon.py
54 lines (40 loc) · 1.66 KB
/
test_pycon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from copy import deepcopy
import pytest
from pycon import (load_pycon_data,
get_most_popular_talks_by_views,
get_most_popular_talks_by_like_ratio,
get_talks_gt_one_hour,
get_talks_lt_twentyfour_min)
@pytest.fixture(scope='module')
def videos():
return load_pycon_data()
def test_load_pycon_data(videos):
assert len(videos) == 147
assert isinstance(videos[0], tuple)
def test_get_most_popular_talks_by_views(videos):
# as sort might be used in place, or any other list manipulation
# let's make sure we work with a copy of the module fixture
videos_copy = deepcopy(videos)
expected = ['T-TwcmT6Rcw', 'GBQAKldqgZs', 'ms29ZPUKxbU',
'zJ9z6Ge-vXs', 'WiQqqB9MlkA']
vids = list(get_most_popular_talks_by_views(videos_copy))
actual = [vid.id for vid in vids[:5]]
assert expected == actual
def test_get_most_popular_talks_by_like_ratio(videos):
# same here: let's use a local copy of videos
videos_copy = deepcopy(videos)
vids = list(get_most_popular_talks_by_like_ratio(videos_copy))
expected = ['8OoR-P6wE0M', 'h-38HZqanJs', 'C7ZhMnfUKIA',
'GmbaKdd6o6A', '3EXvR1shVFQ']
actual = [vid.id for vid in vids[:5]]
assert expected == actual
def test_get_talks_gt_one_hour(videos):
vids = get_talks_gt_one_hour(videos)
assert vids[0].id == '0hsKLYfyQZc'
assert vids[-1].id == 'ZwvjtCjimiw'
assert len(vids) == 35
def test_get_talks_lt_twentyfour_min(videos):
vids = get_talks_lt_twentyfour_min(videos)
assert vids[0].id == 'zQeYx87mfyw'
assert vids[-1].id == 'TcHkkzWBMKY'
assert len(vids) == 12