Skip to content

Commit

Permalink
fix windows path problem
Browse files Browse the repository at this point in the history
  • Loading branch information
吕俊宏 committed Aug 21, 2023
1 parent d0fe738 commit c092b64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
20 changes: 10 additions & 10 deletions dataframe_image/_browser_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,18 @@ def get_html_data(nb, resources, **kw):
return html_data

# deprecated
def get_pdf_data(file_name, p):
def get_pdf_data(file_name):
p = launch_chrome()
try:
from asyncio import run
except ImportError:
from ._my_asyncio import run

with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
future = executor.submit(run, main(file_name, p))
return future.result()
data = future.result()
p.kill()
return data


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

html_data = get_html_data(nb, resources, **kw)
_, tf_name = mkstemp(dir=nb_home, suffix=".html")
with open(tf_name, "w", encoding="utf-8") as f:
fd, tf_name = mkstemp(dir=nb_home, suffix=".html")
with open(fd, "w", encoding="utf-8") as f:
f.write(html_data)
tf_path = Path(tf_name)
full_file_name = "file://" + urllib.parse.quote(tf_name)
# p = launch_chrome()
pdf_data = get_pdf_data_chromecontroller(full_file_name)
import os

file_uri = tf_path.as_uri()
# pdf_data = get_pdf_data_chromecontroller(file_uri)
pdf_data = get_pdf_data(file_uri)
os.remove(tf_path)
# p.kill()
return pdf_data, resources
18 changes: 4 additions & 14 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestConvertPDF:
def test_to_pdf(self, request, filename, use, execute, no_input):
document_name = tname_to_filename(request.node.name)
convert(
filename, to="pdf", use=use, execute=execute, document_name=document_name, no_input=no_input
filename, to="pdf", use=use, execute=execute, document_name=document_name, no_input=no_input, output_dir="tests/test_output"
)


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


class TestConvertOther:
Expand All @@ -53,18 +53,7 @@ def test_save_notebook(self):
save_notebook=True,
execute=True,
document_name=document_name,
)

def test_output_dir(self):
filename = "tests/notebooks/Short.ipynb"
to = "pdf"
document_name = Path(filename).stem + " output_dir NEW NAME"
convert(
filename,
to=to,
execute=True,
output_dir="tests/test_output",
document_name=document_name,
output_dir="tests/test_output"
)

def test_matplotlib(self):
Expand All @@ -77,4 +66,5 @@ def test_matplotlib(self):
execute=True,
document_name=document_name,
table_conversion="matplotlib",
output_dir="tests/test_output"
)

0 comments on commit c092b64

Please sign in to comment.