1
- from action import VideoParser
1
+ import os
2
+ import re
3
+
4
+ from action import FileUpdater , VideoParser
5
+
6
+ video_parser = VideoParser (
7
+ base_url = "https://ytcards.demolab.com/" ,
8
+ channel_id = "UCipSxT7a3rn81vGLw9lqRkg" ,
9
+ max_videos = 6 ,
10
+ card_width = 250 ,
11
+ background_color = "#0d1117" ,
12
+ title_color = "#ffffff" ,
13
+ stats_color = "#dedede" ,
14
+ youtube_api_key = "" ,
15
+ theme_context_light = {},
16
+ theme_context_dark = {},
17
+ show_duration = False ,
18
+ )
2
19
3
20
4
21
def test_parse_iso8601_duration ():
@@ -8,11 +25,73 @@ def test_parse_iso8601_duration():
8
25
assert VideoParser .parse_iso8601_duration ("P1DT2H10M10S" ) == 94210
9
26
10
27
11
- def test_parse_video ():
12
- """TODO: Test parsing a video from feedparser video object"""
13
- pass
28
+ def test_parse_videos ():
29
+ videos = video_parser .parse_videos ()
30
+
31
+ assert len (videos .splitlines ()) == 6
14
32
33
+ line_regex = r"^\[!\[.*\]\(.* \"(.*)\"\)\]\(.*\)$"
34
+ assert all (re .match (line_regex , line ) for line in videos .splitlines ())
15
35
16
- def test_parse_videos ():
17
- """TODO: Test parsing a list of videos with feedparser"""
18
- pass
36
+ assert "https://ytcards.demolab.com/?id=" in videos
37
+ assert "title=" in videos
38
+ assert "timestamp=" in videos
39
+ assert "background_color=" in videos
40
+ assert "title_color=" in videos
41
+ assert "stats_color=" in videos
42
+ assert "width=" in videos
43
+
44
+
45
+ def test_parse_videos_with_theme_context ():
46
+ video_parser ._theme_context_light = {
47
+ "background_color" : "#ffffff" ,
48
+ "title_color" : "#000000" ,
49
+ "stats_color" : "#000000" ,
50
+ }
51
+ video_parser ._theme_context_dark = {
52
+ "background_color" : "#000000" ,
53
+ "title_color" : "#ffffff" ,
54
+ "stats_color" : "#ffffff" ,
55
+ }
56
+ videos = video_parser .parse_videos ()
57
+
58
+ assert len (videos .splitlines ()) == 6
59
+
60
+ line_regex = (
61
+ r"^\[!\[.*\]\(.* \"(.*)\"\)\]\(.*\#gh-dark-mode-only\)"
62
+ r"\[!\[.*\]\(.* \"(.*)\"\)\]\(.*\#gh-light-mode-only\)$"
63
+ )
64
+ assert all (re .match (line_regex , line ) for line in videos .splitlines ())
65
+
66
+
67
+ def test_update_file ():
68
+ path = "./tests/README.md"
69
+ # create a file to test with
70
+ with open (path , "w+" ) as f :
71
+ f .write (
72
+ "Test Before\n "
73
+ "\n "
74
+ "<!-- BEGIN YOUTUBE-CARDS -->\n "
75
+ "<!-- END YOUTUBE-CARDS -->\n "
76
+ "\n "
77
+ "Test After\n "
78
+ )
79
+ try :
80
+ # update the file
81
+ FileUpdater .update (path , "YOUTUBE-CARDS" , "A\n B\n C" )
82
+ # read the file and assert the contents
83
+ with open (path , "r" ) as f :
84
+ assert f .read () == (
85
+ "Test Before\n "
86
+ "\n "
87
+ "<!-- BEGIN YOUTUBE-CARDS -->\n "
88
+ "A\n "
89
+ "B\n "
90
+ "C\n "
91
+ "<!-- END YOUTUBE-CARDS -->\n "
92
+ "\n "
93
+ "Test After\n "
94
+ )
95
+ finally :
96
+ # remove the file
97
+ os .remove (path )
0 commit comments