1
1
"""Tests for tinypages build using sphinx extensions."""
2
2
3
3
import filecmp
4
- from os . path import join as pjoin , dirname , isdir
4
+ from pathlib import Path
5
5
from subprocess import Popen , PIPE
6
6
import sys
7
7
12
12
13
13
14
14
def 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'
17
18
# 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 )]
20
22
proc = Popen (cmd , stdout = PIPE , stderr = PIPE , universal_newlines = True )
21
23
out , err = proc .communicate ()
22
24
assert proc .returncode == 0 , \
@@ -25,10 +27,10 @@ def test_tinypages(tmpdir):
25
27
pytest .fail ("sphinx build emitted the following warnings:\n {}"
26
28
.format (err ))
27
29
28
- assert isdir ( html_dir )
30
+ assert html_dir . is_dir ( )
29
31
30
32
def plot_file (num ):
31
- return pjoin ( html_dir , 'some_plots-{0 }.png' . format ( num ))
33
+ return html_dir / f 'some_plots-{ num } .png'
32
34
33
35
range_10 , range_6 , range_4 = [plot_file (i ) for i in range (1 , 4 )]
34
36
# Plot 5 is range(6) plot
@@ -43,11 +45,10 @@ def plot_file(num):
43
45
# Plot 13 shows close-figs in action
44
46
assert filecmp .cmp (range_4 , plot_file (13 ))
45
47
# 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 ()
48
49
assert b'# Only a comment' in html_contents
49
50
# 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' )
52
53
# check if figure caption made it into html file
53
54
assert b'This is the caption for plot 15.' in html_contents
0 commit comments