def _list_help(object_name, path=(), parent_object_names=()): """See get_help().""" items = graph_reference.ARRAYS[object_name]['items'] items_classes = set() for item in items: if item in graph_reference.OBJECT_NAME_TO_CLASS_NAME: items_classes.add(graph_reference.string_to_class_name(item)) else: # There are no lists objects which can contain list entries. items_classes.add('dict') items_classes = list(items_classes) items_classes.sort() lines = textwrap.wrap(repr(items_classes), width=LINE_SIZE-TAB_SIZE-1) help_dict = { 'object_name': object_name, 'path_string': '[' + ']['.join(repr(k) for k in path) + ']', 'parent_object_names': parent_object_names, 'items_string': '\t' + '\n\t'.join(lines) } return ( "Valid items for '{object_name}' at path {path_string} under parents " "{parent_object_names}:\n{items_string}\n".format(**help_dict) )
def test_traces_should_be_defined(self): # we *always* want to create classes for traces class_names = [gr.string_to_class_name(object_name) for object_name in gr.TRACE_NAMES] for class_name in class_names: self.assertIn(class_name, go.__dict__.keys())
def test_no_new_classes(self): # for maintenance reasons, we don't want to generate new class defs expected_class_names = {gr.string_to_class_name(object_name) for object_name in gr.TRACE_NAMES} expected_class_names.update(OLD_CLASS_NAMES) # assume that CapitalCased keys are the classes we defined current_class_names = {key for key in go.__dict__.keys() if key[0].isupper()} self.assertEqual(current_class_names, expected_class_names)
def _list_help(object_name, path=(), parent_object_names=()): """See get_help().""" items = graph_reference.ARRAYS[object_name]['items'] items_classes = [graph_reference.string_to_class_name(item) for item in items] lines = textwrap.wrap(repr(items_classes), width=LINE_SIZE-TAB_SIZE) help_dict = { 'object_name': object_name, 'path_string': '[' + ']['.join(repr(k) for k in path) + ']', 'parent_object_names': parent_object_names, 'items_string': '\t' + '\n\t'.join(lines) } return ( "Valid items for '{object_name}' at path {path_string} under parents " "{parent_object_names}:\n{items_string}\n".format(**help_dict) )
def validate(obj, obj_type): """Validate a dictionary, list, or graph object as 'obj_type'. This will not alter the 'obj' referenced in the call signature. It will raise an error if the 'obj' reference could not be instantiated as a valid 'obj_type' graph object. """ # TODO: Deprecate or move. #283 from plotly import graph_reference from plotly.graph_objs import graph_objs if obj_type not in graph_reference.CLASSES: obj_type = graph_reference.string_to_class_name(obj_type) try: cls = getattr(graph_objs, obj_type) #except AttributeError: except ValueError: raise exceptions.PlotlyError( "'{0}' is not a recognizable graph_obj.".format(obj_type)) cls(obj) # this will raise on invalid keys/items
def validate(obj, obj_type): """Validate a dictionary, list, or graph object as 'obj_type'. This will not alter the 'obj' referenced in the call signature. It will raise an error if the 'obj' reference could not be instantiated as a valid 'obj_type' graph object. """ # TODO: Deprecate or move. #283 from plotly import graph_reference from plotly.graph_objs import graph_objs if obj_type not in graph_reference.CLASSES: obj_type = graph_reference.string_to_class_name(obj_type) try: cls = getattr(graph_objs, obj_type) #except AttributeError: except ValueError: raise exceptions.PlotlyError( "'{0}' is not a recognizable graph_obj.". format(obj_type)) cls(obj) # this will raise on invalid keys/items
def _list_help(object_name, path=(), parent_object_names=()): """See get_help().""" items = graph_reference.ARRAYS[object_name]['items'] items_classes = set() for item in items: if item in graph_reference.OBJECT_NAME_TO_CLASS_NAME: items_classes.add(graph_reference.string_to_class_name(item)) else: # There are no lists objects which can contain list entries. items_classes.add('dict') items_classes = list(items_classes) items_classes.sort() lines = textwrap.wrap(repr(items_classes), width=LINE_SIZE - TAB_SIZE - 1) help_dict = { 'object_name': object_name, 'path_string': '[' + ']['.join(repr(k) for k in path) + ']', 'parent_object_names': parent_object_names, 'items_string': '\t' + '\n\t'.join(lines) } return ( "Valid items for '{object_name}' at path {path_string} under parents " "{parent_object_names}:\n{items_string}\n".format(**help_dict))
def test_capitalize_after_underscore(self): object_names = ['error_y', 'error_x'] class_names = ['ErrorY', 'ErrorX'] for object_name, class_name in zip(object_names, class_names): self.assertEqual(string_to_class_name(object_name), class_name)
def test_capitalize_first_letter(self): object_names = ['marker', 'line', 'scatter'] class_names = ['Marker', 'Line', 'Scatter'] for object_name, class_name in zip(object_names, class_names): self.assertEqual(string_to_class_name(object_name), class_name)