Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
MinerU
Commits
59ad2737
"vscode:/vscode.git/clone" did not exist on "921ab01217c0903b4d4f3ed42924ef751ada10d3"
Commit
59ad2737
authored
Nov 17, 2024
by
quyuan
Browse files
update test case
parent
12ced4f3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
25 deletions
+113
-25
tests/test_cli/conftest.py
tests/test_cli/conftest.py
+0
-7
tests/test_cli/lib/common.py
tests/test_cli/lib/common.py
+15
-4
tests/test_cli/test_cli_sdk.py
tests/test_cli/test_cli_sdk.py
+98
-14
No files found.
tests/test_cli/conftest.py
View file @
59ad2737
...
@@ -8,10 +8,3 @@ def clear_gpu_memory():
...
@@ -8,10 +8,3 @@ def clear_gpu_memory():
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
print
(
"GPU memory cleared."
)
print
(
"GPU memory cleared."
)
@
pytest
.
hookimpl
(
tryfirst
=
True
,
hookwrapper
=
True
)
def
pytest_runtest_teardown
(
item
,
nextitem
):
'''
clear GPU memory after each test
'''
yield
clear_gpu_memory
()
\ No newline at end of file
tests/test_cli/lib/common.py
View file @
59ad2737
...
@@ -3,6 +3,15 @@ import os
...
@@ -3,6 +3,15 @@ import os
import
shutil
import
shutil
import
re
import
re
import
json
import
json
import
torch
def
clear_gpu_memory
():
'''
clear GPU memory
'''
torch
.
cuda
.
empty_cache
()
print
(
"GPU memory cleared."
)
def
check_shell
(
cmd
):
def
check_shell
(
cmd
):
"""shell successful."""
"""shell successful."""
res
=
os
.
system
(
cmd
)
res
=
os
.
system
(
cmd
)
...
@@ -10,11 +19,12 @@ def check_shell(cmd):
...
@@ -10,11 +19,12 @@ def check_shell(cmd):
def
update_config_file
(
file_path
,
key
,
value
):
def
update_config_file
(
file_path
,
key
,
value
):
"""update config file."""
"""update config file."""
with
open
(
file_path
,
'r'
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
file_path
,
'r'
,
encoding
=
"utf-8"
)
as
f
r
:
config
=
json
.
loads
(
f
.
read
())
config
=
json
.
loads
(
f
r
.
read
())
config
[
key
]
=
value
config
[
key
]
=
value
with
open
(
file_path
,
'w'
,
encoding
=
"utf-8"
)
as
f
:
# 保存修改后的内容
f
.
write
(
json
.
dumps
(
config
))
with
open
(
file_path
,
'w'
,
encoding
=
'utf-8'
)
as
fw
:
json
.
dump
(
config
,
fw
,
ensure_ascii
=
False
,
indent
=
4
)
def
cli_count_folders_and_check_contents
(
file_path
):
def
cli_count_folders_and_check_contents
(
file_path
):
"""" count cli files."""
"""" count cli files."""
...
@@ -33,6 +43,7 @@ def sdk_count_folders_and_check_contents(file_path):
...
@@ -33,6 +43,7 @@ def sdk_count_folders_and_check_contents(file_path):
exit
(
1
)
exit
(
1
)
def
delete_file
(
path
):
def
delete_file
(
path
):
"""delete file."""
"""delete file."""
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
...
...
tests/test_cli/test_cli_sdk.py
View file @
59ad2737
...
@@ -13,10 +13,19 @@ model_config.__use_inside_model__ = True
...
@@ -13,10 +13,19 @@ model_config.__use_inside_model__ = True
pdf_res_path
=
conf
.
conf
[
'pdf_res_path'
]
pdf_res_path
=
conf
.
conf
[
'pdf_res_path'
]
code_path
=
conf
.
conf
[
'code_path'
]
code_path
=
conf
.
conf
[
'code_path'
]
pdf_dev_path
=
conf
.
conf
[
'pdf_dev_path'
]
pdf_dev_path
=
conf
.
conf
[
'pdf_dev_path'
]
magic_pdf_config
=
"/home/quyuan/magic-pdf.json"
class
TestCli
:
class
TestCli
:
"""test cli."""
"""test cli."""
@
pytest
.
fixture
(
autouse
=
True
)
def
setup
(
self
):
"""
init
"""
common
.
clear_gpu_memory
()
common
.
update_config_file
(
magic_pdf_config
,
"device-mode"
,
"cuda"
)
# 这里可以添加任何前置操作
yield
@
pytest
.
mark
.
P0
@
pytest
.
mark
.
P0
def
test_pdf_auto_sdk
(
self
):
def
test_pdf_auto_sdk
(
self
):
...
@@ -291,22 +300,32 @@ class TestCli:
...
@@ -291,22 +300,32 @@ class TestCli:
def
test_local_magic_pdf_open_st_table
(
self
):
def
test_local_magic_pdf_open_st_table
(
self
):
"""magic pdf cli open st table."""
"""magic pdf cli open st table."""
time
.
sleep
(
2
)
time
.
sleep
(
2
)
pre_cmd
=
"cp ~/magic_pdf_st.json ~/magic-pdf.json"
#pre_cmd = "cp ~/magic_pdf_st.json ~/magic-pdf.json"
print
(
pre_cmd
)
value
=
{
os
.
system
(
pre_cmd
)
"model"
:
"struct_eqtable"
,
"enable"
:
True
,
"max_time"
:
400
}
common
.
update_config_file
(
magic_pdf_config
,
"table-config"
,
value
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
common
.
delete_file
(
pdf_res_path
)
common
.
delete_file
(
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
os
.
system
(
cli_cmd
)
os
.
system
(
cli_cmd
)
res
=
common
.
check_
latex
_table_exists
(
os
.
path
.
join
(
pdf_res_path
,
"test_rearch_report"
,
"auto"
,
"test_rearch_report.md"
))
res
=
common
.
check_
html
_table_exists
(
os
.
path
.
join
(
pdf_res_path
,
"test_rearch_report"
,
"auto"
,
"test_rearch_report.md"
))
assert
res
is
True
assert
res
is
True
@
pytest
.
mark
.
P1
@
pytest
.
mark
.
P1
def
test_local_magic_pdf_open_
html_
table
(
self
):
def
test_local_magic_pdf_open_table
master_cuda
(
self
):
"""magic pdf cli open
html tabl
e."""
"""magic pdf cli open
table master html table cuda mod
e."""
time
.
sleep
(
2
)
time
.
sleep
(
2
)
pre_cmd
=
"cp ~/magic_pdf_html.json ~/magic-pdf.json"
#pre_cmd = "cp ~/magic_pdf_html.json ~/magic-pdf.json"
os
.
system
(
pre_cmd
)
#os.system(pre_cmd)
value
=
{
"model"
:
"tablemaster"
,
"enable"
:
True
,
"max_time"
:
400
}
common
.
update_config_file
(
magic_pdf_config
,
"table-config"
,
value
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
common
.
delete_file
(
pdf_res_path
)
common
.
delete_file
(
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
...
@@ -315,11 +334,69 @@ class TestCli:
...
@@ -315,11 +334,69 @@ class TestCli:
assert
res
is
True
assert
res
is
True
@
pytest
.
mark
.
P1
@
pytest
.
mark
.
P1
def
test_magic_pdf_close_html_table_cpu
(
self
):
def
test_local_magic_pdf_open_rapidai_table
(
self
):
"""magic pdf cli open rapid ai table."""
time
.
sleep
(
2
)
#pre_cmd = "cp ~/magic_pdf_html.json ~/magic-pdf.json"
#os.system(pre_cmd)
value
=
{
"model"
:
"rapid_table"
,
"enable"
:
True
,
"max_time"
:
400
}
common
.
update_config_file
(
magic_pdf_config
,
"table-config"
,
value
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
common
.
delete_file
(
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
os
.
system
(
cli_cmd
)
res
=
common
.
check_html_table_exists
(
os
.
path
.
join
(
pdf_res_path
,
"test_rearch_report"
,
"auto"
,
"test_rearch_report.md"
))
assert
res
is
True
@
pytest
.
mark
.
P1
def
test_local_magic_pdf_doclayout_yolo
(
self
):
"""magic pdf cli open doclyaout yolo."""
time
.
sleep
(
2
)
#pre_cmd = "cp ~/magic_pdf_html.json ~/magic-pdf.json"
#os.system(pre_cmd)
value
=
{
"model"
:
"doclayout_yolo"
}
common
.
update_config_file
(
magic_pdf_config
,
"layout-config"
,
value
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
common
.
delete_file
(
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
os
.
system
(
cli_cmd
)
common
.
cli_count_folders_and_check_contents
(
os
.
path
.
join
(
pdf_res_path
,
"test_rearch_report"
,
"auto"
))
@
pytest
.
mark
.
P1
def
test_local_magic_pdf_layoutlmv3_yolo
(
self
):
"""magic pdf cli open layoutlmv3."""
time
.
sleep
(
2
)
value
=
{
"model"
:
"layoutlmv3"
}
common
.
update_config_file
(
magic_pdf_config
,
"layout-config"
,
value
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
common
.
delete_file
(
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
os
.
system
(
cli_cmd
)
common
.
cli_count_folders_and_check_contents
(
os
.
path
.
join
(
pdf_res_path
,
"test_rearch_report"
,
"auto"
))
#res = common.check_html_table_exists(os.path.join(pdf_res_path, "test_rearch_report", "auto", "test_rearch_report.md"))
@
pytest
.
mark
.
P1
def
test_magic_pdf_open_tablemaster_table_cpu
(
self
):
"""magic pdf cli close html table cpu mode."""
"""magic pdf cli close html table cpu mode."""
time
.
sleep
(
2
)
time
.
sleep
(
2
)
pre_cmd
=
"cp ~/magic_pdf_html_table_cpu.json ~/magic-pdf.json"
#pre_cmd = "cp ~/magic_pdf_html_table_cpu.json ~/magic-pdf.json"
os
.
system
(
pre_cmd
)
#os.system(pre_cmd)
value
=
{
"model"
:
"tablemaster"
,
"enable"
:
True
,
"max_time"
:
400
}
common
.
update_config_file
(
magic_pdf_config
,
"table-config"
,
value
)
common
.
update_config_file
(
magic_pdf_config
,
"device-mode"
,
"cpu"
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
common
.
delete_file
(
pdf_res_path
)
common
.
delete_file
(
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
...
@@ -327,12 +404,19 @@ class TestCli:
...
@@ -327,12 +404,19 @@ class TestCli:
res
=
common
.
check_html_table_exists
(
os
.
path
.
join
(
pdf_res_path
,
"test_rearch_report"
,
"auto"
,
"test_rearch_report.md"
))
res
=
common
.
check_html_table_exists
(
os
.
path
.
join
(
pdf_res_path
,
"test_rearch_report"
,
"auto"
,
"test_rearch_report.md"
))
assert
res
is
True
assert
res
is
True
@
pytest
.
mark
.
P1
@
pytest
.
mark
.
P1
def
test_local_magic_pdf_close_html_table
(
self
):
def
test_local_magic_pdf_close_html_table
(
self
):
"""magic pdf cli close table."""
"""magic pdf cli close table."""
time
.
sleep
(
2
)
time
.
sleep
(
2
)
pre_cmd
=
"cp ~/magic_pdf_close_table.json ~/magic-pdf.json"
#pre_cmd = "cp ~/magic_pdf_close_table.json ~/magic-pdf.json"
os
.
system
(
pre_cmd
)
#os.system(pre_cmd)
value
=
{
"model"
:
"tablemaster"
,
"enable"
:
False
,
"max_time"
:
400
}
common
.
update_config_file
(
magic_pdf_config
,
"table-config"
,
value
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
pdf_path
=
os
.
path
.
join
(
pdf_dev_path
,
"pdf"
,
"test_rearch_report.pdf"
)
common
.
delete_file
(
pdf_res_path
)
common
.
delete_file
(
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
cli_cmd
=
"magic-pdf -p %s -o %s"
%
(
pdf_path
,
pdf_res_path
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment