Skip to content

Commit bbe4684

Browse files
praetorian20iMichka
authored andcommitted
Fixes for Python2.6 and gcc + castxml
unittest module in Python2.6 doesn't contain the methods 'assertIn' and 'assertNotIn', monkey patch these methods for versions < 2.7 gcc 4.4.7 and above, when using castxml, should use std::tr1 unordered containers instead of extensions provided under the __gnu_cxx namespace Cosmetic fix for xml generator name printed to stdout at the beginning of unit test execution Cherry-picked from develop branch
1 parent 95f8433 commit bbe4684

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

unittests/autoconfig.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class cxx_parsers_cfg(object):
5050
if 'msvc9' == gccxml.compiler:
5151
gccxml.define_symbols.append('_HAS_TR1=0')
5252

53+
if cxx_parsers_cfg.gccxml.xml_generator:
54+
generator_name = cxx_parsers_cfg.gccxml.xml_generator
55+
if cxx_parsers_cfg.gccxml.xml_generator_path:
56+
generator_path = cxx_parsers_cfg.gccxml.xml_generator_path
57+
5358
print(
5459
'%s configured to simulate compiler %s' %
5560
(generator_name.title(), cxx_parsers_cfg.gccxml.compiler))

unittests/data/remove_template_defaults.hpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if defined( __llvm__ )
1010

11-
// This is mostly for CastXML with never compilers
11+
// This is mostly for CastXML with newer compilers
1212

1313
// When parsing with clang//llvm use the new c++11 (c++0x even ?)
1414
// unordered_maps and unordered_sets
@@ -38,9 +38,31 @@
3838
// This is mostly for GCCXML (when using old compilers)
3939

4040
#if defined( __GNUC__ )
41-
#include <ext/hash_set>
42-
#include <ext/hash_map>
43-
#define HASH_XXX_NS __gnu_cxx
41+
#if ((__GNUC__ > 4) || \
42+
(__GNUC__ == 4 && __GNUC_MINOR__ > 4) || \
43+
(__GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ == 7)) && \
44+
defined(__castxml__)
45+
46+
// Use TR1 containers for gcc >= 4.4.7 + castxml
47+
// (this might work on older versions of gcc too, needs testing)
48+
#include <tr1/unordered_map>
49+
#include <tr1/unordered_set>
50+
#define HASH_XXX_NS std::tr1
51+
52+
#define HASH_XXX_UMAP unordered_map
53+
#define HASH_XXX_USET unordered_set
54+
#define HASH_XXX_UMMAP unordered_multimap
55+
#define HASH_XXX_UMMSET unordered_multiset
56+
#else
57+
#include <ext/hash_set>
58+
#include <ext/hash_map>
59+
#define HASH_XXX_NS __gnu_cxx
60+
61+
#define HASH_XXX_UMAP hash_map
62+
#define HASH_XXX_USET hash_set
63+
#define HASH_XXX_UMMAP hash_multimap
64+
#define HASH_XXX_UMMSET hash_multiset
65+
#endif
4466
#else
4567
#include <hash_set>
4668
#include <hash_map>
@@ -49,12 +71,12 @@
4971
#else
5072
#define HASH_XXX_NS stdext
5173
#endif
52-
#endif
5374

54-
#define HASH_XXX_UMAP hash_map
55-
#define HASH_XXX_USET hash_set
56-
#define HASH_XXX_UMMAP hash_multimap
57-
#define HASH_XXX_UMMSET hash_multiset
75+
#define HASH_XXX_UMAP hash_map
76+
#define HASH_XXX_USET hash_set
77+
#define HASH_XXX_UMMAP hash_multimap
78+
#define HASH_XXX_UMMSET hash_multiset
79+
#endif
5880

5981
#endif
6082

unittests/parser_test_case.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
# See http://www.boost.org/LICENSE_1_0.txt
55

66
import pprint
7-
try:
8-
import unittest2 as unittest
9-
except ImportError:
10-
import unittest
7+
import sys
8+
import unittest
119
import autoconfig
1210

1311

@@ -84,3 +82,10 @@ def _test_calldef_exceptions(self, calldef, exceptions):
8482
(calldef.name,
8583
pprint.pformat([delc.name for delc in exception_decls]),
8684
pprint.pformat([delc.name for delc in exceptions_indeed])))
85+
86+
if sys.version_info < (2, 7, 0):
87+
# Python2.6 does not have the following methods in the unittest module
88+
parser_test_case_t.assertIn = \
89+
lambda parser, a1, a2, *args: parser.assertTrue(a1 in a2, args)
90+
parser_test_case_t.assertNotIn = \
91+
lambda parser, a1, a2, *args: parser.assertFalse(a1 in a2, args)

0 commit comments

Comments
 (0)