1515from matplotlib .testing import _has_tex_package , _check_for_pgf
1616from matplotlib .testing .exceptions import ImageComparisonFailure
1717from matplotlib .testing .compare import compare_images
18- from matplotlib .backends .backend_pgf import PdfPages
18+ from matplotlib .backends .backend_pgf import _metadata_to_str , PdfPages
1919from matplotlib .testing .decorators import (
2020 _image_directories , check_figures_equal , image_comparison )
2121from matplotlib .testing ._markers import (
@@ -37,6 +37,26 @@ def compare_figure(fname, savefig_kwargs={}, tol=0):
3737 raise ImageComparisonFailure (err )
3838
3939
40+ @pytest .mark .parametrize ("key, value, expected_str" , [
41+ ("Author" , "me" , "Author={me}" ),
42+ ("ModDate" ,
43+ datetime .datetime (1968 , 8 , 1 , tzinfo = datetime .timezone (datetime .timedelta (0 ))),
44+ "ModDate={D:19680801000000Z}" ),
45+ ])
46+ def test__metadata_to_str (key , value , expected_str ):
47+ assert _metadata_to_str (key , value ) == expected_str
48+
49+
50+ @pytest .mark .parametrize ("value" , [
51+ r"Backslashes, e.g. in \commands" ,
52+ r"funny braces {}" ,
53+ r"and square brackets]" ,
54+ ])
55+ def test__metadata_to_str_error (value ):
56+ with pytest .raises (ValueError , match = "value must not contain the chars" ):
57+ _metadata_to_str ("Title" , value )
58+
59+
4060@needs_pgf_xelatex
4161@needs_ghostscript
4262@pytest .mark .backend ('pgf' )
0 commit comments