From de5917e5f01374bb1a647f49ae85283241a2bea9 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 18 Jun 2011 04:42:52 +0200 Subject: Creation of the arborescence --- test/__init__.py | 0 test/clean.jpg | Bin 0 -> 83261 bytes test/clitest.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/dirty.jpg | Bin 0 -> 83261 bytes test/libtest.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ test/test.py | 31 +++++++++++++++++++++++ 6 files changed, 168 insertions(+) create mode 100644 test/__init__.py create mode 100644 test/clean.jpg create mode 100755 test/clitest.py create mode 100644 test/dirty.jpg create mode 100755 test/libtest.py create mode 100755 test/test.py (limited to 'test') diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/clean.jpg b/test/clean.jpg new file mode 100644 index 0000000..09c9161 Binary files /dev/null and b/test/clean.jpg differ diff --git a/test/clitest.py b/test/clitest.py new file mode 100755 index 0000000..da0563f --- /dev/null +++ b/test/clitest.py @@ -0,0 +1,73 @@ +#!/usr/bin/python +''' + Unit test for the CLI interface +''' + +import unittest +import subprocess +import sys +sys.path.append('..') +import cli +from lib import mat +import test + +class Test_Remove_cli(test.MATTest): + def test_remove(self): + '''make sure that the cli remove all compromizing meta''' + for clean, dirty in self.file_list: + subprocess.call(['../cli.py', dirty]) + current_file = mat.create_class_file(dirty) + self.assertTrue(current_file.is_clean()) + + def test_remove_empty(self): + '''Test removal with clean files''' + for clean, dirty in self.file_list: + subprocess.call(['../cli.py', clean]) + current_file = mat.create_class_file(clean) + self.assertTrue(current_file.is_clean()) + + +class Test_List_cli(test.MATTest): + def test_list_clean(self): + '''check if get_meta returns meta''' + for clean, dirty in self.file_list: + #fixme : a (clean|dirty).(jpg|pdf|...).out ? + proc = subprocess.Popen(['../cli.py', '-d', clean], + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate() + self.assertEqual(stdout, "[+] File %s" % clean) + + def test_list_dirty(self): + '''check if get_meta returns all the expected meta''' + for clean, dirty in self.file_list: + proc = subprocess.Popen(['../cli.py', '-d', dirty], + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate() + self.assertNotEqual(stdout, "[+] File %s" % dirty) + + +class Test_isClean_cli(test.MATTest): + #FIXME : use an external file with string as const ? + def test_clean(self): + '''test is_clean on clean files''' + for clean, dirty in self.file_list: + proc = subprocess.Popen(['../cli.py', '-c', clean], + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate() + self.assertEqual(stdout.strip('\n'), '[+] %s is clean' % clean) + + def test_dirty(self): + '''test is_clean on dirty files''' + for clean, dirty in self.file_list: + proc = subprocess.Popen(['../cli.py', '-c', dirty], + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate() + self.assertEqual(stdout.strip('\n'), '[+] %s is not clean' % dirty) + + +if __name__ == '__main__': + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(Test_Remove_cli)) + suite.addTest(unittest.makeSuite(Test_List_cli)) + suite.addTest(unittest.makeSuite(Test_isClean_cli)) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/dirty.jpg b/test/dirty.jpg new file mode 100644 index 0000000..09c9161 Binary files /dev/null and b/test/dirty.jpg differ diff --git a/test/libtest.py b/test/libtest.py new file mode 100755 index 0000000..2bd1fa7 --- /dev/null +++ b/test/libtest.py @@ -0,0 +1,64 @@ +#!/usr/bin/python + +''' + Unit test for the library +''' + +import unittest +import test +import sys +sys.path.append('..') +from lib import mat + +class Test_Remove_lib(test.MATTest): + def test_remove(self): + '''make sure that the lib remove all compromizing meta''' + for clean, dirty in self.file_list: + current_file = mat.create_class_file(dirty) + current_file.remove_all() + self.assertTrue(current_file.is_clean()) + + def test_remove_empty(self): + '''Test removal with clean files''' + for clean, dirty in self.file_list: + current_file = mat.create_class_file(clean) + current_file.remove_all() + self.assertTrue(current_file.is_clean()) + + +class Test_List_lib(test.MATTest): + def test_list(self): + '''check if get_meta returns all the expected meta''' + for clean, dirty in self.file_list: + current_file = mat.create_class_file(dirty) + meta_list = dict({"fixme":"please"},) + self.assertEqual(current_file.get_meta(), meta_list) + + def testlist_list_empty(self): + '''check that a listing of a clean file return an empty dict''' + for clean, dirty in self.file_list: + current_file = mat.create_class_file(clean) + self.assertEqual(current_file.get_meta(), dict()) #dirty, isn't it ? + + +class Test_isClean_lib(test.MATTest): + def test_dirty(self): + '''test is_clean on clean files''' + for clean, dirty in self.file_list: + current_file = mat.create_class_file(dirty) + self.assertTrue(current_file.is_clean()) + + def test_clean(self): + '''test is_clean on dirty files''' + for clean, dirty in self.file_list: + current_file = mat.create_class_file(clean) + self.assertFalse(current_file.is_clean()) + + +if __name__ == '__main__': + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(Test_Remove_lib)) + suite.addTest(unittest.makeSuite(Test_List_lib)) + suite.addTest(unittest.makeSuite(Test_isClean_lib)) + unittest.TextTestRunner(verbosity=2).run(suite) + diff --git a/test/test.py b/test/test.py new file mode 100755 index 0000000..f095157 --- /dev/null +++ b/test/test.py @@ -0,0 +1,31 @@ +''' + Class for the testing suite : + - get the list of all test files + - create a copy of them on start + - remove the copy on end +''' + +import shutil +import glob +import sys +import tempfile +import unittest +sys.path.append('..') +from lib import mat + +FILE_LIST = zip(glob.glob('clean*'), glob.glob('dirty*')) + +class MATTest(unittest.TestCase): + def setUp(self): + '''create working copy of the clean and the dirty file in the TMP dir''' + self.file_list = [] + self.tmpdir = tempfile.mkdtemp() + + for clean, dirty in FILE_LIST: + shutil.copy2(clean, self.tmpdir + clean) + shutil.copy2(dirty, self.tmpdir + dirty) + self.file_list.append((self.tmpdir + clean, self.tmpdir + dirty)) + + def tearDown(self): + '''Remove the tmp folder''' + shutil.rmtree(self.tmpdir) -- cgit v1.3