Skip to content
Snippets Groups Projects
Commit 53271495 authored by Julien (jvoisin) Voisin's avatar Julien (jvoisin) Voisin
Browse files

Add support for .txt files

parent 0638b9bb
Branches
Tags
No related merge requests found
...@@ -12,8 +12,6 @@ unsupported_extensions = { ...@@ -12,8 +12,6 @@ unsupported_extensions = {
'.pot', '.pot',
'.rdf', '.rdf',
'.srt', '.srt',
'.text',
'.txt',
'.wsdl', '.wsdl',
'.xpdl', '.xpdl',
'.xsd', '.xsd',
......
import shutil
from typing import Dict from typing import Dict
from . import abstract from . import abstract
...@@ -6,13 +7,9 @@ class HarmlessParser(abstract.AbstractParser): ...@@ -6,13 +7,9 @@ class HarmlessParser(abstract.AbstractParser):
""" This is the parser for filetypes that do not contain metadata. """ """ This is the parser for filetypes that do not contain metadata. """
mimetypes = {'text/plain', } mimetypes = {'text/plain', }
def __init__(self, filename: str) -> None:
super().__init__(filename)
self.filename = filename
self.output_filename = filename
def get_meta(self) -> Dict[str, str]: def get_meta(self) -> Dict[str, str]:
return dict() return dict()
def remove_all(self) -> bool: def remove_all(self) -> bool:
shutil.copy(self.filename, self.output_filename)
return True return True
I'm a file that can't have metadata, but I'm supposed to be supported anyway.
\ No newline at end of file
...@@ -18,11 +18,11 @@ class TestUnsupportedFiles(unittest.TestCase): ...@@ -18,11 +18,11 @@ class TestUnsupportedFiles(unittest.TestCase):
class TestExplicitelyUnsupportedFiles(unittest.TestCase): class TestExplicitelyUnsupportedFiles(unittest.TestCase):
def test_pdf(self): def test_pdf(self):
shutil.copy('./tests/test_libmat2.py', './tests/clean.txt') shutil.copy('./tests/test_libmat2.py', './tests/data/clean.py')
parser, mimetype = parser_factory.get_parser('./tests/data/clean.txt') parser, mimetype = parser_factory.get_parser('./tests/data/clean.py')
self.assertEqual(mimetype, 'text/plain') self.assertEqual(mimetype, 'text/x-python')
self.assertEqual(parser, None) self.assertEqual(parser, None)
os.remove('./tests/clean.txt') os.remove('./tests/data/clean.py')
class TestCorruptedFiles(unittest.TestCase): class TestCorruptedFiles(unittest.TestCase):
......
...@@ -6,7 +6,7 @@ import os ...@@ -6,7 +6,7 @@ import os
import zipfile import zipfile
import tempfile import tempfile
from libmat2 import pdf, images, audio, office, parser_factory, torrent from libmat2 import pdf, images, audio, office, parser_factory, torrent, harmless
class TestParserFactory(unittest.TestCase): class TestParserFactory(unittest.TestCase):
...@@ -104,6 +104,12 @@ class TestGetMeta(unittest.TestCase): ...@@ -104,6 +104,12 @@ class TestGetMeta(unittest.TestCase):
self.assertEqual(meta['meta:creation-date'], '2011-07-26T03:27:48') self.assertEqual(meta['meta:creation-date'], '2011-07-26T03:27:48')
self.assertEqual(meta['meta:generator'], 'LibreOffice/3.3$Unix LibreOffice_project/330m19$Build-202') self.assertEqual(meta['meta:generator'], 'LibreOffice/3.3$Unix LibreOffice_project/330m19$Build-202')
def test_txt(self):
p, mimetype = parser_factory.get_parser('./tests/data/dirty.txt')
self.assertEqual(mimetype, 'text/plain')
meta = p.get_meta()
self.assertEqual(meta, {})
class TestRemovingThumbnails(unittest.TestCase): class TestRemovingThumbnails(unittest.TestCase):
def test_odt(self): def test_odt(self):
...@@ -473,3 +479,19 @@ class TestCleaning(unittest.TestCase): ...@@ -473,3 +479,19 @@ class TestCleaning(unittest.TestCase):
os.remove('./tests/data/clean.odg') os.remove('./tests/data/clean.odg')
os.remove('./tests/data/clean.cleaned.odg') os.remove('./tests/data/clean.cleaned.odg')
def test_txt(self):
shutil.copy('./tests/data/dirty.txt', './tests/data/clean.txt')
p = harmless.HarmlessParser('./tests/data/clean.txt')
meta = p.get_meta()
self.assertEqual(meta, {})
ret = p.remove_all()
self.assertTrue(ret)
p = harmless.HarmlessParser('./tests/data/clean.cleaned.txt')
self.assertEqual(p.get_meta(), {})
os.remove('./tests/data/clean.txt')
os.remove('./tests/data/clean.cleaned.txt')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment