| 1 | n/a | """Tests for packaging.cygwinccompiler.""" |
|---|
| 2 | n/a | import os |
|---|
| 3 | n/a | import sys |
|---|
| 4 | n/a | import sysconfig |
|---|
| 5 | n/a | from packaging.compiler.cygwinccompiler import ( |
|---|
| 6 | n/a | check_config_h, get_msvcr, |
|---|
| 7 | n/a | CONFIG_H_OK, CONFIG_H_NOTOK, CONFIG_H_UNCERTAIN) |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | from packaging.tests import unittest, support |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | class CygwinCCompilerTestCase(support.TempdirManager, |
|---|
| 13 | n/a | unittest.TestCase): |
|---|
| 14 | n/a | |
|---|
| 15 | n/a | def setUp(self): |
|---|
| 16 | n/a | super(CygwinCCompilerTestCase, self).setUp() |
|---|
| 17 | n/a | self.version = sys.version |
|---|
| 18 | n/a | self.python_h = os.path.join(self.mkdtemp(), 'python.h') |
|---|
| 19 | n/a | self.old_get_config_h_filename = sysconfig.get_config_h_filename |
|---|
| 20 | n/a | sysconfig.get_config_h_filename = self._get_config_h_filename |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | def tearDown(self): |
|---|
| 23 | n/a | sys.version = self.version |
|---|
| 24 | n/a | sysconfig.get_config_h_filename = self.old_get_config_h_filename |
|---|
| 25 | n/a | super(CygwinCCompilerTestCase, self).tearDown() |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | def _get_config_h_filename(self): |
|---|
| 28 | n/a | return self.python_h |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | def test_check_config_h(self): |
|---|
| 31 | n/a | # check_config_h looks for "GCC" in sys.version first |
|---|
| 32 | n/a | # returns CONFIG_H_OK if found |
|---|
| 33 | n/a | sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) \n[GCC ' |
|---|
| 34 | n/a | '4.0.1 (Apple Computer, Inc. build 5370)]') |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | self.assertEqual(check_config_h()[0], CONFIG_H_OK) |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | # then it tries to see if it can find "__GNUC__" in pyconfig.h |
|---|
| 39 | n/a | sys.version = 'something without the *CC word' |
|---|
| 40 | n/a | |
|---|
| 41 | n/a | # if the file doesn't exist it returns CONFIG_H_UNCERTAIN |
|---|
| 42 | n/a | self.assertEqual(check_config_h()[0], CONFIG_H_UNCERTAIN) |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | # if it exists but does not contain __GNUC__, it returns CONFIG_H_NOTOK |
|---|
| 45 | n/a | self.write_file(self.python_h, 'xxx') |
|---|
| 46 | n/a | self.assertEqual(check_config_h()[0], CONFIG_H_NOTOK) |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | # and CONFIG_H_OK if __GNUC__ is found |
|---|
| 49 | n/a | self.write_file(self.python_h, 'xxx __GNUC__ xxx') |
|---|
| 50 | n/a | self.assertEqual(check_config_h()[0], CONFIG_H_OK) |
|---|
| 51 | n/a | |
|---|
| 52 | n/a | def test_get_msvcr(self): |
|---|
| 53 | n/a | # none |
|---|
| 54 | n/a | sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) ' |
|---|
| 55 | n/a | '\n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]') |
|---|
| 56 | n/a | self.assertEqual(get_msvcr(), None) |
|---|
| 57 | n/a | |
|---|
| 58 | n/a | # MSVC 7.0 |
|---|
| 59 | n/a | sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' |
|---|
| 60 | n/a | '[MSC v.1300 32 bits (Intel)]') |
|---|
| 61 | n/a | self.assertEqual(get_msvcr(), ['msvcr70']) |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | # MSVC 7.1 |
|---|
| 64 | n/a | sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' |
|---|
| 65 | n/a | '[MSC v.1310 32 bits (Intel)]') |
|---|
| 66 | n/a | self.assertEqual(get_msvcr(), ['msvcr71']) |
|---|
| 67 | n/a | |
|---|
| 68 | n/a | # VS2005 / MSVC 8.0 |
|---|
| 69 | n/a | sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' |
|---|
| 70 | n/a | '[MSC v.1400 32 bits (Intel)]') |
|---|
| 71 | n/a | self.assertEqual(get_msvcr(), ['msvcr80']) |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | # VS2008 / MSVC 9.0 |
|---|
| 74 | n/a | sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' |
|---|
| 75 | n/a | '[MSC v.1500 32 bits (Intel)]') |
|---|
| 76 | n/a | self.assertEqual(get_msvcr(), ['msvcr90']) |
|---|
| 77 | n/a | |
|---|
| 78 | n/a | # unknown |
|---|
| 79 | n/a | sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' |
|---|
| 80 | n/a | '[MSC v.1999 32 bits (Intel)]') |
|---|
| 81 | n/a | self.assertRaises(ValueError, get_msvcr) |
|---|
| 82 | n/a | |
|---|
| 83 | n/a | |
|---|
| 84 | n/a | def test_suite(): |
|---|
| 85 | n/a | return unittest.makeSuite(CygwinCCompilerTestCase) |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | if __name__ == '__main__': |
|---|
| 88 | n/a | unittest.main(defaultTest='test_suite') |
|---|