unittest: adjust package list format with the change of backend.
[platform/upstream/mic.git] / tests / mic-test.py
1 #!/usr/bin/python
2 import unittest
3 import os, sys, glob, tempfile, shutil
4 from testbase import *
5
6 class MICTest(unittest.TestCase):
7     cases_dir = "mic_cases"
8     if os.path.isdir(cases_dir):
9         for case in glob.glob(os.path.join(cases_dir,'test-*')):
10             case = os.path.basename(case)[5:]
11             method = """
12 def test_%s(self):
13     self._testTemplate("%s")
14 """ % (case, case)
15             exec method in locals()
16    
17     def setUp(self):
18         self.work_env = tempfile.mkdtemp()
19     
20     def tearDown(self):
21         shutil.rmtree(self.work_env, ignore_errors = True)
22             
23     def _testTemplate(self, case):
24         """test function"""
25         PrepEnv(self.cases_dir, case, self.work_env)
26         RunandCheck(self, self.work_env)
27                                
28 def MICtestsuite():
29     suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
30     alltests = unittest.TestSuite(suite)
31     return alltests       
32
33 if __name__ == '__main__':
34     if os.getuid() != 0:
35         raise SystemExit("Root permission is needed")
36
37     suite = MICtestsuite()
38     unittest.TextTestRunner(verbosity=2).run(suite)