1 """Tests for distutils.msvc9compiler."""
6 from distutils.errors import DistutilsPlatformError
7 from distutils.tests import support
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">
16 <requestedExecutionLevel level="asInvoker" uiAccess="false">
17 </requestedExecutionLevel>
18 </requestedPrivileges>
23 <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
24 version="9.0.21022.8" processorArchitecture="x86"
25 publicKeyToken="XXXX">
31 <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
32 version="9.0.21022.8" processorArchitecture="x86"
33 publicKeyToken="XXXX"></assemblyIdentity>
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">
46 <requestedExecutionLevel level="asInvoker" uiAccess="false">
47 </requestedExecutionLevel>
48 </requestedPrivileges>
56 <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
57 version="9.0.21022.8" processorArchitecture="x86"
58 publicKeyToken="XXXX"></assemblyIdentity>
63 if sys.platform=="win32":
64 from distutils.msvccompiler import get_build_version
65 if get_build_version()>=8.0:
68 SKIP_MESSAGE = "These tests are only for MSVC8.0 or above"
70 SKIP_MESSAGE = "These tests are only for win32"
72 @unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE)
73 class msvc9compilerTestCase(support.TempdirManager,
76 def test_no_compiler(self):
77 # makes sure query_vcvarsall throws
78 # a DistutilsPlatformError if the compiler
80 from distutils.msvc9compiler import query_vcvarsall
81 def _find_vcvarsall(version):
84 from distutils import msvc9compiler
85 old_find_vcvarsall = msvc9compiler.find_vcvarsall
86 msvc9compiler.find_vcvarsall = _find_vcvarsall
88 self.assertRaises(DistutilsPlatformError, query_vcvarsall,
89 'wont find this version')
91 msvc9compiler.find_vcvarsall = old_find_vcvarsall
93 def test_reg_class(self):
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'))
104 HKCU = _winreg.HKEY_CURRENT_USER
105 keys = Reg.read_keys(HKCU, 'xxxx')
106 self.assertEqual(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')
121 compiler = MSVCCompiler()
122 compiler._remove_visual_c_ref(manifest)
127 # removing trailing spaces
128 content = '\n'.join([line.rstrip() for line in f.readlines()])
132 # makes sure the manifest was properly cleaned
133 self.assertEqual(content, _CLEANED_MANIFEST)
137 return unittest.makeSuite(msvc9compilerTestCase)
139 if __name__ == "__main__":
140 unittest.main(defaultTest="test_suite")