/Lib/test/test_coding.py

http://unladen-swallow.googlecode.com/ · Python · 28 lines · 21 code · 7 blank · 0 comment · 1 complexity · 958db4201a7ca3eccb9802a09169e2e8 MD5 · raw file

  1. import test.test_support, unittest
  2. import os
  3. class CodingTest(unittest.TestCase):
  4. def test_bad_coding(self):
  5. module_name = 'bad_coding'
  6. self.verify_bad_module(module_name)
  7. def test_bad_coding2(self):
  8. module_name = 'bad_coding2'
  9. self.verify_bad_module(module_name)
  10. def verify_bad_module(self, module_name):
  11. self.assertRaises(SyntaxError, __import__, 'test.' + module_name)
  12. path = os.path.dirname(__file__)
  13. filename = os.path.join(path, module_name + '.py')
  14. fp = open(filename)
  15. text = fp.read()
  16. fp.close()
  17. self.assertRaises(SyntaxError, compile, text, filename, 'exec')
  18. def test_main():
  19. test.test_support.run_unittest(CodingTest)
  20. if __name__ == "__main__":
  21. test_main()