@@ -367,56 +367,55 @@ def test_mathtext_to_png(tmpdir):
367
367
368
368
369
369
def test_mathtext_fontset ():
370
- #This is my first time doing this kinds of tests, so I am not sure if I am
370
+ #This is my first time doing this kinds of tests, so I am not sure if I am
371
371
#doing it the right way, here's my plan for this testing:
372
372
#
373
- #1) Create two figures, one without my implementation
374
- # (should produce 2 texts with the same font)
373
+ #1) Create two figures, one without my implementation
374
+ # (should produce 2 texts with the same font)
375
375
# and one with (should create two texts with different fonts)
376
376
#2) Save the figures on Disk
377
377
#3) Load the figures and compare them, if they are equal, the test fails
378
- #4) Delete the figures
378
+ #4) Delete the figures
379
379
#
380
- # I am making the test a bit slower but avoiding the burden of adding
380
+ # I am making the test a bit slower but avoiding the burden of adding
381
381
# more figures to the repo. On my computer at least, the time for this
382
382
# test was of the order of a few seconds.
383
-
383
+
384
384
plt .rcParams ["mathtext.fontset" ] = "dejavusans"
385
385
386
386
#figure 1 setup
387
- #this figure IS NOT using the 'fontset' argument, therefore,
387
+ #this figure IS NOT using the 'fontset' argument, therefore,
388
388
#the font should be equal to the font set in rcParams["mathtext.fontset"]
389
- f1 , ax1 = plt .subplots (figsize = (12 ,10 ))
390
- ax1 .plot (range (11 ),color = "0.9" )
391
- ax1 .text (0.2 ,9 , r"$\mathit{This\ text\ should\ have\ a\ one\ font} $" ,
389
+ f1 , ax1 = plt .subplots (figsize = (12 , 10 ))
390
+ ax1 .plot (range (11 ), color = "0.9" )
391
+ ax1 .text (0.2 , 9 , r"$\mathit{This\ text\ should\ have\ a\ one\ font} $" ,
392
392
size = 18 )
393
-
394
- ax1 .text (0.2 ,8 , r"$\mathit{This\ text\ should\ have\ another} $" ,
393
+
394
+ ax1 .text (0.2 , 8 , r"$\mathit{This\ text\ should\ have\ another} $" ,
395
395
size = 18 )
396
-
396
+
397
397
#figure 2 setup
398
398
#this figure IS using the 'fontset' parameter and must have two texts
399
399
#with distinct fonts in the final image
400
- f2 , ax2 = plt .subplots (figsize = (12 ,10 ))
401
- ax2 .plot (range (11 ),color = "0.9" )
402
- ax2 .text (0.2 ,9 , r"$\mathit{This\ text\ should\ have\ a\ one\ font} $" ,
403
- size = 18 , fontset = 'dejavusans' )
404
-
405
- ax2 .text (0.2 ,8 , r"$\mathit{This\ text\ should\ have\ another} $" ,
406
- size = 18 , fontset = 'dejavuserif' )
407
-
400
+ f2 , ax2 = plt .subplots (figsize = (12 , 10 ))
401
+ ax2 .plot (range (11 ), color = "0.9" )
402
+ ax2 .text (0.2 , 9 , r"$\mathit{This\ text\ should\ have\ a\ one\ font} $" ,
403
+ size = 18 , fontset = 'dejavusans' )
404
+
405
+ ax2 .text (0.2 , 8 , r"$\mathit{This\ text\ should\ have\ another} $" ,
406
+ size = 18 , fontset = 'dejavuserif' )
407
+
408
408
f1 .savefig ('mathtext_fontset_image1.png' )
409
409
f2 .savefig ('mathtext_fontset_image2.png' )
410
-
410
+
411
411
figureLoaded1 = io .FileIO ('mathtext_fontset_image1.png' ).readall ()
412
412
figureLoaded2 = io .FileIO ('mathtext_fontset_image2.png' ).readall ()
413
-
413
+
414
414
figuresEqual = figureLoaded1 == figureLoaded2
415
-
415
+
416
416
os .remove ('mathtext_fontset_image1.png' )
417
417
os .remove ('mathtext_fontset_image2.png' )
418
-
418
+
419
419
#if the parameter fontset is not working, the figures will be equal and the
420
420
#test will fail
421
421
assert not figuresEqual
422
-
0 commit comments