Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mat2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jvoisin
mat2
Commits
3d284280
Commit
3d284280
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Split the tests
parent
a1a06d02
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_deep_cleaning.py
+72
-0
72 additions, 0 deletions
tests/test_deep_cleaning.py
tests/test_libmat2.py
+0
-64
0 additions, 64 deletions
tests/test_libmat2.py
with
72 additions
and
64 deletions
tests/test_deep_cleaning.py
0 → 100644
+
72
−
0
View file @
3d284280
#!/usr/bin/env python3
import
unittest
import
shutil
import
os
import
zipfile
import
tempfile
from
libmat2
import
office
,
parser_factory
class
TestZipMetadata
(
unittest
.
TestCase
):
def
__check_deep_meta
(
self
,
p
):
tempdir
=
tempfile
.
mkdtemp
()
zipin
=
zipfile
.
ZipFile
(
p
.
filename
)
zipin
.
extractall
(
tempdir
)
for
subdir
,
dirs
,
files
in
os
.
walk
(
tempdir
):
for
f
in
files
:
complete_path
=
os
.
path
.
join
(
subdir
,
f
)
inside_p
,
_
=
parser_factory
.
get_parser
(
complete_path
)
if
inside_p
is
None
:
continue
self
.
assertEqual
(
inside_p
.
get_meta
(),
{})
shutil
.
rmtree
(
tempdir
)
def
__check_zip_meta
(
self
,
p
):
zipin
=
zipfile
.
ZipFile
(
p
.
filename
)
for
item
in
zipin
.
infolist
():
self
.
assertEqual
(
item
.
comment
,
b
''
)
self
.
assertEqual
(
item
.
date_time
,
(
1980
,
1
,
1
,
0
,
0
,
0
))
self
.
assertEqual
(
item
.
create_system
,
3
)
# 3 is UNIX
def
test_office
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.docx
'
,
'
./tests/data/clean.docx
'
)
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.docx
'
)
meta
=
p
.
get_meta
()
self
.
assertIsNotNone
(
meta
)
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.cleaned.docx
'
)
self
.
assertEqual
(
p
.
get_meta
(),
{})
self
.
__check_zip_meta
(
p
)
self
.
__check_deep_meta
(
p
)
os
.
remove
(
'
./tests/data/clean.docx
'
)
os
.
remove
(
'
./tests/data/clean.cleaned.docx
'
)
def
test_libreoffice
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.odt
'
,
'
./tests/data/clean.odt
'
)
p
=
office
.
LibreOfficeParser
(
'
./tests/data/clean.odt
'
)
meta
=
p
.
get_meta
()
self
.
assertIsNotNone
(
meta
)
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
office
.
LibreOfficeParser
(
'
./tests/data/clean.cleaned.odt
'
)
self
.
assertEqual
(
p
.
get_meta
(),
{})
self
.
__check_zip_meta
(
p
)
self
.
__check_deep_meta
(
p
)
os
.
remove
(
'
./tests/data/clean.odt
'
)
os
.
remove
(
'
./tests/data/clean.cleaned.odt
'
)
This diff is collapsed.
Click to expand it.
tests/test_libmat2.py
+
0
−
64
View file @
3d284280
...
...
@@ -182,70 +182,6 @@ class TestRevisionsCleaning(unittest.TestCase):
os
.
remove
(
'
./tests/data/revision_clean.docx
'
)
os
.
remove
(
'
./tests/data/revision_clean.cleaned.docx
'
)
class
TestDeepCleaning
(
unittest
.
TestCase
):
def
__check_deep_meta
(
self
,
p
):
tempdir
=
tempfile
.
mkdtemp
()
zipin
=
zipfile
.
ZipFile
(
p
.
filename
)
zipin
.
extractall
(
tempdir
)
for
subdir
,
dirs
,
files
in
os
.
walk
(
tempdir
):
for
f
in
files
:
complete_path
=
os
.
path
.
join
(
subdir
,
f
)
inside_p
,
_
=
parser_factory
.
get_parser
(
complete_path
)
if
inside_p
is
None
:
continue
self
.
assertEqual
(
inside_p
.
get_meta
(),
{})
shutil
.
rmtree
(
tempdir
)
def
__check_zip_meta
(
self
,
p
):
zipin
=
zipfile
.
ZipFile
(
p
.
filename
)
for
item
in
zipin
.
infolist
():
self
.
assertEqual
(
item
.
comment
,
b
''
)
self
.
assertEqual
(
item
.
date_time
,
(
1980
,
1
,
1
,
0
,
0
,
0
))
self
.
assertEqual
(
item
.
create_system
,
3
)
# 3 is UNIX
def
test_office
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.docx
'
,
'
./tests/data/clean.docx
'
)
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.docx
'
)
meta
=
p
.
get_meta
()
self
.
assertIsNotNone
(
meta
)
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.cleaned.docx
'
)
self
.
assertEqual
(
p
.
get_meta
(),
{})
self
.
__check_zip_meta
(
p
)
self
.
__check_deep_meta
(
p
)
os
.
remove
(
'
./tests/data/clean.docx
'
)
os
.
remove
(
'
./tests/data/clean.cleaned.docx
'
)
def
test_libreoffice
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.odt
'
,
'
./tests/data/clean.odt
'
)
p
=
office
.
LibreOfficeParser
(
'
./tests/data/clean.odt
'
)
meta
=
p
.
get_meta
()
self
.
assertIsNotNone
(
meta
)
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
office
.
LibreOfficeParser
(
'
./tests/data/clean.cleaned.odt
'
)
self
.
assertEqual
(
p
.
get_meta
(),
{})
self
.
__check_zip_meta
(
p
)
self
.
__check_deep_meta
(
p
)
os
.
remove
(
'
./tests/data/clean.odt
'
)
os
.
remove
(
'
./tests/data/clean.cleaned.odt
'
)
class
TestLightWeightCleaning
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.pdf
'
,
'
./tests/data/clean.pdf
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment