1
0
mirror of synced 2024-11-25 18:54:22 +01:00

Fix some minor formatting issues

This commit is contained in:
jvoisin 2018-09-24 19:50:24 +02:00
parent 174d4a0ac0
commit 2e243355f5
8 changed files with 15 additions and 13 deletions

View File

@ -21,7 +21,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
# Those are the files that we _do not_ want to keep, # Those are the files that we _do not_ want to keep,
# no matter if they are supported or not. # no matter if they are supported or not.
files_to_omit = set() # type: Set[Pattern] files_to_omit = set() # type: Set[Pattern]
# what should the parser do if it encounters an unknown file in # what should the parser do if it encounters an unknown file in
# the archive? # the archive?

View File

@ -21,7 +21,7 @@ def _parse_xml(full_path: str):
for _, (key, value) in ET.iterparse(full_path, ("start-ns", )): for _, (key, value) in ET.iterparse(full_path, ("start-ns", )):
# The ns[0-9]+ namespaces are reserved for interal usage, so # The ns[0-9]+ namespaces are reserved for interal usage, so
# we have to use an other nomenclature. # we have to use an other nomenclature.
if re.match('^ns[0-9]+$', key, re.I): #pragma: no cover if re.match('^ns[0-9]+$', key, re.I): # pragma: no cover
key = 'mat' + key[2:] key = 'mat' + key[2:]
namespace_map[key] = value namespace_map[key] = value

View File

@ -17,7 +17,7 @@ from gi.repository import Poppler, GLib
from . import abstract from . import abstract
poppler_version = Poppler.get_version() poppler_version = Poppler.get_version()
if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover if LooseVersion(poppler_version) < LooseVersion('0.46'): # pragma: no cover
raise ValueError("MAT2 needs at least Poppler version 0.46 to work. \ raise ValueError("MAT2 needs at least Poppler version 0.46 to work. \
The installed version is %s." % poppler_version) # pragma: no cover The installed version is %s." % poppler_version) # pragma: no cover

View File

@ -77,7 +77,6 @@ class TestCleanFolder(unittest.TestCase):
shutil.rmtree('./tests/data/folder/') shutil.rmtree('./tests/data/folder/')
class TestCleanMeta(unittest.TestCase): class TestCleanMeta(unittest.TestCase):
def test_jpg(self): def test_jpg(self):
shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg') shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg')

View File

@ -53,16 +53,21 @@ class TestUnsupportedFiles(unittest.TestCase):
class TestCorruptedEmbedded(unittest.TestCase): class TestCorruptedEmbedded(unittest.TestCase):
def test_docx(self): def test_docx(self):
shutil.copy('./tests/data/embedded_corrupted.docx', './tests/data/clean.docx') shutil.copy('./tests/data/embedded_corrupted.docx', './tests/data/clean.docx')
parser, mimetype = parser_factory.get_parser('./tests/data/clean.docx') parser, _ = parser_factory.get_parser('./tests/data/clean.docx')
self.assertFalse(parser.remove_all()) self.assertFalse(parser.remove_all())
self.assertIsNotNone(parser.get_meta()) self.assertIsNotNone(parser.get_meta())
os.remove('./tests/data/clean.docx') os.remove('./tests/data/clean.docx')
def test_odt(self): def test_odt(self):
expected = {
'create_system': 'Weird',
'date_time': '2018-06-10 17:18:18',
'meta.xml': 'harmful content'
}
shutil.copy('./tests/data/embedded_corrupted.odt', './tests/data/clean.odt') shutil.copy('./tests/data/embedded_corrupted.odt', './tests/data/clean.odt')
parser, mimetype = parser_factory.get_parser('./tests/data/clean.odt') parser, _ = parser_factory.get_parser('./tests/data/clean.odt')
self.assertFalse(parser.remove_all()) self.assertFalse(parser.remove_all())
self.assertEqual(parser.get_meta(), {'create_system': 'Weird', 'date_time': '2018-06-10 17:18:18', 'meta.xml': 'harmful content'}) self.assertEqual(parser.get_meta(), expected)
os.remove('./tests/data/clean.odt') os.remove('./tests/data/clean.odt')
@ -90,7 +95,7 @@ class TestCorruptedFiles(unittest.TestCase):
def test_png2(self): def test_png2(self):
shutil.copy('./tests/test_libmat2.py', './tests/clean.png') shutil.copy('./tests/test_libmat2.py', './tests/clean.png')
parser, mimetype = parser_factory.get_parser('./tests/clean.png') parser, _ = parser_factory.get_parser('./tests/clean.png')
self.assertIsNone(parser) self.assertIsNone(parser)
os.remove('./tests/clean.png') os.remove('./tests/clean.png')
@ -134,7 +139,8 @@ class TestCorruptedFiles(unittest.TestCase):
def test_bmp(self): def test_bmp(self):
shutil.copy('./tests/data/dirty.png', './tests/data/clean.bmp') shutil.copy('./tests/data/dirty.png', './tests/data/clean.bmp')
harmless.HarmlessParser('./tests/data/clean.bmp') ret = harmless.HarmlessParser('./tests/data/clean.bmp')
self.assertIsNotNone(ret)
os.remove('./tests/data/clean.bmp') os.remove('./tests/data/clean.bmp')
def test_docx(self): def test_docx(self):

View File

@ -23,7 +23,6 @@ class TestZipMetadata(unittest.TestCase):
self.assertEqual(inside_p.get_meta(), {}) self.assertEqual(inside_p.get_meta(), {})
shutil.rmtree(tempdir) shutil.rmtree(tempdir)
def __check_zip_meta(self, p): def __check_zip_meta(self, p):
zipin = zipfile.ZipFile(p.filename) zipin = zipfile.ZipFile(p.filename)
for item in zipin.infolist(): for item in zipin.infolist():
@ -135,4 +134,3 @@ class TestRsidRemoval(unittest.TestCase):
os.remove('./tests/data/clean.docx') os.remove('./tests/data/clean.docx')
os.remove('./tests/data/clean.cleaned.docx') os.remove('./tests/data/clean.cleaned.docx')

View File

@ -12,7 +12,7 @@ from libmat2 import check_dependencies
class TestCheckDependencies(unittest.TestCase): class TestCheckDependencies(unittest.TestCase):
def test_deps(self): def test_deps(self):
ret = check_dependencies() ret = check_dependencies()
for key, value in ret.items(): for value in ret.values():
self.assertTrue(value) self.assertTrue(value)

View File

@ -29,4 +29,3 @@ class TestPolicy(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
p.unknown_member_policy = UnknownMemberPolicy('unknown_policy_name_totally_invalid') p.unknown_member_policy = UnknownMemberPolicy('unknown_policy_name_totally_invalid')
os.remove('./tests/data/clean.docx') os.remove('./tests/data/clean.docx')