Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ typer==0.12.3
wftools==0.0.9
xlrd==2.0.1
xlwt==1.3.0

pofile~=0.1.5
poexcel~=0.0.22
poimage~=0.0.22
poprogress~=0.0.2
PyOfficeRobot~=0.1.21
popdf~=1.0.1
poppt~=0.1.1
pospider~=0.0.1
poword~=0.0.17
povideo~=0.0.8
pomarkdown~=0.0.3
Binary file added tests/test_files/images/pencil4img.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/test_files/md/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
程序员晚枫
Binary file modified tests/test_files/ppt/test_pdf.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_files/ruiming/change_label_in_xml/testfile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</size>
<segmented>0</segmented>
<object>
<name>测试1</name>
<name>测试</name>
<pose>Unspecified</pose>
<truncated>1</truncated>
<difficult>0</difficult>
Expand All @@ -24,7 +24,7 @@
</bndbox>
</object>
<object>
<name>测试1</name>
<name>测试</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
Expand Down
4 changes: 2 additions & 2 deletions tests/test_files/ruiming/change_label_in_xml/testfile1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</size>
<segmented>0</segmented>
<object>
<name>测试1</name>
<name>测试</name>
<pose>Unspecified</pose>
<truncated>1</truncated>
<difficult>0</difficult>
Expand All @@ -24,7 +24,7 @@
</bndbox>
</object>
<object>
<name>测试1</name>
<name>测试</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
Expand Down
Binary file removed tests/test_files/本目录文件列表.xlsx
Binary file not shown.
Binary file removed tests/test_unit/pencil4img.jpg
Binary file not shown.
Empty file removed tests/test_unit/test_dev.py
Empty file.
2 changes: 1 addition & 1 deletion tests/test_unit/test_excel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from test_excel_utils import *
from tests.test_utils.comm_utils import *
from office.api.excel import *


Expand Down
35 changes: 31 additions & 4 deletions tests/test_unit/test_file.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
import unittest

from office.api.file import *
from tests.test_utils.comm_utils import *

ORIGIN_FILE_NAME = '../test_files/file/add_fix/aabbccddeeffgghhppddaacc.docx'


class TestFile(unittest.TestCase):

def test_replace4filename(self):
touch_file(ORIGIN_FILE_NAME)
replace4filename(path='../test_files/file/add_fix', del_content='dd', replace_content='pp')
# 检查文件存在
self.assertTrue(file_exist('../test_files/file/add_fix/aabbccppeeffgghhppppaacc.docx'))
# 删除文件
delete_file('../test_files/file/add_fix/aabbccppeeffgghhppppaacc.docx')

def test_file_name_insert_content(self):
touch_file(ORIGIN_FILE_NAME)
file_name_insert_content(file_path=r"../test_files/file/add_fix",
insert_position=1, insert_content="插入内容测试")
insert_position=1, insert_content="111")
# 检查文件存在
self.assertTrue(file_exist('../test_files/file/add_fix/a111abbccddeeffgghhppddaacc.docx'))
# 删除文件
delete_file('../test_files/file/add_fix/a111abbccddeeffgghhppddaacc.docx')

def test_file_name_add_prefix(self):
touch_file(ORIGIN_FILE_NAME)
file_name_add_prefix(file_path=r'../test_files/file/add_fix', prefix_content='2022')
# 检查文件存在
self.assertTrue(file_exist('../test_files/file/add_fix/2022aabbccddeeffgghhppddaacc.docx'))
# 删除文件
delete_file('../test_files/file/add_fix/2022aabbccddeeffgghhppddaacc.docx')

def test_file_name_add_postfix(self):
touch_file(ORIGIN_FILE_NAME)
file_name_add_postfix(file_path=r"../test_files/file/add_fix",
postfix_content="添加后缀测试")
postfix_content="5555")
# 检查文件存在
self.assertTrue(file_exist('../test_files/file/add_fix/aabbccddeeffgghhppddaacc5555.docx'))
# 删除文件
delete_file('../test_files/file/add_fix/aabbccddeeffgghhppddaacc5555.docx')

def test_search_specify_type_file(self):
search_specify_type_file(file_path=r'../test_files/popdf', file_type='.popdf')
search_specify_type_file(file_path=r'../test_files/docx', file_type='.docx')

def test_output_file_list_to_excel(self):
output_file_list_to_excel("../test_files")
self.assertTrue(file_exist('../test_files/本目录文件列表.xlsx'))
# 删除文件
delete_file('../test_files/本目录文件列表.xlsx')

def test_search_by_content(self):
search_by_content(search_path=r'../test_files/docx', content='程序')

def test_get_files(self):
f = get_files(path=r'../test_files/docx')
print(f)
self.assertEqual(len(f), 1)
24 changes: 16 additions & 8 deletions tests/test_unit/test_image.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import unittest

from office.api.image import *
from tests.test_utils.comm_utils import *


class TestImage(unittest.TestCase):
def test_add_watermark(self):
add_watermark(file='../test_files/images/0816.jpg', mark='python-office',
output_path=r'../test_output/img_output')
self.assertTrue(file_exist('../test_output/img_output/0816.jpg'))
delete_file('../test_output/img_output/0816.jpg')

def test_com_img(self):
compress_image()
compress_image(input_file='../test_files/images/0816.jpg',
output_file='../test_output/img_output/0816.jpg', quality=50)
self.assertTrue(file_exist('../test_output/img_output/0816.jpg'))
delete_file('../test_output/img_output/0816.jpg')

def test_down4img(self):
down4img(url='https://python-office-1300615378.cos.ap-chongqing.myqcloud.com/python-office-qr.jpg',
output_path=r'D:\download\xunlei')

# def test_img2Cartoon(self):
# img2Cartoon()
output_path=r'../test_files/images')
self.assertTrue(file_exist('../test_files/images/down4img.jpg'))
delete_file('../test_files/images/down4img.jpg')

def test_txt2wordcloud(self):
txt2wordcloud(filename=r'D:\workplace\code\test\wordcloud\test.txt', color="white",
result_file="your_wordcloud.png")
txt2wordcloud(filename=r'../test_files/md/test.txt')
self.assertTrue(file_exist('your_wordcloud.png'))
delete_file('your_wordcloud.png')

def test_pencil4img(self):
pencil4img(input_img=r'D:\workplace\code\test\down4img\girl.jpg')
pencil4img(input_img=r'../test_files/images/pencil4img.jpg')
self.assertTrue(file_exist('pencil4img.jpg'))
delete_file('pencil4img.jpg')
18 changes: 7 additions & 11 deletions tests/test_unit/test_markdown.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import unittest

from office.api.markdown import *
from tests.test_utils.comm_utils import *


class TestMarkdown(unittest.TestCase):

class TestMarkdown():
# def test_markdown_link_image_to_base64(self, ):
# # TODO:提交测试文档
# markdown_link_image_to_base64(
# markdown_path=r"C:\Users\37386\PycharmProjects\python-office\testfile\markdown\test.md")
#
# def test_check_local_dir_image_link_markdown(self):
# # TODO:提交测试文档
# check_local_dir_image_link_markdown(
# markdown_path=r"C:\Users\37386\PycharmProjects\python-office\testfile\markdown\test.md",
# image_path=r"C:\Users\37386\PycharmProjects\python-office\testfile\markdown\test.assets")
def test_excel2markdown(self):
excel2markdown(input_file=r'../test_files/excel/fake2excel.xlsx', output_file=r'../test_files/markdown/test.md',
sheet_name=None)
self.assertTrue(file_exist('../test_files/markdown/test.md'))
delete_file('../test_files/markdown/test.md')
1 change: 1 addition & 0 deletions tests/test_unit/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_decrypt4pdf(self):
path=r'./test_files/popdf/encrypt.popdf',
password='123456'
)

def test_pdf2imgs(self):
pdf2imgs(
pdf_path =r'./test_files/popdf/in.popdf',
Expand Down
7 changes: 4 additions & 3 deletions tests/test_unit/test_ppt.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import unittest

from office.api.ppt import *
from test_excel_utils import *
from tests.test_utils.comm_utils import *


class TestPPT(unittest.TestCase):
def test_ppt2pdf(self):
ppt2pdf(path=r'../test_files/ppt/程序员晚枫的文档.pptx',
ppt2pdf(path=r'../test_files/ppt/程序员晚枫的ppt.pptx',
output_path=r'../test_files/ppt/ppt2pdf')
self.assertTrue(file_exist('../test_files/ppt/ppt2pdf/程序员晚枫的文档.pdf'))

# todo: 文件打开有异常
def test_ppt2img(self):
ppt2img(input_path=r'../test_files/ppt/程序员晚枫的文档.pptx',
ppt2img(input_path=r'../test_files/ppt/程序员晚枫的ppt.pptx',
output_path=r'../test_files/ppt/ppt2img')
11 changes: 9 additions & 2 deletions tests/test_unit/test_ruiming.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

from office.api.testApi.ruiming import screen_unmarked_image, change_label_in_xml, screen_without_label_json_file
from tests.test_utils.comm_utils import *


class TestRuiming(unittest.TestCase):
Expand All @@ -10,10 +11,16 @@ def test_screen_unmarked_image(self):

def test_change_label_in_xml(self):
# TODO:相对路径问题
change_label_in_xml(dir_path="./test_files/ruiming/change_label_in_xml", old_label="测试", new_label="测试1")
change_label_in_xml(dir_path="../test_files/ruiming/change_label_in_xml", old_label="测试", new_label="测试1")
# 预期结果:name标签内容从“测试”改为“测试1”
file_names = get_file_by_suffix('../test_files/ruiming/change_label_in_xml', 'xml')
for file_name in file_names:
names = get_all_name_values('../test_files/ruiming/change_label_in_xml/' + file_name)
self.assertNotIn('测试', names)
# 还原
change_label_in_xml(dir_path="../test_files/ruiming/change_label_in_xml", old_label="测试1", new_label="测试")

def test_screen_without_label_json_file(self):
# TODO:相对路径问题
screen_without_label_json_file(dir_path="./test_files/ruiming/screen_without_label_json_file")
screen_without_label_json_file(dir_path="../test_files/ruiming/screen_without_label_json_file")
# 预期结果:除1.json外均被移动到”无标签json文件“文件夹中
4 changes: 2 additions & 2 deletions tests/test_unit/test_search_by_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from office.api.file import *


class TestSBC():
class TestSBC(unittest.TestCase):
def test_search_by_content(self):
search_by_content(search_path=r'./test_files/', content='python-office')
search_by_content(search_path=r'../test_files/', content='python-office')
2 changes: 1 addition & 1 deletion tests/test_unit/test_video.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from test_excel_utils import *
from tests.test_utils.comm_utils import *
from office.api.video import *


Expand Down
4 changes: 3 additions & 1 deletion tests/test_unit/test_word.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from office.api.word import *
from test_excel_utils import *
from tests.test_utils.comm_utils import *


class TestWechat(unittest.TestCase):
Expand All @@ -13,9 +13,11 @@ def test_doc2docx(self):
output_name='abcd.docx')
# 检查文件是否存在
self.assertTrue(file_exist('../test_output/word/abcd.docx'))
delete_file('../test_output/word/abcd.docx')

def test_docx2doc(self):
docx2doc(input_path=r'../test_output/word/abcd.docx', output_path=r'../test_output/word',
output_name='abce')
# 检查文件是否存在
self.assertTrue(file_exist('../test_output/word/abce.doc'))
delete_file('../test_output/word/abce.doc')
Loading