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
74f2d504
Commit
74f2d504
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Split the testsuite a bit and add more tests
parent
b4ef0c96
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libmat2/audio.py
+11
-0
11 additions, 0 deletions
libmat2/audio.py
tests/test_corrupted_files.py
+88
-0
88 additions, 0 deletions
tests/test_corrupted_files.py
tests/test_libmat2.py
+0
-66
0 additions, 66 deletions
tests/test_libmat2.py
with
99 additions
and
66 deletions
libmat2/audio.py
+
11
−
0
View file @
74f2d504
...
...
@@ -6,6 +6,17 @@ from . import abstract
class
MutagenParser
(
abstract
.
AbstractParser
):
def
__init__
(
self
,
filename
):
super
().
__init__
(
filename
)
try
:
mutagen
.
File
(
self
.
filename
)
except
mutagen
.
flac
.
MutagenError
:
raise
ValueError
except
mutagen
.
mp3
.
MutagenError
:
raise
ValueError
except
mutagen
.
ogg
.
MutagenError
:
raise
ValueError
def
get_meta
(
self
):
f
=
mutagen
.
File
(
self
.
filename
)
if
f
.
tags
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_corrupted_files.py
0 → 100644
+
88
−
0
View file @
74f2d504
#!/usr/bin/python3
import
unittest
import
shutil
import
os
from
libmat2
import
pdf
,
images
,
audio
,
office
,
parser_factory
,
torrent
class
TestUnsupportedFiles
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/test_libmat2.py
'
,
'
./tests/clean.py
'
)
parser
,
mimetype
=
parser_factory
.
get_parser
(
'
./tests/data/clean.py
'
)
self
.
assertEqual
(
mimetype
,
'
text/x-python
'
)
self
.
assertEqual
(
parser
,
None
)
os
.
remove
(
'
./tests/clean.py
'
)
class
TestExplicitelyUnsupportedFiles
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/test_libmat2.py
'
,
'
./tests/clean.txt
'
)
parser
,
mimetype
=
parser_factory
.
get_parser
(
'
./tests/data/clean.txt
'
)
self
.
assertEqual
(
mimetype
,
'
text/plain
'
)
self
.
assertEqual
(
parser
,
None
)
os
.
remove
(
'
./tests/clean.txt
'
)
class
TestCorruptedFiles
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.png
'
)
with
self
.
assertRaises
(
ValueError
):
pdf
.
PDFParser
(
'
./tests/data/clean.png
'
)
os
.
remove
(
'
./tests/data/clean.png
'
)
def
test_png
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.pdf
'
,
'
./tests/data/clean.pdf
'
)
with
self
.
assertRaises
(
ValueError
):
images
.
PNGParser
(
'
./tests/data/clean.pdf
'
)
os
.
remove
(
'
./tests/data/clean.pdf
'
)
def
test_png2
(
self
):
shutil
.
copy
(
'
./tests/test_libmat2.py
'
,
'
./tests/clean.png
'
)
parser
,
mimetype
=
parser_factory
.
get_parser
(
'
./tests/clean.png
'
)
self
.
assertIsNone
(
parser
)
os
.
remove
(
'
./tests/clean.png
'
)
def
test_torrent
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.torrent
'
)
p
=
torrent
.
TorrentParser
(
'
./tests/data/clean.torrent
'
)
self
.
assertFalse
(
p
.
remove_all
())
expected
=
{
'
Unknown meta
'
:
'
Unable to parse torrent file
"
./tests/data/clean.torrent
"
.
'
}
self
.
assertEqual
(
p
.
get_meta
(),
expected
)
with
open
(
"
./tests/data/clean.torrent
"
,
"
a
"
)
as
f
:
f
.
write
(
"
trailing garbage
"
)
p
=
torrent
.
TorrentParser
(
'
./tests/data/clean.torrent
'
)
self
.
assertEqual
(
p
.
get_meta
(),
expected
)
os
.
remove
(
'
./tests/data/clean.torrent
'
)
def
test_odg
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.odg
'
)
with
self
.
assertRaises
(
ValueError
):
office
.
LibreOfficeParser
(
'
./tests/data/clean.odg
'
)
os
.
remove
(
'
./tests/data/clean.odg
'
)
def
test_bmp
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.bmp
'
)
with
self
.
assertRaises
(
ValueError
):
images
.
BMPParser
(
'
./tests/data/clean.bmp
'
)
os
.
remove
(
'
./tests/data/clean.bmp
'
)
def
test_docx
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.docx
'
)
with
self
.
assertRaises
(
ValueError
):
office
.
MSOfficeParser
(
'
./tests/data/clean.docx
'
)
os
.
remove
(
'
./tests/data/clean.docx
'
)
def
test_flac
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.flac
'
)
with
self
.
assertRaises
(
ValueError
):
audio
.
FLACParser
(
'
./tests/data/clean.flac
'
)
os
.
remove
(
'
./tests/data/clean.flac
'
)
def
test_mp3
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.mp3
'
)
with
self
.
assertRaises
(
ValueError
):
audio
.
MP3Parser
(
'
./tests/data/clean.mp3
'
)
os
.
remove
(
'
./tests/data/clean.mp3
'
)
This diff is collapsed.
Click to expand it.
tests/test_libmat2.py
+
0
−
66
View file @
74f2d504
...
...
@@ -40,72 +40,6 @@ class TestUnsupportedEmbeddedFiles(unittest.TestCase):
self
.
assertFalse
(
p
.
remove_all
())
os
.
remove
(
'
./tests/data/clean.docx
'
)
class
TestUnsupportedFiles
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/test_libmat2.py
'
,
'
./tests/clean.py
'
)
parser
,
mimetype
=
parser_factory
.
get_parser
(
'
./tests/data/clean.py
'
)
self
.
assertEqual
(
mimetype
,
'
text/x-python
'
)
self
.
assertEqual
(
parser
,
None
)
os
.
remove
(
'
./tests/clean.py
'
)
class
TestExplicitelyUnsupportedFiles
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/test_libmat2.py
'
,
'
./tests/clean.txt
'
)
parser
,
mimetype
=
parser_factory
.
get_parser
(
'
./tests/data/clean.txt
'
)
self
.
assertEqual
(
mimetype
,
'
text/plain
'
)
self
.
assertEqual
(
parser
,
None
)
os
.
remove
(
'
./tests/clean.txt
'
)
class
TestCorruptedFiles
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.png
'
)
with
self
.
assertRaises
(
ValueError
):
pdf
.
PDFParser
(
'
./tests/data/clean.png
'
)
os
.
remove
(
'
./tests/data/clean.png
'
)
def
test_png
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.pdf
'
,
'
./tests/data/clean.pdf
'
)
with
self
.
assertRaises
(
ValueError
):
images
.
PNGParser
(
'
./tests/data/clean.pdf
'
)
os
.
remove
(
'
./tests/data/clean.pdf
'
)
def
test_png2
(
self
):
shutil
.
copy
(
'
./tests/test_libmat2.py
'
,
'
./tests/clean.png
'
)
parser
,
mimetype
=
parser_factory
.
get_parser
(
'
./tests/clean.png
'
)
self
.
assertIsNone
(
parser
)
os
.
remove
(
'
./tests/clean.png
'
)
def
test_torrent
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.torrent
'
)
p
=
torrent
.
TorrentParser
(
'
./tests/data/clean.torrent
'
)
self
.
assertFalse
(
p
.
remove_all
())
expected
=
{
'
Unknown meta
'
:
'
Unable to parse torrent file
"
./tests/data/clean.torrent
"
.
'
}
self
.
assertEqual
(
p
.
get_meta
(),
expected
)
with
open
(
"
./tests/data/clean.torrent
"
,
"
a
"
)
as
f
:
f
.
write
(
"
trailing garbage
"
)
p
=
torrent
.
TorrentParser
(
'
./tests/data/clean.torrent
'
)
self
.
assertEqual
(
p
.
get_meta
(),
expected
)
os
.
remove
(
'
./tests/data/clean.torrent
'
)
def
test_odg
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.odg
'
)
with
self
.
assertRaises
(
ValueError
):
office
.
LibreOfficeParser
(
'
./tests/data/clean.odg
'
)
os
.
remove
(
'
./tests/data/clean.odg
'
)
def
test_bmp
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.bmp
'
)
with
self
.
assertRaises
(
ValueError
):
p
=
images
.
BMPParser
(
'
./tests/data/clean.bmp
'
)
os
.
remove
(
'
./tests/data/clean.bmp
'
)
def
test_docx
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.png
'
,
'
./tests/data/clean.docx
'
)
with
self
.
assertRaises
(
ValueError
):
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.docx
'
)
os
.
remove
(
'
./tests/data/clean.docx
'
)
class
TestGetMeta
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
...
...
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