[pygccxml-commit] SF.net SVN: pygccxml: [1164] pyplusplus_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-11-20 21:30:52
|
Revision: 1164 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1164&view=rev Author: roman_yakovenko Date: 2007-11-20 13:30:53 -0800 (Tue, 20 Nov 2007) Log Message: ----------- improving and fixing unittests Modified Paths: -------------- pyplusplus_dev/unittests/already_exposed_tester.py pyplusplus_dev/unittests/custom_smart_ptr_classes_tester.py pyplusplus_dev/unittests/data/custom_smart_ptr.h pyplusplus_dev/unittests/data/custom_smart_ptr_classes_to_be_exported.hpp pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp pyplusplus_dev/unittests/exposed_decls_db_tester.py pyplusplus_dev/unittests/function_transformations_tester.py pyplusplus_dev/unittests/fundamental_tester_base.py pyplusplus_dev/unittests/include_exclude_bug_tester.py pyplusplus_dev/unittests/split_module_tester.py pyplusplus_dev/unittests/test_all.py pyplusplus_dev/unittests/transfer_ownership_old_tester.py Modified: pyplusplus_dev/unittests/already_exposed_tester.py =================================================================== --- pyplusplus_dev/unittests/already_exposed_tester.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/already_exposed_tester.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -13,17 +13,17 @@ class tester_t( unittest.TestCase ): def test(self): + exposed_db = utils.exposed_decls_db_t() + fpath = os.path.join( autoconfig.data_directory, 'already_exposed_to_be_exported.hpp' ) mb = module_builder.module_builder_t( [module_builder.create_source_fc( fpath )] , gccxml_path=autoconfig.gccxml.executable ) - exposed_db = utils.exposed_decls_db_t() - ae = mb.namespace( 'already_exposed' ) - map( exposed_db.expose, ae.decls(recursive=True) ) + mb.global_ns.exclude() + mb.namespace( 'already_exposed' ).include() + exposed_db.register_decls( mb.global_ns ) exposed_db.save( autoconfig.build_dir ) mb.register_module_dependency( autoconfig.build_dir ) - mb.decls().exclude() - mb.namespace( 'already_exposed' ).include() mb.class_( 'ae_derived' ).include() mb.build_code_creator( 'xxx' ) Modified: pyplusplus_dev/unittests/custom_smart_ptr_classes_tester.py =================================================================== --- pyplusplus_dev/unittests/custom_smart_ptr_classes_tester.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/custom_smart_ptr_classes_tester.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -15,26 +15,31 @@ # include <boost/python/converter/rvalue_from_python_data.hpp> # include <boost/python/converter/registered.hpp> -namespace boost{ namespace python{ +using namespace controllers; - using namespace controllers; - using namespace converter; +namespace smart_ptrs{ + controller_i* get_pointer( my_smart_ptr_t< controller_i > const& p ){ return p.get(); } - template <> - struct pointee< my_smart_ptr_t< controller_i > >{ - typedef controller_i type; - }; - - add_x_t* get_pointer( my_smart_ptr_t< add_x_t > const& p ){ return p.get(); } +} + +namespace boost{ namespace python{ + + using namespace converter; + template <> - struct pointee< my_smart_ptr_t< add_x_t > >{ + struct pointee< smart_ptrs::my_smart_ptr_t< controller_i > >{ + typedef controller_i type; + }; + + template <> + struct pointee< smart_ptrs::my_smart_ptr_t< add_x_t > >{ typedef add_x_t type; }; @@ -44,7 +49,7 @@ { my_smart_ptr_from_python() { - converter::registry::insert(&convertible, &construct, type_id<my_smart_ptr_t<T> >()); + converter::registry::insert(&convertible, &construct, type_id<smart_ptrs::my_smart_ptr_t<T> >()); } private: @@ -58,13 +63,13 @@ static void construct(PyObject* source, rvalue_from_python_stage1_data* data) { - void* const storage = ((converter::rvalue_from_python_storage<my_smart_ptr_t<T> >*)data)->storage.bytes; + void* const storage = ((converter::rvalue_from_python_storage<smart_ptrs::my_smart_ptr_t<T> >*)data)->storage.bytes; // Deal with the "None" case. if (data->convertible == source) - new (storage) my_smart_ptr_t<T>(); + new (storage) smart_ptrs::my_smart_ptr_t<T>(); else{ - std::cout << "before new (storage) my_smart_ptr_t<T>( static_cast< T* >(data->convertible) );" << std::endl; - new (storage) my_smart_ptr_t<T>( static_cast< T* >(data->convertible) ); + std::cout << "before new (storage) smart_ptrs::my_smart_ptr_t<T>( static_cast< T* >(data->convertible) );" << std::endl; + new (storage) smart_ptrs::my_smart_ptr_t<T>( static_cast< T* >(data->convertible) ); } data->convertible = storage; } @@ -72,8 +77,8 @@ template <class T> struct ptr_to_python { - static PyObject *convert(my_smart_ptr_t<T> const &p) { - return incref(object(my_smart_ptr_t<T>(p)).ptr()); + static PyObject *convert(smart_ptrs::my_smart_ptr_t<T> const &p) { + return incref(object(smart_ptrs::my_smart_ptr_t<T>(p)).ptr()); } }; @@ -86,7 +91,7 @@ template <typename Class> void visit(Class &c) const { typedef typename Class::wrapped_type T; - to_python_converter<my_smart_ptr_t<T>, ptr_to_python<T> >(); + to_python_converter<smart_ptrs::my_smart_ptr_t<T>, ptr_to_python<T> >(); } }; @@ -98,11 +103,11 @@ """ boost::python::my_smart_ptr_from_python<controllers::add_x_t>(); - bp::register_ptr_to_python< my_smart_ptr_t< controllers::controller_i > >(); + bp::register_ptr_to_python< smart_ptrs::my_smart_ptr_t< controllers::controller_i > >(); - //bp::register_ptr_to_python< my_smart_ptr_t< controllers::add_x_t > >(); + //bp::register_ptr_to_python< smart_ptrs::my_smart_ptr_t< controllers::add_x_t > >(); - bp::implicitly_convertible< my_smart_ptr_t< controllers::add_x_t >, my_smart_ptr_t< controllers::controller_i > >(); + bp::implicitly_convertible< smart_ptrs::my_smart_ptr_t< controllers::add_x_t >, smart_ptrs::my_smart_ptr_t< controllers::controller_i > >(); """ @@ -120,7 +125,7 @@ mb.add_declaration_code( MODULE_SPTR_DECL_CODE ) mb.add_registration_code( MODULE_SPTR_REG_CODE ) add_x_t = mb.class_( 'add_x_t' ) - add_x_t.held_type = 'my_smart_ptr_t< controllers::add_x_t >' + add_x_t.held_type = 'smart_ptrs::my_smart_ptr_t< controllers::add_x_t >' add_x_t.add_registration_code( 'def(boost::python::smart_ptr_stuff())' ) mb.build_code_creator( self.EXTENSION_NAME ) @@ -149,6 +154,7 @@ return add_5_value_t( v ) def run_tests(self, module): + self.fail( "The test fails with Segmentation fault error." ) add_0 = module.add_x_t( 23 ) print '>',1 self.failUnless( 23 == add_0.get_value() ) Modified: pyplusplus_dev/unittests/data/custom_smart_ptr.h =================================================================== --- pyplusplus_dev/unittests/data/custom_smart_ptr.h 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/data/custom_smart_ptr.h 2007-11-20 21:30:53 UTC (rev 1164) @@ -3,6 +3,8 @@ #include <assert.h> +namespace smart_ptrs{ + template<class T> class my_smart_ptr_t { protected: T* pRep; @@ -100,6 +102,7 @@ return a.get() != b.get(); } +} #endif //__my_smart_ptr_t__ Modified: pyplusplus_dev/unittests/data/custom_smart_ptr_classes_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/custom_smart_ptr_classes_to_be_exported.hpp 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/data/custom_smart_ptr_classes_to_be_exported.hpp 2007-11-20 21:30:53 UTC (rev 1164) @@ -8,7 +8,7 @@ virtual int get_value(void) const = 0; }; -typedef my_smart_ptr_t<controller_i> controller_ptr_i; +typedef smart_ptrs::my_smart_ptr_t<controller_i> controller_ptr_i; struct multiply_x_t : controller_i{ multiply_x_t( int value ) @@ -27,7 +27,7 @@ int m_value; }; -typedef my_smart_ptr_t<multiply_x_t> multiply_x_ptr_t; +typedef smart_ptrs::my_smart_ptr_t<multiply_x_t> multiply_x_ptr_t; struct add_x_t : controller_i{ add_x_t( int value ) @@ -47,19 +47,19 @@ }; -struct add_x_ptr_t : public my_smart_ptr_t< add_x_t >{ +struct add_x_ptr_t : public smart_ptrs::my_smart_ptr_t< add_x_t >{ explicit add_x_ptr_t(add_x_t* rep) - : my_smart_ptr_t<add_x_t>(rep) + : smart_ptrs::my_smart_ptr_t<add_x_t>(rep) {} add_x_ptr_t(const add_x_ptr_t& r) - : my_smart_ptr_t<add_x_t>(r) + : smart_ptrs::my_smart_ptr_t<add_x_t>(r) {} //added by me( Roman ), to allow implicit conversion between add_x_ptr_t and add_x_ptr_t - //operator my_smart_ptr_t<resource_t>() const { - // return my_smart_ptr_t<resource_t>( *this ); + //operator smart_ptrs::my_smart_ptr_t<resource_t>() const { + // return smart_ptrs::my_smart_ptr_t<resource_t>( *this ); //} /// Operator used to convert a add_x_ptr_t to a add_x_ptr_t @@ -101,7 +101,7 @@ } //inline int -//val_get_value( my_smart_ptr_t< controllers::add_x_t > a ){ +//val_get_value( smart_ptrs::my_smart_ptr_t< controllers::add_x_t > a ){ // return a->get_value(); //} Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2007-11-20 21:30:53 UTC (rev 1164) @@ -245,6 +245,13 @@ } }; +struct render_queue_listener_t{ + virtual void + render_queue_ended( int group_id + , const std::string& invocation + , bool& repeat_this_invocation ){}; +}; + } #endif//__function_transformations_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/exposed_decls_db_tester.py =================================================================== --- pyplusplus_dev/unittests/exposed_decls_db_tester.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/exposed_decls_db_tester.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -9,6 +9,7 @@ import autoconfig from pygccxml import parser from pygccxml import declarations +from pyplusplus import decl_wrappers from pyplusplus import code_creators from pyplusplus import module_creator from pyplusplus import module_builder @@ -43,15 +44,22 @@ def test(self): db = pypp_utils.exposed_decls_db_t() config = parser.config_t( gccxml_path=autoconfig.gccxml.executable ) - global_ns = declarations.get_global_namespace( parser.parse_string( self.CODE, config ) ) + + reader = parser.project_reader_t( config, None, decl_wrappers.dwfactory_t() ) + decls = reader.read_files( [parser.create_text_fc(self.CODE)] ) + + global_ns = declarations.get_global_namespace( decls ) ns = global_ns.namespace( 'ns' ) - for d in ns.decls(recursive=True): - db.expose( d ) + ns_skip = global_ns.namespace( 'ns_skip' ) + + global_ns.exclude() + ns.include() + + db.register_decls( global_ns ) for x in ns.decls(recursive=True): self.failUnless( db.is_exposed( x ) == True ) - - ns_skip = global_ns.namespace( 'ns_skip' ) + for x in ns_skip.decls(recursive=True): self.failUnless( db.is_exposed( x ) == False ) @@ -66,7 +74,6 @@ for x in ns_skip.decls(recursive=True): self.failUnless( db.is_exposed( x ) == False ) - def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -91,6 +91,10 @@ tester = transfer_ownership_tester.mem_fun( 'tester' ) tester.add_transformation( ft.transfer_ownership( 0 ) ) + render_queue_listener_t = mb.class_( 'render_queue_listener_t' ) + render_queue_ended = render_queue_listener_t.mem_fun( 'render_queue_ended' ) + render_queue_ended.add_transformation( ft.inout(2) ) + def run_tests(self, module): """Run the actual unit tests. """ Modified: pyplusplus_dev/unittests/fundamental_tester_base.py =================================================================== --- pyplusplus_dev/unittests/fundamental_tester_base.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/fundamental_tester_base.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -55,13 +55,24 @@ , declarations.namespace_t , declarations.free_operator_t ) for d in mb.decls(): - if d.ignore or not d.exportable or isinstance( d, irrelevant_decl_types ): + if not d.exportable: continue - if d.parent and not d.parent.name: - continue #unnamed classes - self.failUnless( exposed_db.is_exposed( d ) - , '''Declaration "%s" is exposed, but for some reason it isn't marked as such.''' - % str( d ) ) + elif isinstance( d, declarations.free_operator_t ): + continue + elif d.ignore: + if exposed_db.is_exposed( d ): + i = 0 + self.failUnless( not exposed_db.is_exposed( d ) + , '''Declaration "%s" is NOT exposed, but for some reason it is marked as such.''' + % str( d ) ) + #if d.ignore or not d.exportable or isinstance( d, irrelevant_decl_types ): + #continue + #if d.parent and not d.parent.name: + #continue #unnamed classes + else: + self.failUnless( exposed_db.is_exposed( d ) + , '''Declaration "%s" is exposed, but for some reason it isn't marked as such.''' + % str( d ) ) def customize(self, generator): pass Modified: pyplusplus_dev/unittests/include_exclude_bug_tester.py =================================================================== --- pyplusplus_dev/unittests/include_exclude_bug_tester.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/include_exclude_bug_tester.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -19,7 +19,7 @@ , *args ) def customize(self, mb ): - pass + mb.mem_fun( '::Ogre::Any::swap' ).exclude() def run_tests( self, module): pass Modified: pyplusplus_dev/unittests/split_module_tester.py =================================================================== --- pyplusplus_dev/unittests/split_module_tester.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/split_module_tester.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -27,8 +27,12 @@ def customize( self, mb ): mb.global_ns.exclude() + nm_t = declarations.remove_declarated( mb.global_ns.typedef( 'naive_matrix_t' ).type ) + nm_t.include() + exposed_db = utils.exposed_decls_db_t() - exposed_db.expose( declarations.remove_declarated( mb.global_ns.typedef( 'naive_matrix_t' ).type ) ) + + exposed_db.register_decls( mb.global_ns ) exposed_db.save( autoconfig.build_dir ) mb.register_module_dependency( autoconfig.build_dir ) Modified: pyplusplus_dev/unittests/test_all.py =================================================================== --- pyplusplus_dev/unittests/test_all.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/test_all.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -179,58 +179,28 @@ , include_exclude_bug_tester ] -class process_tester_runner_t( object ): +class module_runner_t( object ): + bottom_line_re = re.compile( 'Ran\s(?P<num_of_tests>\d+)\stests?\sin\s(?P<seconds>\d+\.?\d*)s') + test_name_re = re.compile( '(?P<name>.+ \(.+\))\s\.\.\.' ) + failed_test_re = re.compile( 'FAIL\:\s(?P<name>.+ \(.+\))' ) + error_test_re = re.compile( 'ERROR\:\s(?P<name>.+ \(.+\))' ) - class module_stat_t( object ): - bottom_line_re = re.compile( 'Ran\s(?P<num_of_tests>\d+)\stests?\sin\s(?P<seconds>\d+\.?\d*)s') - test_name_re = re.compile( '(?P<name>.+ \(.+\))\s\.\.\.' ) - failed_test_re = re.compile( 'FAIL\:\s(?P<name>.+ \(.+\))' ) - error_test_re = re.compile( 'ERROR\:\s(?P<name>.+ \(.+\))' ) + def __init__( self, module ): + self.module = module + self.output = None - def __init__( self, module, output, exit_status ): - self.module = module - self.output = output - - self.test_results = {} #test name : result - self.num_of_tests = 0 - self.total_run_time = 0 - self.exit_status = exit_status + self.test_results = {} #test name : result + self.num_of_tests = 0 + self.total_run_time = 0 + self.exit_status = None - self.__update() - - def __create_unique_name( self, name ): - if '__main__.' in name: - name = name.replace( '__main__', os.path.basename( self.module.__file__)[:-4] ) - return name - - def __update( self ): - match_found = self.bottom_line_re.search( self.output ) - if match_found: - self.num_of_tests += int( match_found.group( 'num_of_tests' ) ) - self.total_run_time += float( match_found.group( 'seconds' ) ) - - uname = self.__create_unique_name - for match_found in self.test_name_re.finditer( self.output ): - self.test_results[ uname( match_found.group( 'name' ) ) ] = 'ok' - - for match_found in self.failed_test_re.finditer( self.output ): - self.test_results[ uname( match_found.group( 'name' ) ) ] = 'FAIL' - - for match_found in self.error_test_re.finditer( self.output ): - self.test_results[ uname( match_found.group( 'name' ) ) ] = 'ERROR' - - assert( self.num_of_tests == len( self.test_results ) ) - - def __init__( self, modules ): - self.__modules = modules - self.__statistics = [] - self.__total_time = 0 - - def __run_single( self, module ): - test_file_name = module.__file__[:-1] + def __call__( self ): + print os.linesep, '<*> start %s tester' % os.path.basename( self.module.__file__) + + test_file_name = self.module.__file__ if test_file_name.endswith( 'pyc' ): test_file_name = test_file_name[:-1] - command_line = ' '.join([ sys.executable, test_file_name ]) #pyc -> py + command_line = ' '.join([ sys.executable, test_file_name ]) input_, output = os.popen4( command_line ) input_.close() report = [] @@ -241,15 +211,47 @@ break else: print data, - exit_status = output.close() - self.__statistics.append( self.module_stat_t( module, ''.join( report ), exit_status ) ) + self.output = ''.join( report ) + self.exit_status = output.close() + self.__update() + print '<***> finish %s tester' % os.path.basename( self.module.__file__) + + def __create_unique_name( self, name ): + if '__main__.' in name: + name = name.replace( '__main__', os.path.basename( self.module.__file__)[:-4] ) + return name + + def __update( self ): + match_found = self.bottom_line_re.search( self.output ) + if match_found: + self.num_of_tests += int( match_found.group( 'num_of_tests' ) ) + self.total_run_time += float( match_found.group( 'seconds' ) ) + uname = self.__create_unique_name + for match_found in self.test_name_re.finditer( self.output ): + self.test_results[ uname( match_found.group( 'name' ) ) ] = 'ok' + + for match_found in self.failed_test_re.finditer( self.output ): + self.test_results[ uname( match_found.group( 'name' ) ) ] = 'FAIL' + + for match_found in self.error_test_re.finditer( self.output ): + self.test_results[ uname( match_found.group( 'name' ) ) ] = 'ERROR' + + assert( self.num_of_tests == len( self.test_results ) ) + + +class process_tester_runner_t( object ): + + def __init__( self, modules ): + self.__m_runners = [ module_runner_t(m) for m in modules ] + self.__total_time = 0 + def __dump_statistics( self ): num_of_tests = 0 test_results = {} total_tests_only_run_time = 0 exit_status = 0 - for stat in self.__statistics: + for stat in self.__m_runners: num_of_tests += stat.num_of_tests total_tests_only_run_time += stat.total_run_time test_results.update( stat.test_results ) @@ -272,8 +274,7 @@ def __call__( self ): start_time = time.time() - for m in self.__modules: - self.__run_single( m ) + [ m() for m in self.__m_runners ] self.__total_time = time.time() - start_time self.__dump_statistics() Modified: pyplusplus_dev/unittests/transfer_ownership_old_tester.py =================================================================== --- pyplusplus_dev/unittests/transfer_ownership_old_tester.py 2007-11-20 21:29:57 UTC (rev 1163) +++ pyplusplus_dev/unittests/transfer_ownership_old_tester.py 2007-11-20 21:30:53 UTC (rev 1164) @@ -34,7 +34,7 @@ def customize( self, mb ): event_clss = mb.classes( lambda cls: cls.name in ( 'event_t', 'do_nothing_t' ) ) for cls in event_clss: - cls.class_type = cls.CLASS_TYPE.WRAPPER + cls.exposed_class_type = cls.EXPOSED_CLASS_TYPE.WRAPPER cls.held_type = 'std::auto_ptr< %s >' % cls.wrapper_alias cls.add_registration_code( register_sptr % 'std::auto_ptr< %s >' % cls.decl_string, False ) cls.add_registration_code( impl_conv_code % { 'from' : cls.wrapper_alias This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |