Mention Giampolo R's new FTP TLS support in the what's new file
[python.git] / Lib / distutils / tests / test_cygwinccompiler.py
blobb54ffff3617bc17ea283552c12b931aae751bc8d
1 """Tests for distutils.cygwinccompiler."""
2 import unittest
3 import sys
4 import os
5 import warnings
7 from test.test_support import check_warnings
8 from test.test_support import captured_stdout
10 from distutils import cygwinccompiler
11 from distutils.cygwinccompiler import (CygwinCCompiler, check_config_h,
12 CONFIG_H_OK, CONFIG_H_NOTOK,
13 CONFIG_H_UNCERTAIN, get_versions,
14 get_msvcr, RE_VERSION)
15 from distutils.util import get_compiler_versions
16 from distutils.tests import support
18 class CygwinCCompilerTestCase(support.TempdirManager,
19 unittest.TestCase):
21 def setUp(self):
22 super(CygwinCCompilerTestCase, self).setUp()
23 self.version = sys.version
24 self.python_h = os.path.join(self.mkdtemp(), 'python.h')
25 from distutils import sysconfig
26 self.old_get_config_h_filename = sysconfig.get_config_h_filename
27 sysconfig.get_config_h_filename = self._get_config_h_filename
29 def tearDown(self):
30 sys.version = self.version
31 from distutils import sysconfig
32 sysconfig.get_config_h_filename = self.old_get_config_h_filename
33 super(CygwinCCompilerTestCase, self).tearDown()
35 def _get_config_h_filename(self):
36 return self.python_h
38 def test_check_config_h(self):
40 # check_config_h looks for "GCC" in sys.version first
41 # returns CONFIG_H_OK if found
42 sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) \n[GCC '
43 '4.0.1 (Apple Computer, Inc. build 5370)]')
45 self.assertEquals(check_config_h()[0], CONFIG_H_OK)
47 # then it tries to see if it can find "__GNUC__" in pyconfig.h
48 sys.version = 'something without the *CC word'
50 # if the file doesn't exist it returns CONFIG_H_UNCERTAIN
51 self.assertEquals(check_config_h()[0], CONFIG_H_UNCERTAIN)
53 # if it exists but does not contain __GNUC__, it returns CONFIG_H_NOTOK
54 self.write_file(self.python_h, 'xxx')
55 self.assertEquals(check_config_h()[0], CONFIG_H_NOTOK)
57 # and CONFIG_H_OK if __GNUC__ is found
58 self.write_file(self.python_h, 'xxx __GNUC__ xxx')
59 self.assertEquals(check_config_h()[0], CONFIG_H_OK)
61 def test_get_msvcr(self):
63 # none
64 sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) '
65 '\n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]')
66 self.assertEquals(get_msvcr(), None)
68 # MSVC 7.0
69 sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
70 '[MSC v.1300 32 bits (Intel)]')
71 self.assertEquals(get_msvcr(), ['msvcr70'])
73 # MSVC 7.1
74 sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
75 '[MSC v.1310 32 bits (Intel)]')
76 self.assertEquals(get_msvcr(), ['msvcr71'])
78 # VS2005 / MSVC 8.0
79 sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
80 '[MSC v.1400 32 bits (Intel)]')
81 self.assertEquals(get_msvcr(), ['msvcr80'])
83 # VS2008 / MSVC 9.0
84 sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
85 '[MSC v.1500 32 bits (Intel)]')
86 self.assertEquals(get_msvcr(), ['msvcr90'])
88 # unknown
89 sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
90 '[MSC v.1999 32 bits (Intel)]')
91 self.assertRaises(ValueError, get_msvcr)
94 def test_get_version_deprecated(self):
95 with check_warnings() as w:
96 warnings.simplefilter("always")
97 # make sure get_compiler_versions and get_versions
98 # returns the same thing
99 self.assertEquals(get_compiler_versions(), get_versions())
100 # make sure using get_version() generated a warning
101 self.assertEquals(len(w.warnings), 1)
102 # make sure any usage of RE_VERSION will also
103 # generate a warning, but till works
104 version = RE_VERSION.search('1.2').group(1)
105 self.assertEquals(version, '1.2')
106 self.assertEquals(len(w.warnings), 2)
108 def test_suite():
109 return unittest.makeSuite(CygwinCCompilerTestCase)
111 if __name__ == '__main__':
112 test_support.run_unittest(test_suite())