test_specify.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/python -tt
  2. # vim: ai ts=4 sts=4 et sw=4
  3. # Copyright (c) 2009 Intel Corporation
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by the Free
  7. # Software Foundation; version 2 of the License
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. # for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License along
  15. # with this program; if not, write to the Free Software Foundation, Inc., 59
  16. # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. import os,sys
  18. import glob
  19. import tempfile
  20. import subprocess
  21. import unittest
  22. from testbase import *
  23. class TestSpecifyKeys(unittest.TestCase):
  24. cases_dir = 'specify_cases'
  25. # build cases on the fly based on directories
  26. if os.path.isdir(cases_dir):
  27. for case in glob.glob(os.path.join(cases_dir, 'test-*')):
  28. if not os.path.exists(os.path.join(case, 'input.p')):
  29. continue
  30. case = os.path.basename(case)[5:]
  31. newmethod = """
  32. def test_%s(self):
  33. print "case %s ok"
  34. self.assertTrue(self._compare_out_file("%s"))
  35. """ % (case, case, case)
  36. exec newmethod in locals()
  37. def _compare_out_file(self, case):
  38. prep_working_env(self.cases_dir, case, self.work_dir)
  39. if run_and_check(self.work_dir):
  40. return (compare_outfile(self.work_dir))
  41. else:
  42. return False
  43. def setUp(self):
  44. self.work_dir = tempfile.mkdtemp()
  45. def tearDown(self):
  46. cleanup(self.work_dir)
  47. def suite():
  48. tl = unittest.TestLoader()
  49. return tl.loadTestsFromModule(sys.modules[__name__])