def method_format(self, method_name, method_args, return_type): result = View.tab() + 'def ' + method_name + '(self' result += self.method_parameter(method_args) result += '):' + View.newline() result += View.tab() + View.tab() + return_type + View.newline( ) + View.newline() return result
def attribute_maker(self, new_attributes): attributes = '' if len(new_attributes) > 0: attributes = View.tab() + 'def __init__(self):' + View.newline() self_attributes = '' for attribute in new_attributes: data_type = '' if ':' in attribute: list_temp = attribute.split(':') att_name = self.name_to_lower(list_temp[0]) data_type = ': ' + self.get_data_type(list_temp[1]) else: att_name = self.name_to_lower(attribute) self_attributes += View.tab() + View.tab( ) + 'self.' + att_name + data_type + View.newline() attributes += self_attributes return attributes
def test_02(self): # Arrange expected_result = 'Hello\nWorld' # Act actual_result = 'Hello' + View.newline() + 'World' # Assert self.assertEqual(actual_result, expected_result, 'Expected to be "Hello World')
def test_01(self): # Arrange expected_result = '\n' # Act actual_result = View.newline() # Assert self.assertEqual(actual_result, expected_result, 'Expected to be a Newline')
def class_designer(self, new_dict): file_name = self.file_name(new_dict['class']) class_name = self.class_maker(new_dict['class']) methods = self.method_maker(new_dict['method']) attributes = self.attribute_maker(new_dict['attribute']) if 'relationship' in new_dict.keys(): relationships = self.get_rel_type(new_dict['relationship']) attributes += self.relationship_maker(relationships) attributes += View.newline() temp_dict = { 'file_name': file_name, 'file_content': class_name + attributes + methods } return temp_dict
def class_maker(self, new_class_name): """ >>> name = 'LevelDesigner' >>> c_maker = ClassMaker() >>> c_maker.class_maker(name) This is the beginning. No exception is raised This is the end 'class LevelDesigner:\\n' >>> name = 'gamePlayer' >>> c_maker.class_maker(name) This is the beginning. No exception is raised This is the end 'class GamePlayer:\\n' >>> name = 'filehandler' >>> c_maker.class_maker(name) This is the beginning. No exception is raised This is the end 'class Filehandler:\\n' """ try: print("This is the beginning.") class_name = new_class_name.replace(new_class_name[0], new_class_name[0].upper(), 1) except AttributeError as err: print("The exception is: ", err) except MyError as err: print(err) else: print("No exception is raised") return 'class ' + class_name + ':' + View.newline() finally: print("This is the end")
def relationship_maker(self, new_relationship): relationships = '' for relationship in new_relationship: relationships += View.tab() + View.tab( ) + 'self.' + relationship + View.newline() return relationships