blob: 7898e07b2517145f1c5c21fdd8d258ef277c8859 [file] [log] [blame]
Tarek Ziadé275958a2009-02-13 22:22:03 +00001"""Tests for distutils.util."""
Tarek Ziadé275958a2009-02-13 22:22:03 +00002import sys
3import unittest
Éric Araujo54274ad2011-02-03 00:12:18 +00004from test.test_support import run_unittest
Tarek Ziadé275958a2009-02-13 22:22:03 +00005
Éric Araujo3d1134e2014-03-12 03:14:48 -04006from distutils.errors import DistutilsByteCompileError
Victor Stinner15f8d0d2017-05-03 17:28:10 +02007from distutils.tests import support
Éric Araujo3d1134e2014-03-12 03:14:48 -04008from distutils.util import byte_compile, grok_environment_error
9
Tarek Ziadéa99dedf2009-07-16 15:35:45 +000010
Victor Stinner15f8d0d2017-05-03 17:28:10 +020011class UtilTestCase(support.EnvironGuard, unittest.TestCase):
Tarek Ziadéa99dedf2009-07-16 15:35:45 +000012
Tarek Ziadéb9c1cfc2009-10-24 15:10:37 +000013 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:
Tarek Ziadé468f7002009-10-24 15:19:03 +000021 sys.dont_write_bytecode = old_dont_write_bytecode
Tarek Ziadéb9c1cfc2009-10-24 15:10:37 +000022
Éric Araujo3d1134e2014-03-12 03:14:48 -040023 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
Tarek Ziadé275958a2009-02-13 22:22:03 +000030def test_suite():
Tarek Ziadé450ca112009-05-10 12:17:30 +000031 return unittest.makeSuite(UtilTestCase)
Tarek Ziadé275958a2009-02-13 22:22:03 +000032
33if __name__ == "__main__":
Éric Araujo54274ad2011-02-03 00:12:18 +000034 run_unittest(test_suite())