Skip to content

Commit c092b64

Browse files
author
吕俊宏
committed
fix windows path problem
1 parent d0fe738 commit c092b64

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

dataframe_image/_browser_pdf.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,18 @@ def get_html_data(nb, resources, **kw):
109109
return html_data
110110

111111
# deprecated
112-
def get_pdf_data(file_name, p):
112+
def get_pdf_data(file_name):
113+
p = launch_chrome()
113114
try:
114115
from asyncio import run
115116
except ImportError:
116117
from ._my_asyncio import run
117118

118119
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
119120
future = executor.submit(run, main(file_name, p))
120-
return future.result()
121+
data = future.result()
122+
p.kill()
123+
return data
121124

122125

123126
def get_pdf_data_chromecontroller(file_name):
@@ -153,15 +156,12 @@ def from_notebook_node(self, nb, resources=None, **kw):
153156
nb_home = resources["metadata"]["path"]
154157

155158
html_data = get_html_data(nb, resources, **kw)
156-
_, tf_name = mkstemp(dir=nb_home, suffix=".html")
157-
with open(tf_name, "w", encoding="utf-8") as f:
159+
fd, tf_name = mkstemp(dir=nb_home, suffix=".html")
160+
with open(fd, "w", encoding="utf-8") as f:
158161
f.write(html_data)
159162
tf_path = Path(tf_name)
160-
full_file_name = "file://" + urllib.parse.quote(tf_name)
161-
# p = launch_chrome()
162-
pdf_data = get_pdf_data_chromecontroller(full_file_name)
163-
import os
164-
163+
file_uri = tf_path.as_uri()
164+
# pdf_data = get_pdf_data_chromecontroller(file_uri)
165+
pdf_data = get_pdf_data(file_uri)
165166
os.remove(tf_path)
166-
# p.kill()
167167
return pdf_data, resources

tests/test_convert.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TestConvertPDF:
2929
def test_to_pdf(self, request, filename, use, execute, no_input):
3030
document_name = tname_to_filename(request.node.name)
3131
convert(
32-
filename, to="pdf", use=use, execute=execute, document_name=document_name, no_input=no_input
32+
filename, to="pdf", use=use, execute=execute, document_name=document_name, no_input=no_input, output_dir="tests/test_output"
3333
)
3434

3535

@@ -39,7 +39,7 @@ def test_to_pdf(self, request, filename, use, execute, no_input):
3939
class TestConvertMD:
4040
def test_to_md(self, request, filename, execute, no_input):
4141
document_name = tname_to_filename(request.node.name)
42-
convert(filename, to="md", execute=execute, document_name=document_name, no_input=no_input)
42+
convert(filename, to="md", execute=execute, document_name=document_name, no_input=no_input, output_dir="tests/test_output")
4343

4444

4545
class TestConvertOther:
@@ -53,18 +53,7 @@ def test_save_notebook(self):
5353
save_notebook=True,
5454
execute=True,
5555
document_name=document_name,
56-
)
57-
58-
def test_output_dir(self):
59-
filename = "tests/notebooks/Short.ipynb"
60-
to = "pdf"
61-
document_name = Path(filename).stem + " output_dir NEW NAME"
62-
convert(
63-
filename,
64-
to=to,
65-
execute=True,
66-
output_dir="tests/test_output",
67-
document_name=document_name,
56+
output_dir="tests/test_output"
6857
)
6958

7059
def test_matplotlib(self):
@@ -77,4 +66,5 @@ def test_matplotlib(self):
7766
execute=True,
7867
document_name=document_name,
7968
table_conversion="matplotlib",
69+
output_dir="tests/test_output"
8070
)

0 commit comments

Comments
 (0)