From c092b644bf4778a0871259dadb275db67de56ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E4=BF=8A=E5=AE=8F?= Date: Mon, 21 Aug 2023 10:54:13 +0800 Subject: [PATCH] fix windows path problem --- dataframe_image/_browser_pdf.py | 20 ++++++++++---------- tests/test_convert.py | 18 ++++-------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/dataframe_image/_browser_pdf.py b/dataframe_image/_browser_pdf.py index 6a5651b..197decd 100644 --- a/dataframe_image/_browser_pdf.py +++ b/dataframe_image/_browser_pdf.py @@ -109,7 +109,8 @@ 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: @@ -117,7 +118,9 @@ def get_pdf_data(file_name, p): 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): @@ -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 diff --git a/tests/test_convert.py b/tests/test_convert.py index 364d0fb..45653a2 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -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" ) @@ -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: @@ -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): @@ -77,4 +66,5 @@ def test_matplotlib(self): execute=True, document_name=document_name, table_conversion="matplotlib", + output_dir="tests/test_output" )