@@ -119,7 +119,7 @@ def test_image_alt(og_meta_tags):
119
119
120
120
121
121
@pytest .mark .sphinx ('html' , testroot = 'simple' )
122
- def test_image_social_cards (meta_tags ):
122
+ def test_image_social_cards (content , meta_tags ):
123
123
"""Social cards should automatically be added if no og:image is given."""
124
124
pytest .importorskip ('matplotlib' )
125
125
# Asserting `in` instead of `==` because of the hash that is generated
@@ -136,6 +136,33 @@ def test_image_social_cards(meta_tags):
136
136
assert 'summary_large_image' in get_tag_content (
137
137
meta_tags , 'card' , kind = 'name' , prefix = 'twitter'
138
138
)
139
+ png_file = content .outdir / get_tag_content (meta_tags , 'image' ).split ('/' , 5 )[- 1 ]
140
+ assert png_file .is_file ()
141
+ # https://en.wikipedia.org/wiki/List_of_file_signatures
142
+ assert png_file .read_bytes ()[:8 ] == b'\x89 PNG\r \n \x1a \n '
143
+ assert get_tag_content (meta_tags , 'image:width' ) == '1146'
144
+ assert get_tag_content (meta_tags , 'image:height' ) == '600'
145
+
146
+
147
+ @pytest .mark .sphinx ('html' , testroot = 'custom-social-card-generation' )
148
+ def test_image_social_cards_custom (content , meta_tags ):
149
+ """Providing a custom generation function for social cards."""
150
+ # Asserting `in` instead of `==` because of the hash that is generated
151
+ assert (
152
+ 'http://example.org/en/latest/_images/social_previews/summary_index'
153
+ in get_tag_content (meta_tags , 'image' )
154
+ )
155
+ # Make sure the extra tags are in the HTML
156
+ assert 'summary_large_image' in get_tag_content (
157
+ meta_tags , 'card' , kind = 'name' , prefix = 'twitter'
158
+ )
159
+ assert get_tag_content (meta_tags , 'image:width' ) == '1'
160
+ assert get_tag_content (meta_tags , 'image:height' ) == '1'
161
+ png_file = content .outdir / get_tag_content (meta_tags , 'image' ).split ('/' , 5 )[- 1 ]
162
+ assert png_file .is_file ()
163
+ # https://en.wikipedia.org/wiki/List_of_file_signatures
164
+ assert png_file .read_bytes ()[:8 ] == b'\x89 PNG\r \n \x1a \n '
165
+ assert len (png_file .read_bytes ()) == 95 # Size of the provided pixel.png
139
166
140
167
141
168
@pytest .mark .sphinx ('html' , testroot = 'type' )
0 commit comments