Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mat2
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
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
atenart
mat2
Commits
46bb1b83
Commit
46bb1b83
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Improve the previous commit
parent
1d7e374e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
libmat2/office.py
+5
-3
5 additions, 3 deletions
libmat2/office.py
mat2
+2
-2
2 additions, 2 deletions
mat2
tests/test_climat2.py
+2
-2
2 additions, 2 deletions
tests/test_climat2.py
tests/test_policy.py
+31
-0
31 additions, 0 deletions
tests/test_policy.py
with
40 additions
and
7 deletions
libmat2/office.py
+
5
−
3
View file @
46bb1b83
...
...
@@ -84,6 +84,11 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
def
remove_all
(
self
)
->
bool
:
# pylint: disable=too-many-branches
if
self
.
unknown_member_policy
not
in
[
'
omit
'
,
'
keep
'
,
'
abort
'
]:
logging
.
error
(
"
The policy %s is invalid.
"
,
self
.
unknown_member_policy
)
raise
ValueError
with
zipfile
.
ZipFile
(
self
.
filename
)
as
zin
,
\
zipfile
.
ZipFile
(
self
.
output_filename
,
'
w
'
)
as
zout
:
...
...
@@ -120,9 +125,6 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
logging
.
warning
(
"
In file %s, keeping unknown element %s (format: %s)
"
,
self
.
filename
,
item
.
filename
,
mtype
)
else
:
if
self
.
unknown_member_policy
!=
'
abort
'
:
logging
.
warning
(
"
Invalid unknown_member_policy %s,
"
+
"
treating as
'
abort
'"
,
self
.
unknown_member_policy
)
logging
.
error
(
"
In file %s, element %s
'
s format (%s)
"
+
"
isn
'
t supported
"
,
self
.
filename
,
item
.
filename
,
mtype
)
...
...
This diff is collapsed.
Click to expand it.
mat2
+
2
−
2
View file @
46bb1b83
...
...
@@ -41,9 +41,9 @@ def create_arg_parser():
help
=
'
check if MAT2 has all the dependencies it needs
'
)
parser
.
add_argument
(
'
-V
'
,
'
--verbose
'
,
action
=
'
store_true
'
,
help
=
'
show more verbose status information
'
)
parser
.
add_argument
(
'
-u
'
,
'
--unknown-members
'
,
metavar
=
'
POLICY
'
,
default
=
'
abort
'
,
parser
.
add_argument
(
'
-u
'
,
'
--unknown-members
'
,
metavar
=
'
policy
'
,
default
=
'
abort
'
,
help
=
'
how to handle unknown members of archive-style files
'
+
'
(
POLICY
should be abort, omit, or keep)
'
)
'
(
policy
should be abort, omit, or keep)
'
)
info
=
parser
.
add_mutually_exclusive_group
()
...
...
This diff is collapsed.
Click to expand it.
tests/test_climat2.py
+
2
−
2
View file @
46bb1b83
...
...
@@ -8,13 +8,13 @@ class TestHelp(unittest.TestCase):
def
test_help
(
self
):
proc
=
subprocess
.
Popen
([
'
./mat2
'
,
'
--help
'
],
stdout
=
subprocess
.
PIPE
)
stdout
,
_
=
proc
.
communicate
()
self
.
assertIn
(
b
'
usage: mat2 [-h] [-v] [-l] [-c] [-V] [-u
POLICY
] [-s | -L] [files [files ...]]
'
,
self
.
assertIn
(
b
'
usage: mat2 [-h] [-v] [-l] [-c] [-V] [-u
policy
] [-s | -L] [files [files ...]]
'
,
stdout
)
def
test_no_arg
(
self
):
proc
=
subprocess
.
Popen
([
'
./mat2
'
],
stdout
=
subprocess
.
PIPE
)
stdout
,
_
=
proc
.
communicate
()
self
.
assertIn
(
b
'
usage: mat2 [-h] [-v] [-l] [-c] [-V] [-u
POLICY
] [-s | -L] [files [files ...]]
'
,
self
.
assertIn
(
b
'
usage: mat2 [-h] [-v] [-l] [-c] [-V] [-u
policy
] [-s | -L] [files [files ...]]
'
,
stdout
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_policy.py
0 → 100644
+
31
−
0
View file @
46bb1b83
#!/usr/bin/python3
import
unittest
import
shutil
import
os
from
libmat2
import
office
class
TestPolicy
(
unittest
.
TestCase
):
def
test_policy_omit
(
self
):
shutil
.
copy
(
'
./tests/data/embedded.docx
'
,
'
./tests/data/clean.docx
'
)
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.docx
'
)
p
.
unknown_member_policy
=
'
omit
'
self
.
assertTrue
(
p
.
remove_all
())
os
.
remove
(
'
./tests/data/clean.docx
'
)
def
test_policy_keep
(
self
):
shutil
.
copy
(
'
./tests/data/embedded.docx
'
,
'
./tests/data/clean.docx
'
)
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.docx
'
)
p
.
unknown_member_policy
=
'
keep
'
self
.
assertTrue
(
p
.
remove_all
())
os
.
remove
(
'
./tests/data/clean.docx
'
)
def
test_policy_unknown
(
self
):
shutil
.
copy
(
'
./tests/data/embedded.docx
'
,
'
./tests/data/clean.docx
'
)
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.docx
'
)
p
.
unknown_member_policy
=
'
unknown_policy_name_totally_invalid
'
with
self
.
assertRaises
(
ValueError
):
p
.
remove_all
()
os
.
remove
(
'
./tests/data/clean.docx
'
)
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