55Test for macros.ShowIcons
66"""
77
8+ import re
9+ import os
810from moin .macros .ShowIcons import Macro
911
12+ my_dir = os .path .abspath (os .path .dirname (__file__ ))
13+
1014
1115def test_ShowIconsMacro ():
1216 """Call ShowIcons macro and test output"""
@@ -30,3 +34,35 @@ def test_ShowIconsMacro():
3034 assert expected_tags .issubset (result_tags )
3135 assert expected_texts .issubset (result_texts )
3236 assert expected_paths .issubset (result_paths )
37+
38+
39+ def get_css_icon_names ():
40+ """Read css file and search for icon urls"""
41+ css_file = os .path .join (os .path .split (my_dir )[0 ], ".." , "static" , "css" , "common.css" )
42+ with open (css_file , encoding = "utf-8" ) as f :
43+ common_css = f .readlines ()
44+ icon_list = set ()
45+ for line in common_css :
46+ link = re .search (r"url\([\'\"]?([(.)/].*?)[\'\"]?\)" , line )
47+ if link and link .group (0 )[5 :].startswith ("../img/icons" ):
48+ icon_list .add (link .group (0 ).split ("/" , 3 )[3 ][:- 2 ])
49+ return icon_list
50+
51+
52+ def get_icon_filenames ():
53+ """Scan img/icons dir for filenames"""
54+ icon_dir = os .path .join (os .path .split (my_dir )[0 ], ".." , "static" , "img" , "icons" )
55+ filenames = set ()
56+ with os .scandir (icon_dir ) as files :
57+ for file in files :
58+ if not file .name .startswith ("." ) and file .is_file ():
59+ filenames .add (file .name )
60+ return filenames
61+
62+
63+ def test_all_icon_files_exist ():
64+ """Test if icons from css urls is a subset of filenames in icon dir"""
65+ icons = get_css_icon_names ()
66+ files = get_icon_filenames ()
67+ missing_icons = list (icons - files )
68+ assert not missing_icons
0 commit comments