MCPcopy Index your code
hub / github.com/plotly/plotly.py / test_write_html

Function test_write_html

tests/test_io/test_pathlib.py:16–51  ·  view source on GitHub ↗

Verify that various methods for producing HTML have equivalent results. The results will not be identical because the div id is pseudorandom. Thus we compare the results after replacing the div id. We test the results of - pio.to_html - pio.write_html with a StringIO buffer

()

Source from the content-addressed store, hash-verified

14
15
16def test_write_html():
17 """Verify that various methods for producing HTML have equivalent results.
18
19 The results will not be identical because the div id is pseudorandom. Thus
20 we compare the results after replacing the div id.
21
22 We test the results of
23 - pio.to_html
24 - pio.write_html with a StringIO buffer
25 - pio.write_html with a mock pathlib Path
26 - pio.write_html with a mock file descriptor
27 """
28 # Test pio.to_html
29 html = pio.to_html(fig)
30
31 # Test pio.write_html with a StringIO buffer
32 sio = StringIO()
33 pio.write_html(fig, sio)
34 sio.seek(0) # Rewind to the beginning of the buffer, otherwise read() returns ''.
35 sio_html = sio.read()
36 assert replace_div_id(html) == replace_div_id(sio_html)
37
38 # Test pio.write_html with a mock pathlib Path
39 mock_pathlib_path = Mock(spec=Path)
40 pio.write_html(fig, mock_pathlib_path)
41 mock_pathlib_path.write_text.assert_called_once()
42 pl_html = mock_pathlib_path.write_text.call_args[0][0]
43 assert replace_div_id(html) == replace_div_id(pl_html)
44
45 # Test pio.write_html with a mock file descriptor
46 mock_file_descriptor = Mock()
47 del mock_file_descriptor.write_bytes
48 pio.write_html(fig, mock_file_descriptor)
49 mock_file_descriptor.write.assert_called_once()
50 (fd_html,) = mock_file_descriptor.write.call_args[0]
51 assert replace_div_id(html) == replace_div_id(fd_html)
52
53
54def replace_div_id(s):

Callers

nothing calls this directly

Calls 5

replace_div_idFunction · 0.85
to_htmlMethod · 0.80
write_htmlMethod · 0.80
readMethod · 0.80
seekMethod · 0.45

Tested by

no test coverage detected