summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/dirty.txt1
-rw-r--r--tests/test_corrupted_files.py8
-rw-r--r--tests/test_libmat2.py24
3 files changed, 28 insertions, 5 deletions
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')