def test_camelize(self): input_expected = { "test": "Test", "TestCamel": "TestCamel", "test camel": "TestCamel", "test camel case": "TestCamelCase", " test camel": "TestCamel", "test camel ": "TestCamel", "test camel ": "TestCamel", "+test camel ": "TestCamel", } for noncamel_input, expected in input_expected.items(): result = util.camelize(noncamel_input) self.assertEquals(result, expected)
def _find_class_for(cls, element_name=None, class_name=None, create_missing=True): """Look in the parent modules for classes matching the element name. One or both of element/class name must be specified. Args: element_name: The name of the element type. class_name: The class name of the element type. create_missing: Whether classes should be auto-created if no existing match is found. Returns: A Resource class. """ if not element_name and not class_name: raise Error('One of element_name,class_name must be specified.') elif not element_name: element_name = util.underscore(class_name) elif not class_name: class_name = util.camelize(element_name) module_path = cls.__module__.split('.') for depth in range(len(module_path), 0, -1): try: __import__('.'.join(module_path[:depth])) module = sys.modules['.'.join(module_path[:depth])] except ImportError: continue try: klass = getattr(module, class_name) return klass except AttributeError: try: __import__('.'.join([module.__name__, element_name])) submodule = sys.modules['.'.join( [module.__name__, element_name])] except ImportError: continue try: klass = getattr(submodule, class_name) return klass except AttributeError: continue # If we made it this far, no such class was found if create_missing: return new.classobj(class_name, (cls, ), {'__module__': cls.__module__})
def _find_class_for(cls, element_name=None, class_name=None, create_missing=True): """Look in the parent modules for classes matching the element name. One or both of element/class name must be specified. Args: element_name: The name of the element type. class_name: The class name of the element type. create_missing: Whether classes should be auto-created if no existing match is found. Returns: A Resource class. """ if not element_name and not class_name: raise Error('One of element_name,class_name must be specified.') elif not element_name: element_name = util.underscore(class_name) elif not class_name: class_name = util.camelize(element_name) module_path = cls.__module__.split('.') for depth in range(len(module_path), 0, -1): try: __import__('.'.join(module_path[:depth])) module = sys.modules['.'.join(module_path[:depth])] except ImportError: continue try: klass = getattr(module, class_name) return klass except AttributeError: try: __import__('.'.join([module.__name__, element_name])) submodule = sys.modules['.'.join([module.__name__, element_name])] except ImportError: continue try: klass = getattr(submodule, class_name) return klass except AttributeError: continue # If we made it this far, no such class was found if create_missing: return new.classobj(class_name, (cls,), {'__module__': cls.__module__})
def test_camelize_with_double_underscores(self): camelized = util.camelize('double__underscores') self.assertEqual('DoubleUnderscores', camelized)
def test_camelize_ending_with_underscore(self): camelized = util.camelize('ends_') self.assertEqual('Ends', camelized)
def test_camelize_starting_with_underscore(self): camelized = util.camelize('_starts') self.assertEqual('Starts', camelized)