test_config_cmd.py (2461B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\distutils\tests\test_config_cmd.py 2 import unittest 3 import os 4 import sys 5 from distutils.command.config import dump_file, config 6 from distutils.tests import support 7 from distutils import log 8 9 class ConfigTestCase(support.LoggingSilencer, support.TempdirManager, unittest.TestCase): 10 11 def _info(self, msg, *args): 12 for line in msg.splitlines(): 13 self._logs.append(line) 14 15 def setUp(self): 16 super(ConfigTestCase, self).setUp() 17 self._logs = [] 18 self.old_log = log.info 19 log.info = self._info 20 21 def tearDown(self): 22 log.info = self.old_log 23 super(ConfigTestCase, self).tearDown() 24 25 def test_dump_file(self): 26 this_file = os.path.splitext(__file__)[0] + '.py' 27 f = open(this_file) 28 try: 29 numlines = len(f.readlines()) 30 finally: 31 f.close() 32 33 dump_file(this_file, 'I am the header') 34 self.assertEqual(len(self._logs), numlines + 1) 35 36 def test_search_cpp(self): 37 if sys.platform == 'win32': 38 return 39 pkg_dir, dist = self.create_dist() 40 cmd = config(dist) 41 match = cmd.search_cpp(pattern='xxx', body='// xxx') 42 self.assertEqual(match, 0) 43 match = cmd.search_cpp(pattern='_configtest', body='// xxx') 44 self.assertEqual(match, 1) 45 46 def test_finalize_options(self): 47 pkg_dir, dist = self.create_dist() 48 cmd = config(dist) 49 cmd.include_dirs = 'one%stwo' % os.pathsep 50 cmd.libraries = 'one' 51 cmd.library_dirs = 'three%sfour' % os.pathsep 52 cmd.ensure_finalized() 53 self.assertEqual(cmd.include_dirs, ['one', 'two']) 54 self.assertEqual(cmd.libraries, ['one']) 55 self.assertEqual(cmd.library_dirs, ['three', 'four']) 56 57 def test_clean(self): 58 tmp_dir = self.mkdtemp() 59 f1 = os.path.join(tmp_dir, 'one') 60 f2 = os.path.join(tmp_dir, 'two') 61 self.write_file(f1, 'xxx') 62 self.write_file(f2, 'xxx') 63 for f in (f1, f2): 64 self.assertTrue(os.path.exists(f)) 65 66 pkg_dir, dist = self.create_dist() 67 cmd = config(dist) 68 cmd._clean(f1, f2) 69 for f in (f1, f2): 70 self.assertTrue(not os.path.exists(f)) 71 72 73 def test_suite(): 74 return unittest.makeSuite(ConfigTestCase) 75 76 77 if __name__ == '__main__': 78 unittest.main(defaultTest='test_suite')