11"""Tests for tinypages build using sphinx extensions."""
22
33import filecmp
4- from os . path import join as pjoin , dirname , isdir
4+ from pathlib import Path
55from subprocess import Popen , PIPE
66import sys
77
1212
1313
1414def test_tinypages (tmpdir ):
15- html_dir = pjoin (str (tmpdir ), 'html' )
16- doctree_dir = pjoin (str (tmpdir ), 'doctrees' )
15+ tmp_path = Path (tmpdir )
16+ html_dir = tmp_path / 'html'
17+ doctree_dir = tmp_path / 'doctrees'
1718 # Build the pages with warnings turned into errors
18- cmd = [sys .executable , '-msphinx' , '-W' , '-b' , 'html' , '-d' , doctree_dir ,
19- pjoin (dirname (__file__ ), 'tinypages' ), html_dir ]
19+ cmd = [sys .executable , '-msphinx' , '-W' , '-b' , 'html' ,
20+ '-d' , str (doctree_dir ),
21+ str (Path (__file__ ).parent / 'tinypages' ), str (html_dir )]
2022 proc = Popen (cmd , stdout = PIPE , stderr = PIPE , universal_newlines = True )
2123 out , err = proc .communicate ()
2224 assert proc .returncode == 0 , \
@@ -25,10 +27,10 @@ def test_tinypages(tmpdir):
2527 pytest .fail ("sphinx build emitted the following warnings:\n {}"
2628 .format (err ))
2729
28- assert isdir ( html_dir )
30+ assert html_dir . is_dir ( )
2931
3032 def plot_file (num ):
31- return pjoin ( html_dir , 'some_plots-{0 }.png' . format ( num ))
33+ return html_dir / f 'some_plots-{ num } .png'
3234
3335 range_10 , range_6 , range_4 = [plot_file (i ) for i in range (1 , 4 )]
3436 # Plot 5 is range(6) plot
@@ -43,11 +45,10 @@ def plot_file(num):
4345 # Plot 13 shows close-figs in action
4446 assert filecmp .cmp (range_4 , plot_file (13 ))
4547 # Plot 14 has included source
46- with open (pjoin (html_dir , 'some_plots.html' ), 'rb' ) as fobj :
47- html_contents = fobj .read ()
48+ html_contents = (html_dir / 'some_plots.html' ).read_bytes ()
4849 assert b'# Only a comment' in html_contents
4950 # check plot defined in external file.
50- assert filecmp .cmp (range_4 , pjoin ( html_dir , 'range4.png' ) )
51- assert filecmp .cmp (range_6 , pjoin ( html_dir , 'range6.png' ) )
51+ assert filecmp .cmp (range_4 , html_dir / 'range4.png' )
52+ assert filecmp .cmp (range_6 , html_dir / 'range6.png' )
5253 # check if figure caption made it into html file
5354 assert b'This is the caption for plot 15.' in html_contents
0 commit comments