diff options
| author | jvoisin | 2011-06-07 18:40:44 +0200 |
|---|---|---|
| committer | jvoisin | 2011-06-07 18:40:44 +0200 |
| commit | f7082a21d6511c5069fbb9ff186ce22f3e22fed7 (patch) | |
| tree | 93322a3220e50c1a32583ba197afec870298767c /lib/test.py | |
First commit
Diffstat (limited to '')
| -rw-r--r-- | lib/test.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/test.py b/lib/test.py new file mode 100644 index 0000000..b1ff2a3 --- /dev/null +++ b/lib/test.py | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | import mat | ||
| 2 | import unittest | ||
| 3 | import shutil | ||
| 4 | import glob | ||
| 5 | import tempfile | ||
| 6 | |||
| 7 | FILE_LIST = zip(glob.glob('clean*'), glob.glob('dirty*')) | ||
| 8 | |||
| 9 | class MATTest(unittest.TestCase): | ||
| 10 | def setUp(self): | ||
| 11 | '''create working copy of the clean and the dirty file in the TMP dir''' | ||
| 12 | self.file_list = [] | ||
| 13 | self.tmpdir = tempfile.mkdtemp() | ||
| 14 | |||
| 15 | for clean, dirty in FILE_LIST: | ||
| 16 | shutil.copy2(clean, self.tmpdir + clean) | ||
| 17 | shutil.copy2(dirty, self.tmpdir + dirty) | ||
| 18 | self.file_list.append((self.tmpdir + clean, self.tmpdir + dirty)) | ||
| 19 | |||
| 20 | def tearDown(self): | ||
| 21 | '''Remove the tmp folder''' | ||
| 22 | shutil.rmtree(self.tmpdir) | ||
| 23 | |||
| 24 | class Test_Remove(MATTest): | ||
| 25 | def test_remove(self): | ||
| 26 | '''make sure that the lib remove all compromizing meta''' | ||
| 27 | for clean, dirty in self.file_list: | ||
| 28 | mat.file(dirty).remove_all() | ||
| 29 | self.assertTrue(mat.file(dirty).is_clean()) | ||
| 30 | |||
| 31 | def test_remove_empty(self): | ||
| 32 | '''Test removal with clean files''' | ||
| 33 | for clean, dirty in self.file_list: | ||
| 34 | mat.file(clean).remove_all() | ||
| 35 | self.assertTrue(mat.file(clean).is_clean()) | ||
| 36 | |||
| 37 | |||
| 38 | class Test_List(MATTest): | ||
| 39 | def test_list(self): | ||
| 40 | '''check if get_meta returns all the expected meta''' | ||
| 41 | for clean, dirty in self.file_list: | ||
| 42 | meta_list = dict() #FIXME | ||
| 43 | self.assertDictEqual(mat.file(dirty).get_meta(), meta_list) | ||
| 44 | |||
| 45 | def testlist_list_empty(self): | ||
| 46 | '''check that a listing of a clean file return an empty dict''' | ||
| 47 | for clean, dirty in self.file_list: | ||
| 48 | self.assertEqual(mat.file(clean).get_meta(), None) | ||
| 49 | |||
| 50 | |||
| 51 | class Test_isClean(MATTest): | ||
| 52 | def test_clean(self): | ||
| 53 | '''test is_clean on clean files''' | ||
| 54 | for clean, dirty in self.file_list: | ||
| 55 | print "e" | ||
| 56 | self.assertTrue(mat.file(clean).is_clean()) | ||
| 57 | |||
| 58 | def test_clean(self): | ||
| 59 | '''test is_clean on dirty files''' | ||
| 60 | for clean, dirty in self.file_list: | ||
| 61 | self.assertFalse(mat.file(dirty).is_clean()) | ||
| 62 | |||
| 63 | |||
| 64 | if __name__ == '__main__': | ||
| 65 | suite = unittest.TestSuite() | ||
| 66 | suite.addTest(unittest.makeSuite(Test_Remove)) | ||
| 67 | suite.addTest(unittest.makeSuite(Test_List)) | ||
| 68 | suite.addTest(unittest.makeSuite(Test_isClean)) | ||
| 69 | unittest.TextTestRunner(verbosity=2).run(suite) | ||
| 70 | |||
