1 | n/a | """Tests for distutils.msvc9compiler.""" |
---|
2 | n/a | import sys |
---|
3 | n/a | import unittest |
---|
4 | n/a | import os |
---|
5 | n/a | |
---|
6 | n/a | from distutils.errors import DistutilsPlatformError |
---|
7 | n/a | from distutils.tests import support |
---|
8 | n/a | from test.support import run_unittest |
---|
9 | n/a | |
---|
10 | n/a | # A manifest with the only assembly reference being the msvcrt assembly, so |
---|
11 | n/a | # should have the assembly completely stripped. Note that although the |
---|
12 | n/a | # assembly has a <security> reference the assembly is removed - that is |
---|
13 | n/a | # currently a "feature", not a bug :) |
---|
14 | n/a | _MANIFEST_WITH_ONLY_MSVC_REFERENCE = """\ |
---|
15 | n/a | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
16 | n/a | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
17 | n/a | manifestVersion="1.0"> |
---|
18 | n/a | <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> |
---|
19 | n/a | <security> |
---|
20 | n/a | <requestedPrivileges> |
---|
21 | n/a | <requestedExecutionLevel level="asInvoker" uiAccess="false"> |
---|
22 | n/a | </requestedExecutionLevel> |
---|
23 | n/a | </requestedPrivileges> |
---|
24 | n/a | </security> |
---|
25 | n/a | </trustInfo> |
---|
26 | n/a | <dependency> |
---|
27 | n/a | <dependentAssembly> |
---|
28 | n/a | <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" |
---|
29 | n/a | version="9.0.21022.8" processorArchitecture="x86" |
---|
30 | n/a | publicKeyToken="XXXX"> |
---|
31 | n/a | </assemblyIdentity> |
---|
32 | n/a | </dependentAssembly> |
---|
33 | n/a | </dependency> |
---|
34 | n/a | </assembly> |
---|
35 | n/a | """ |
---|
36 | n/a | |
---|
37 | n/a | # A manifest with references to assemblies other than msvcrt. When processed, |
---|
38 | n/a | # this assembly should be returned with just the msvcrt part removed. |
---|
39 | n/a | _MANIFEST_WITH_MULTIPLE_REFERENCES = """\ |
---|
40 | n/a | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
41 | n/a | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
42 | n/a | manifestVersion="1.0"> |
---|
43 | n/a | <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> |
---|
44 | n/a | <security> |
---|
45 | n/a | <requestedPrivileges> |
---|
46 | n/a | <requestedExecutionLevel level="asInvoker" uiAccess="false"> |
---|
47 | n/a | </requestedExecutionLevel> |
---|
48 | n/a | </requestedPrivileges> |
---|
49 | n/a | </security> |
---|
50 | n/a | </trustInfo> |
---|
51 | n/a | <dependency> |
---|
52 | n/a | <dependentAssembly> |
---|
53 | n/a | <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" |
---|
54 | n/a | version="9.0.21022.8" processorArchitecture="x86" |
---|
55 | n/a | publicKeyToken="XXXX"> |
---|
56 | n/a | </assemblyIdentity> |
---|
57 | n/a | </dependentAssembly> |
---|
58 | n/a | </dependency> |
---|
59 | n/a | <dependency> |
---|
60 | n/a | <dependentAssembly> |
---|
61 | n/a | <assemblyIdentity type="win32" name="Microsoft.VC90.MFC" |
---|
62 | n/a | version="9.0.21022.8" processorArchitecture="x86" |
---|
63 | n/a | publicKeyToken="XXXX"></assemblyIdentity> |
---|
64 | n/a | </dependentAssembly> |
---|
65 | n/a | </dependency> |
---|
66 | n/a | </assembly> |
---|
67 | n/a | """ |
---|
68 | n/a | |
---|
69 | n/a | _CLEANED_MANIFEST = """\ |
---|
70 | n/a | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
71 | n/a | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
72 | n/a | manifestVersion="1.0"> |
---|
73 | n/a | <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> |
---|
74 | n/a | <security> |
---|
75 | n/a | <requestedPrivileges> |
---|
76 | n/a | <requestedExecutionLevel level="asInvoker" uiAccess="false"> |
---|
77 | n/a | </requestedExecutionLevel> |
---|
78 | n/a | </requestedPrivileges> |
---|
79 | n/a | </security> |
---|
80 | n/a | </trustInfo> |
---|
81 | n/a | <dependency> |
---|
82 | n/a | |
---|
83 | n/a | </dependency> |
---|
84 | n/a | <dependency> |
---|
85 | n/a | <dependentAssembly> |
---|
86 | n/a | <assemblyIdentity type="win32" name="Microsoft.VC90.MFC" |
---|
87 | n/a | version="9.0.21022.8" processorArchitecture="x86" |
---|
88 | n/a | publicKeyToken="XXXX"></assemblyIdentity> |
---|
89 | n/a | </dependentAssembly> |
---|
90 | n/a | </dependency> |
---|
91 | n/a | </assembly>""" |
---|
92 | n/a | |
---|
93 | n/a | if sys.platform=="win32": |
---|
94 | n/a | from distutils.msvccompiler import get_build_version |
---|
95 | n/a | if get_build_version()>=8.0: |
---|
96 | n/a | SKIP_MESSAGE = None |
---|
97 | n/a | else: |
---|
98 | n/a | SKIP_MESSAGE = "These tests are only for MSVC8.0 or above" |
---|
99 | n/a | else: |
---|
100 | n/a | SKIP_MESSAGE = "These tests are only for win32" |
---|
101 | n/a | |
---|
102 | n/a | @unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE) |
---|
103 | n/a | class msvc9compilerTestCase(support.TempdirManager, |
---|
104 | n/a | unittest.TestCase): |
---|
105 | n/a | |
---|
106 | n/a | def test_no_compiler(self): |
---|
107 | n/a | # makes sure query_vcvarsall raises |
---|
108 | n/a | # a DistutilsPlatformError if the compiler |
---|
109 | n/a | # is not found |
---|
110 | n/a | from distutils.msvc9compiler import query_vcvarsall |
---|
111 | n/a | def _find_vcvarsall(version): |
---|
112 | n/a | return None |
---|
113 | n/a | |
---|
114 | n/a | from distutils import msvc9compiler |
---|
115 | n/a | old_find_vcvarsall = msvc9compiler.find_vcvarsall |
---|
116 | n/a | msvc9compiler.find_vcvarsall = _find_vcvarsall |
---|
117 | n/a | try: |
---|
118 | n/a | self.assertRaises(DistutilsPlatformError, query_vcvarsall, |
---|
119 | n/a | 'wont find this version') |
---|
120 | n/a | finally: |
---|
121 | n/a | msvc9compiler.find_vcvarsall = old_find_vcvarsall |
---|
122 | n/a | |
---|
123 | n/a | def test_reg_class(self): |
---|
124 | n/a | from distutils.msvc9compiler import Reg |
---|
125 | n/a | self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx') |
---|
126 | n/a | |
---|
127 | n/a | # looking for values that should exist on all |
---|
128 | n/a | # windows registry versions. |
---|
129 | n/a | path = r'Control Panel\Desktop' |
---|
130 | n/a | v = Reg.get_value(path, 'dragfullwindows') |
---|
131 | n/a | self.assertIn(v, ('0', '1', '2')) |
---|
132 | n/a | |
---|
133 | n/a | import winreg |
---|
134 | n/a | HKCU = winreg.HKEY_CURRENT_USER |
---|
135 | n/a | keys = Reg.read_keys(HKCU, 'xxxx') |
---|
136 | n/a | self.assertEqual(keys, None) |
---|
137 | n/a | |
---|
138 | n/a | keys = Reg.read_keys(HKCU, r'Control Panel') |
---|
139 | n/a | self.assertIn('Desktop', keys) |
---|
140 | n/a | |
---|
141 | n/a | def test_remove_visual_c_ref(self): |
---|
142 | n/a | from distutils.msvc9compiler import MSVCCompiler |
---|
143 | n/a | tempdir = self.mkdtemp() |
---|
144 | n/a | manifest = os.path.join(tempdir, 'manifest') |
---|
145 | n/a | f = open(manifest, 'w') |
---|
146 | n/a | try: |
---|
147 | n/a | f.write(_MANIFEST_WITH_MULTIPLE_REFERENCES) |
---|
148 | n/a | finally: |
---|
149 | n/a | f.close() |
---|
150 | n/a | |
---|
151 | n/a | compiler = MSVCCompiler() |
---|
152 | n/a | compiler._remove_visual_c_ref(manifest) |
---|
153 | n/a | |
---|
154 | n/a | # see what we got |
---|
155 | n/a | f = open(manifest) |
---|
156 | n/a | try: |
---|
157 | n/a | # removing trailing spaces |
---|
158 | n/a | content = '\n'.join([line.rstrip() for line in f.readlines()]) |
---|
159 | n/a | finally: |
---|
160 | n/a | f.close() |
---|
161 | n/a | |
---|
162 | n/a | # makes sure the manifest was properly cleaned |
---|
163 | n/a | self.assertEqual(content, _CLEANED_MANIFEST) |
---|
164 | n/a | |
---|
165 | n/a | def test_remove_entire_manifest(self): |
---|
166 | n/a | from distutils.msvc9compiler import MSVCCompiler |
---|
167 | n/a | tempdir = self.mkdtemp() |
---|
168 | n/a | manifest = os.path.join(tempdir, 'manifest') |
---|
169 | n/a | f = open(manifest, 'w') |
---|
170 | n/a | try: |
---|
171 | n/a | f.write(_MANIFEST_WITH_ONLY_MSVC_REFERENCE) |
---|
172 | n/a | finally: |
---|
173 | n/a | f.close() |
---|
174 | n/a | |
---|
175 | n/a | compiler = MSVCCompiler() |
---|
176 | n/a | got = compiler._remove_visual_c_ref(manifest) |
---|
177 | n/a | self.assertIsNone(got) |
---|
178 | n/a | |
---|
179 | n/a | |
---|
180 | n/a | def test_suite(): |
---|
181 | n/a | return unittest.makeSuite(msvc9compilerTestCase) |
---|
182 | n/a | |
---|
183 | n/a | if __name__ == "__main__": |
---|
184 | n/a | run_unittest(test_suite()) |
---|