Issue #7575: An overflow test for math.expm1 was failing on OS X 10.4/Intel,
[python.git] / Lib / distutils / tests / test_msvc9compiler.py
blob503a5a80565c2e586f9a167e0d1653ebddf451a7
1 """Tests for distutils.msvc9compiler."""
2 import sys
3 import unittest
4 import os
6 from distutils.errors import DistutilsPlatformError
7 from distutils.tests import support
9 _MANIFEST = """\
10 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
11 <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
12 manifestVersion="1.0">
13 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
14 <security>
15 <requestedPrivileges>
16 <requestedExecutionLevel level="asInvoker" uiAccess="false">
17 </requestedExecutionLevel>
18 </requestedPrivileges>
19 </security>
20 </trustInfo>
21 <dependency>
22 <dependentAssembly>
23 <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
24 version="9.0.21022.8" processorArchitecture="x86"
25 publicKeyToken="XXXX">
26 </assemblyIdentity>
27 </dependentAssembly>
28 </dependency>
29 <dependency>
30 <dependentAssembly>
31 <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
32 version="9.0.21022.8" processorArchitecture="x86"
33 publicKeyToken="XXXX"></assemblyIdentity>
34 </dependentAssembly>
35 </dependency>
36 </assembly>
37 """
39 _CLEANED_MANIFEST = """\
40 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
41 <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
42 manifestVersion="1.0">
43 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
44 <security>
45 <requestedPrivileges>
46 <requestedExecutionLevel level="asInvoker" uiAccess="false">
47 </requestedExecutionLevel>
48 </requestedPrivileges>
49 </security>
50 </trustInfo>
51 <dependency>
53 </dependency>
54 <dependency>
55 <dependentAssembly>
56 <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
57 version="9.0.21022.8" processorArchitecture="x86"
58 publicKeyToken="XXXX"></assemblyIdentity>
59 </dependentAssembly>
60 </dependency>
61 </assembly>"""
63 @unittest.skipUnless(sys.platform=="win32", "These tests are only for win32")
64 class msvc9compilerTestCase(support.TempdirManager,
65 unittest.TestCase):
67 def test_no_compiler(self):
68 # makes sure query_vcvarsall throws
69 # a DistutilsPlatformError if the compiler
70 # is not found
71 from distutils.msvccompiler import get_build_version
72 if get_build_version() < 8.0:
73 # this test is only for MSVC8.0 or above
74 return
75 from distutils.msvc9compiler import query_vcvarsall
76 def _find_vcvarsall(version):
77 return None
79 from distutils import msvc9compiler
80 old_find_vcvarsall = msvc9compiler.find_vcvarsall
81 msvc9compiler.find_vcvarsall = _find_vcvarsall
82 try:
83 self.assertRaises(DistutilsPlatformError, query_vcvarsall,
84 'wont find this version')
85 finally:
86 msvc9compiler.find_vcvarsall = old_find_vcvarsall
88 def test_reg_class(self):
89 from distutils.msvccompiler import get_build_version
90 if get_build_version() < 8.0:
91 # this test is only for MSVC8.0 or above
92 return
94 from distutils.msvc9compiler import Reg
95 self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx')
97 # looking for values that should exist on all
98 # windows registeries versions.
99 path = r'Control Panel\Desktop'
100 v = Reg.get_value(path, u'dragfullwindows')
101 self.assertTrue(v in (u'0', u'1', u'2'))
103 import _winreg
104 HKCU = _winreg.HKEY_CURRENT_USER
105 keys = Reg.read_keys(HKCU, 'xxxx')
106 self.assertEquals(keys, None)
108 keys = Reg.read_keys(HKCU, r'Control Panel')
109 self.assertTrue('Desktop' in keys)
111 def test_remove_visual_c_ref(self):
112 from distutils.msvc9compiler import MSVCCompiler
113 tempdir = self.mkdtemp()
114 manifest = os.path.join(tempdir, 'manifest')
115 f = open(manifest, 'w')
116 f.write(_MANIFEST)
117 f.close()
119 compiler = MSVCCompiler()
120 compiler._remove_visual_c_ref(manifest)
122 # see what we got
123 f = open(manifest)
124 # removing trailing spaces
125 content = '\n'.join([line.rstrip() for line in f.readlines()])
126 f.close()
128 # makes sure the manifest was properly cleaned
129 self.assertEquals(content, _CLEANED_MANIFEST)
132 def test_suite():
133 return unittest.makeSuite(msvc9compilerTestCase)
135 if __name__ == "__main__":
136 unittest.main(defaultTest="test_suite")