1- from matplotlib .testing .decorators import skip_if_command_unavailable
1+ import json
2+ from pathlib import Path
3+ import shutil
24
35import matplotlib .dviread as dr
4- import os .path
5- import json
66import pytest
77
88
99def test_PsfontsMap (monkeypatch ):
1010 monkeypatch .setattr (dr , 'find_tex_file' , lambda x : x )
1111
12- filename = os .path .join (
13- os .path .dirname (__file__ ),
14- 'baseline_images' , 'dviread' , 'test.map' )
12+ filename = str (Path (__file__ ).parent / 'baseline_images/dviread/test.map' )
1513 fontmap = dr .PsfontsMap (filename )
1614 # Check all properties of a few fonts
1715 for n in [1 , 2 , 3 , 4 , 5 ]:
18- key = ( 'TeXfont%d' % n ). encode ( 'ascii' )
16+ key = b 'TeXfont%d' % n
1917 entry = fontmap [key ]
2018 assert entry .texname == key
21- assert entry .psname == ( 'PSfont%d' % n ). encode ( 'ascii' )
19+ assert entry .psname == b 'PSfont%d' % n
2220 if n not in [3 , 5 ]:
23- assert entry .encoding == ( 'font%d.enc' % n ). encode ( 'ascii' )
21+ assert entry .encoding == b 'font%d.enc' % n
2422 elif n == 3 :
2523 assert entry .encoding == b'enc3.foo'
2624 # We don't care about the encoding of TeXfont5, which specifies
2725 # multiple encodings.
2826 if n not in [1 , 5 ]:
29- assert entry .filename == ( 'font%d.pfa' % n ). encode ( 'ascii' )
27+ assert entry .filename == b 'font%d.pfa' % n
3028 else :
31- assert entry .filename == ( 'font%d.pfb' % n ). encode ( 'ascii' )
29+ assert entry .filename == b 'font%d.pfb' % n
3230 if n == 4 :
3331 assert entry .effects == {'slant' : - 0.1 , 'extend' : 2.2 }
3432 else :
@@ -51,18 +49,16 @@ def test_PsfontsMap(monkeypatch):
5149 assert 'no-such-font' in str (exc .value )
5250
5351
54- @skip_if_command_unavailable (["kpsewhich" , "-version" ])
52+ @pytest .mark .skipif (shutil .which ("kpsewhich" ) is None ,
53+ reason = "kpsewhich is not available" )
5554def test_dviread ():
56- dir = os . path . join ( os . path . dirname ( __file__ ), 'baseline_images' , ' dviread')
57- with open ( os . path . join ( dir , 'test.json' )) as f :
55+ dirpath = Path ( __file__ ). parent / 'baseline_images/ dviread'
56+ with ( dirpath / 'test.json' ). open ( ) as f :
5857 correct = json .load (f )
59- for entry in correct :
60- entry ['text' ] = [[a , b , c , d .encode ('ascii' ), e ]
61- for [a , b , c , d , e ] in entry ['text' ]]
62- with dr .Dvi (os .path .join (dir , 'test.dvi' ), None ) as dvi :
58+ with dr .Dvi (str (dirpath / 'test.dvi' ), None ) as dvi :
6359 data = [{'text' : [[t .x , t .y ,
6460 chr (t .glyph ),
65- t .font .texname ,
61+ t .font .texname . decode ( 'ascii' ) ,
6662 round (t .font .size , 2 )]
6763 for t in page .text ],
6864 'boxes' : [[b .x , b .y , b .height , b .width ] for b in page .boxes ]}
0 commit comments