b8e2209482edaa4caefb313c13b7b094f701910a
[profile/ivi/python.git] / Lib / distutils / tests / test_msvc9compiler.py
1 """Tests for distutils.msvc9compiler."""
2 import sys
3 import unittest
4 import os
5
6 from distutils.errors import DistutilsPlatformError
7 from distutils.tests import support
8
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 """
38
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>
52
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>"""
62
63 if sys.platform=="win32":
64     from distutils.msvccompiler import get_build_version
65     if get_build_version()>=8.0:
66         SKIP_MESSAGE = None
67     else:
68         SKIP_MESSAGE = "These tests are only for MSVC8.0 or above"
69 else:
70     SKIP_MESSAGE = "These tests are only for win32"
71
72 @unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE)
73 class msvc9compilerTestCase(support.TempdirManager,
74                             unittest.TestCase):
75
76     def test_no_compiler(self):
77         # makes sure query_vcvarsall throws
78         # a DistutilsPlatformError if the compiler
79         # is not found
80         from distutils.msvc9compiler import query_vcvarsall
81         def _find_vcvarsall(version):
82             return None
83
84         from distutils import msvc9compiler
85         old_find_vcvarsall = msvc9compiler.find_vcvarsall
86         msvc9compiler.find_vcvarsall = _find_vcvarsall
87         try:
88             self.assertRaises(DistutilsPlatformError, query_vcvarsall,
89                              'wont find this version')
90         finally:
91             msvc9compiler.find_vcvarsall = old_find_vcvarsall
92
93     def test_reg_class(self):
94         from distutils.msvc9compiler import Reg
95         self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx')
96
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'))
102
103         import _winreg
104         HKCU = _winreg.HKEY_CURRENT_USER
105         keys = Reg.read_keys(HKCU, 'xxxx')
106         self.assertEqual(keys, None)
107
108         keys = Reg.read_keys(HKCU, r'Control Panel')
109         self.assertTrue('Desktop' in keys)
110
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         try:
117             f.write(_MANIFEST)
118         finally:
119             f.close()
120
121         compiler = MSVCCompiler()
122         compiler._remove_visual_c_ref(manifest)
123
124         # see what we got
125         f = open(manifest)
126         try:
127             # removing trailing spaces
128             content = '\n'.join([line.rstrip() for line in f.readlines()])
129         finally:
130             f.close()
131
132         # makes sure the manifest was properly cleaned
133         self.assertEqual(content, _CLEANED_MANIFEST)
134
135
136 def test_suite():
137     return unittest.makeSuite(msvc9compilerTestCase)
138
139 if __name__ == "__main__":
140     unittest.main(defaultTest="test_suite")