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):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--help'], stdout=subprocess.PIPE)
|
2018-04-04 00:22:00 +02:00
|
|
|
stdout, _ = proc.communicate()
|
2018-09-05 17:48:14 +02:00
|
|
|
self.assertIn(b'usage: mat2 [-h] [-v] [-l] [--check-dependencies] [-V]',
|
2018-09-01 03:33:42 +02:00
|
|
|
stdout)
|
2018-09-05 17:48:14 +02:00
|
|
|
self.assertIn(b'[--unknown-members policy] [-s | -L]', stdout)
|
2018-04-04 00:37:55 +02:00
|
|
|
|
2018-04-04 23:14:43 +02:00
|
|
|
def test_no_arg(self):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2'], stdout=subprocess.PIPE)
|
2018-04-04 23:14:43 +02:00
|
|
|
stdout, _ = proc.communicate()
|
2018-09-05 17:48:14 +02:00
|
|
|
self.assertIn(b'usage: mat2 [-h] [-v] [-l] [--check-dependencies] [-V]',
|
2018-09-01 03:33:42 +02:00
|
|
|
stdout)
|
2018-09-05 17:48:14 +02:00
|
|
|
self.assertIn(b'[--unknown-members policy] [-s | -L]', stdout)
|
2018-05-14 22:44:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestVersion(unittest.TestCase):
|
|
|
|
def test_version(self):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--version'], stdout=subprocess.PIPE)
|
2018-05-14 22:44:31 +02:00
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertTrue(stdout.startswith(b'MAT2 '))
|
|
|
|
|
2018-07-10 20:49:54 +02:00
|
|
|
class TestDependencies(unittest.TestCase):
|
|
|
|
def test_dependencies(self):
|
|
|
|
proc = subprocess.Popen(['./mat2', '--check-dependencies'], stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertTrue(b'MAT2' in stdout)
|
2018-04-04 23:14:43 +02:00
|
|
|
|
2018-04-29 22:55:26 +02:00
|
|
|
class TestReturnValue(unittest.TestCase):
|
|
|
|
def test_nonzero(self):
|
2018-05-21 22:49:40 +02:00
|
|
|
ret = subprocess.call(['./mat2', './mat2'], stdout=subprocess.DEVNULL)
|
2018-04-29 22:55:26 +02:00
|
|
|
self.assertEqual(255, ret)
|
|
|
|
|
2018-05-21 22:49:40 +02:00
|
|
|
ret = subprocess.call(['./mat2', '--whololo'], stderr=subprocess.DEVNULL)
|
2018-04-29 22:55:26 +02:00
|
|
|
self.assertEqual(2, ret)
|
|
|
|
|
|
|
|
def test_zero(self):
|
2018-05-21 22:49:40 +02:00
|
|
|
ret = subprocess.call(['./mat2'], stdout=subprocess.DEVNULL)
|
2018-04-29 22:55:26 +02:00
|
|
|
self.assertEqual(0, ret)
|
|
|
|
|
2018-05-21 22:49:40 +02:00
|
|
|
ret = subprocess.call(['./mat2', '--show', './mat2'], stdout=subprocess.DEVNULL)
|
2018-04-29 22:55:26 +02:00
|
|
|
self.assertEqual(0, ret)
|
|
|
|
|
|
|
|
|
2018-07-30 22:54:41 +02:00
|
|
|
class TestCleanFolder(unittest.TestCase):
|
|
|
|
def test_jpg(self):
|
2018-09-06 11:32:29 +02:00
|
|
|
try:
|
|
|
|
os.mkdir('./tests/data/folder/')
|
|
|
|
except FileExistsError:
|
|
|
|
pass
|
2018-07-30 22:54:41 +02:00
|
|
|
shutil.copy('./tests/data/dirty.jpg', './tests/data/folder/clean1.jpg')
|
|
|
|
shutil.copy('./tests/data/dirty.jpg', './tests/data/folder/clean2.jpg')
|
|
|
|
|
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/folder/'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'Comment: Created with GIMP', stdout)
|
|
|
|
|
|
|
|
proc = subprocess.Popen(['./mat2', './tests/data/folder/'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
|
|
|
|
os.remove('./tests/data/folder/clean1.jpg')
|
|
|
|
os.remove('./tests/data/folder/clean2.jpg')
|
|
|
|
|
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/folder/'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertNotIn(b'Comment: Created with GIMP', stdout)
|
|
|
|
|
|
|
|
shutil.rmtree('./tests/data/folder/')
|
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/clean.jpg'],
|
2018-04-16 23:20:21 +02:00
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'Comment: Created with GIMP', stdout)
|
|
|
|
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', './tests/data/clean.jpg'],
|
2018-04-16 23:20:21 +02:00
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/clean.cleaned.jpg'],
|
2018-04-16 23:20:21 +02:00
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertNotIn(b'Comment: Created with GIMP', stdout)
|
|
|
|
|
|
|
|
os.remove('./tests/data/clean.jpg')
|
|
|
|
|
|
|
|
|
2018-06-04 22:54:01 +02:00
|
|
|
class TestIsSupported(unittest.TestCase):
|
|
|
|
def test_pdf(self):
|
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.pdf'],
|
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertNotIn(b"isn't supported", stdout)
|
|
|
|
|
2018-04-04 00:37:55 +02:00
|
|
|
class TestGetMeta(unittest.TestCase):
|
|
|
|
def test_pdf(self):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.pdf'],
|
2018-04-04 00:37:55 +02:00
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'producer: pdfTeX-1.40.14', stdout)
|
|
|
|
|
|
|
|
def test_png(self):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.png'],
|
2018-04-04 00:37:55 +02:00
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'Comment: This is a comment, be careful!', stdout)
|
|
|
|
|
|
|
|
def test_jpg(self):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.jpg'],
|
2018-04-04 00:37:55 +02:00
|
|
|
stdout=subprocess.PIPE)
|
|
|
|
stdout, _ = proc.communicate()
|
|
|
|
self.assertIn(b'Comment: Created with GIMP', stdout)
|
|
|
|
|
|
|
|
def test_docx(self):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.docx'],
|
2018-04-04 00:37:55 +02:00
|
|
|
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):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.odt'],
|
2018-04-04 00:37:55 +02:00
|
|
|
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):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.mp3'],
|
2018-04-04 21:59:46 +02:00
|
|
|
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):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.flac'],
|
2018-04-04 21:59:46 +02:00
|
|
|
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):
|
2018-05-21 22:49:40 +02:00
|
|
|
proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.ogg'],
|
2018-04-04 21:59:46 +02:00
|
|
|
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)
|