1"""Tests for distutils.util.""" 2import sys 3import unittest 4from test.test_support import run_unittest 5 6from distutils.errors import DistutilsByteCompileError 7from distutils.tests import support 8from distutils.util import byte_compile, grok_environment_error 9 10 11class UtilTestCase(support.EnvironGuard, unittest.TestCase): 12 13 def test_dont_write_bytecode(self): 14 # makes sure byte_compile raise a DistutilsError 15 # if sys.dont_write_bytecode is True 16 old_dont_write_bytecode = sys.dont_write_bytecode 17 sys.dont_write_bytecode = True 18 try: 19 self.assertRaises(DistutilsByteCompileError, byte_compile, []) 20 finally: 21 sys.dont_write_bytecode = old_dont_write_bytecode 22 23 def test_grok_environment_error(self): 24 # test obsolete function to ensure backward compat (#4931) 25 exc = IOError("Unable to find batch file") 26 msg = grok_environment_error(exc) 27 self.assertEqual(msg, "error: Unable to find batch file") 28 29 30def test_suite(): 31 return unittest.makeSuite(UtilTestCase) 32 33if __name__ == "__main__": 34 run_unittest(test_suite()) 35