def test_custom(self): """Test if custom modules can be imported.""" # First clear the cache. Another module may have already imported # the same class and this would compromise the test from tvtk.tvtk_classes import tvtk_helper tvtk_helper._cache.clear() # Hack to simulate a module inside tvtk.custom. mod = types.ModuleType('xml_data_reader') class XMLDataReader: def f(self): return 'f' setattr(mod, 'XMLDataReader', XMLDataReader) sys.modules['tvtk.custom.xml_data_reader'] = mod # Now test if this is the one imported. r = tvtk.XMLDataReader() self.assertEqual(r.f(), 'f') if len(vtk.vtkObjectBase.__bases__) > 0: if vtk_major_version == 7 or PY_VER < 3: expect = () else: expect = (object,) else: expect = tuple() self.assertEqual(r.__class__.__bases__, expect) # Clean up. del sys.modules['tvtk.custom.xml_data_reader'] tvtk_helper._cache.clear()
def test_custom(self): """Test if custom modules can be imported.""" # Hack to simulate a module inside tvtk.custom. mod = types.ModuleType('xml_data_reader') class XMLDataReader: def f(self): return 'f' setattr(mod, 'XMLDataReader', XMLDataReader) sys.modules['tvtk.custom.xml_data_reader'] = mod # Now test if this is the one imported. r = tvtk.XMLDataReader() self.assertEqual(r.f(), 'f') if len(vtk.vtkObjectBase.__bases__) > 0: if is_version_7(): expect = () else: expect = (object, ) else: expect = tuple() self.assertEqual(r.__class__.__bases__, expect) # Clean up. del sys.modules['tvtk.custom.xml_data_reader']
def test_custom(self): """Test if custom modules can be imported.""" # Hack to simulate a module inside tvtk.custom. mod = new.module('xml_data_reader') class XMLDataReader: def f(self): return 'f' setattr(mod, 'XMLDataReader', XMLDataReader) sys.modules['tvtk.custom.xml_data_reader'] = mod # Now test if this is the one imported. r = tvtk.XMLDataReader() self.assertEqual(r.f(), 'f') self.assertEqual(r.__class__.__bases__, ()) # Clean up. del sys.modules['tvtk.custom.xml_data_reader']