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