summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmat2/__init__.py2
-rw-r--r--libmat2/harmless.py7
-rw-r--r--tests/data/dirty.txt1
-rw-r--r--tests/test_corrupted_files.py8
-rw-r--r--tests/test_libmat2.py24
5 files changed, 30 insertions, 12 deletions
diff --git a/libmat2/__init__.py b/libmat2/__init__.py
index 91a51d8..190abe5 100644
--- a/libmat2/__init__.py
+++ b/libmat2/__init__.py
@@ -12,8 +12,6 @@ unsupported_extensions = {
12 '.pot', 12 '.pot',
13 '.rdf', 13 '.rdf',
14 '.srt', 14 '.srt',
15 '.text',
16 '.txt',
17 '.wsdl', 15 '.wsdl',
18 '.xpdl', 16 '.xpdl',
19 '.xsd', 17 '.xsd',
diff --git a/libmat2/harmless.py b/libmat2/harmless.py
index 2878571..9032caf 100644
--- a/libmat2/harmless.py
+++ b/libmat2/harmless.py
@@ -1,3 +1,4 @@
1import shutil
1from typing import Dict 2from typing import Dict
2from . import abstract 3from . import abstract
3 4
@@ -6,13 +7,9 @@ class HarmlessParser(abstract.AbstractParser):
6 """ This is the parser for filetypes that do not contain metadata. """ 7 """ This is the parser for filetypes that do not contain metadata. """
7 mimetypes = {'text/plain', } 8 mimetypes = {'text/plain', }
8 9
9 def __init__(self, filename: str) -> None:
10 super().__init__(filename)
11 self.filename = filename
12 self.output_filename = filename
13
14 def get_meta(self) -> Dict[str, str]: 10 def get_meta(self) -> Dict[str, str]:
15 return dict() 11 return dict()
16 12
17 def remove_all(self) -> bool: 13 def remove_all(self) -> bool:
14 shutil.copy(self.filename, self.output_filename)
18 return True 15 return True
diff --git a/tests/data/dirty.txt b/tests/data/dirty.txt
new file mode 100644
index 0000000..952975e
--- /dev/null
+++ b/tests/data/dirty.txt
@@ -0,0 +1 @@
I'm a file that can't have metadata, but I'm supposed to be supported anyway. \ No newline at end of file
diff --git a/tests/test_corrupted_files.py b/tests/test_corrupted_files.py
index b784b0e..4b2243d 100644
--- a/tests/test_corrupted_files.py
+++ b/tests/test_corrupted_files.py
@@ -18,11 +18,11 @@ class TestUnsupportedFiles(unittest.TestCase):
18 18
19class TestExplicitelyUnsupportedFiles(unittest.TestCase): 19class TestExplicitelyUnsupportedFiles(unittest.TestCase):
20 def test_pdf(self): 20 def test_pdf(self):
21 shutil.copy('./tests/test_libmat2.py', './tests/clean.txt') 21 shutil.copy('./tests/test_libmat2.py', './tests/data/clean.py')
22 parser, mimetype = parser_factory.get_parser('./tests/data/clean.txt') 22 parser, mimetype = parser_factory.get_parser('./tests/data/clean.py')
23 self.assertEqual(mimetype, 'text/plain') 23 self.assertEqual(mimetype, 'text/x-python')
24 self.assertEqual(parser, None) 24 self.assertEqual(parser, None)
25 os.remove('./tests/clean.txt') 25 os.remove('./tests/data/clean.py')
26 26
27 27
28class TestCorruptedFiles(unittest.TestCase): 28class TestCorruptedFiles(unittest.TestCase):
diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py
index 4df6385..90f37a8 100644
--- a/tests/test_libmat2.py
+++ b/tests/test_libmat2.py
@@ -6,7 +6,7 @@ import os
6import zipfile 6import zipfile
7import tempfile 7import tempfile
8 8
9from libmat2 import pdf, images, audio, office, parser_factory, torrent 9from libmat2 import pdf, images, audio, office, parser_factory, torrent, harmless
10 10
11 11
12class TestParserFactory(unittest.TestCase): 12class TestParserFactory(unittest.TestCase):
@@ -104,6 +104,12 @@ class TestGetMeta(unittest.TestCase):
104 self.assertEqual(meta['meta:creation-date'], '2011-07-26T03:27:48') 104 self.assertEqual(meta['meta:creation-date'], '2011-07-26T03:27:48')
105 self.assertEqual(meta['meta:generator'], 'LibreOffice/3.3$Unix LibreOffice_project/330m19$Build-202') 105 self.assertEqual(meta['meta:generator'], 'LibreOffice/3.3$Unix LibreOffice_project/330m19$Build-202')
106 106
107 def test_txt(self):
108 p, mimetype = parser_factory.get_parser('./tests/data/dirty.txt')
109 self.assertEqual(mimetype, 'text/plain')
110 meta = p.get_meta()
111 self.assertEqual(meta, {})
112
107 113
108class TestRemovingThumbnails(unittest.TestCase): 114class TestRemovingThumbnails(unittest.TestCase):
109 def test_odt(self): 115 def test_odt(self):
@@ -473,3 +479,19 @@ class TestCleaning(unittest.TestCase):
473 479
474 os.remove('./tests/data/clean.odg') 480 os.remove('./tests/data/clean.odg')
475 os.remove('./tests/data/clean.cleaned.odg') 481 os.remove('./tests/data/clean.cleaned.odg')
482
483 def test_txt(self):
484 shutil.copy('./tests/data/dirty.txt', './tests/data/clean.txt')
485 p = harmless.HarmlessParser('./tests/data/clean.txt')
486
487 meta = p.get_meta()
488 self.assertEqual(meta, {})
489
490 ret = p.remove_all()
491 self.assertTrue(ret)
492
493 p = harmless.HarmlessParser('./tests/data/clean.cleaned.txt')
494 self.assertEqual(p.get_meta(), {})
495
496 os.remove('./tests/data/clean.txt')
497 os.remove('./tests/data/clean.cleaned.txt')