2018-04-16 23:20:21 +02:00
|
|
|
import os
|
|
|
|
import shutil
|
2018-04-04 00:22:00 +02:00
|
|
|
import subprocess
|
2018-04-16 23:20:21 +02:00
|
|
|
import unittest
|
2018-04-04 00:22:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestHelp(unittest.TestCase):
|
|
|
|
def test_help(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--help'], stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
2018-04-14 21:23:31 +02:00
|
|
|
self.assertIn(b'usage: main.py [-h] [-c] [-l] [-s] [-L] [files [files ...]]', stdout)
|
2018-04-04 00:37:55 +02:00
|
|
|
|
2018-04-04 23:14:43 +02:00
|
|
|
def test_no_arg(self):
|
|
|
|
proc = subprocess.Popen(['./main.py'], stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
2018-04-14 21:23:31 +02:00
|
|
|
self.assertIn(b'usage: main.py [-h] [-c] [-l] [-s] [-L] [files [files ...]]', stdout)
|
2018-04-04 23:14:43 +02:00
|
|
|
|
2018-04-04 23:21:48 +02:00
|
|
|
|
2018-04-16 23:20:21 +02:00
|
|
|
class TestCleanMeta(unittest.TestCase):
|
|
|
|
def test_jpg(self):
|
|
|
|
shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg')
|
|
|
|
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/clean.jpg'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'Comment: Created with GIMP', stdout)
|
|
|
|
|
|
|
|
proc = subprocess.Popen(['./main.py', './tests/data/clean.jpg'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/clean.jpg.cleaned'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertNotIn(b'Comment: Created with GIMP', stdout)
|
|
|
|
|
|
|
|
os.remove('./tests/data/clean.jpg')
|
|
|
|
|
|
|
|
|
2018-04-04 00:37:55 +02:00
|
|
|
class TestGetMeta(unittest.TestCase):
|
|
|
|
def test_pdf(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/dirty.pdf'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'producer: pdfTeX-1.40.14', stdout)
|
|
|
|
|
|
|
|
def test_png(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/dirty.png'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'Comment: This is a comment, be careful!', stdout)
|
|
|
|
|
|
|
|
def test_jpg(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/dirty.jpg'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'Comment: Created with GIMP', stdout)
|
|
|
|
|
|
|
|
def test_docx(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/dirty.docx'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'Application: LibreOffice/5.4.5.1$Linux_X86_64', stdout)
|
|
|
|
self.assertIn(b'creator: julien voisin', stdout)
|
|
|
|
self.assertIn(b'revision: 1', stdout)
|
|
|
|
|
|
|
|
def test_odt(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/dirty.odt'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'generator: LibreOffice/3.3$Unix', stdout)
|
|
|
|
self.assertIn(b'creator: jvoisin', stdout)
|
|
|
|
self.assertIn(b'date_time: 2011-07-26 02:40:16', stdout)
|
2018-04-04 21:59:46 +02:00
|
|
|
|
|
|
|
def test_mp3(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/dirty.mp3'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'TALB: harmfull', stdout)
|
|
|
|
self.assertIn(b'COMM::: Thank you for using MAT !', stdout)
|
|
|
|
|
|
|
|
def test_flac(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/dirty.flac'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'comments: Thank you for using MAT !', stdout)
|
|
|
|
self.assertIn(b'genre: Python', stdout)
|
|
|
|
self.assertIn(b'title: I am so', stdout)
|
|
|
|
|
|
|
|
def test_ogg(self):
|
|
|
|
proc = subprocess.Popen(['./main.py', '--show', './tests/data/dirty.ogg'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'comments: Thank you for using MAT !', stdout)
|
|
|
|
self.assertIn(b'genre: Python', stdout)
|
|
|
|
self.assertIn(b'i am a : various comment', stdout)
|
|
|
|
self.assertIn(b'artist: jvoisin', stdout)
|