MCPcopy Create free account
hub / github.com/Vanderhoof/PyDBML / Enum

Class Enum

pydbml/_classes/enum.py:41–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40
41class Enum(SQLObject, DBMLObject):
42 required_attributes = ('name', 'schema', 'items')
43
44 def __init__(self,
45 name: str,
46 items: Iterable[Union['EnumItem', str]],
47 schema: str = 'public',
48 comment: Optional[str] = None):
49 self.database = None
50 self.name = name
51 self.schema = schema
52 self.comment = comment
53 self.items: List[EnumItem] = []
54 for item in items:
55 self.add_item(item)
56
57 def add_item(self, item: Union['EnumItem', str]) -> None:
58 if isinstance(item, EnumItem):
59 self.items.append(item)
60 elif isinstance(item, str):
61 self.items.append(EnumItem(item))
62
63 def __getitem__(self, key: int) -> EnumItem:
64 return self.items[key]
65
66 def __iter__(self):
67 return iter(self.items)
68
69 def __repr__(self):
70 '''
71 >>> en = EnumItem('en-US')
72 >>> ru = EnumItem('ru-RU')
73 >>> Enum('languages', [en, ru])
74 <Enum 'languages', ['en-US', 'ru-RU']>
75 ''&#x27;
76
77 item_names = [i.name for i in self.items]
78 classname = self.__class__.__name__
79 return f'<{classname} {self.name!r}, {item_names!r}>'
80
81 def __str__(self):
82 ''&#x27;
83 >>> en = EnumItem('en-US')
84 >>> ru = EnumItem('ru-RU')
85 >>> print(Enum('languages', [en, ru]))
86 languages
87 ''&#x27;
88
89 return self.name

Callers 13

test_add_enumMethod · 0.90
test_add_enum_badMethod · 0.90
test_delete_enumMethod · 0.90
test_addMethod · 0.90
test_deleteMethod · 0.90
enum1Function · 0.90
create_databaseMethod · 0.90
test_getitemMethod · 0.90
test_iterMethod · 0.90
test_enum_typeMethod · 0.90
test_enum_type_schemaMethod · 0.90

Calls

no outgoing calls

Tested by 12

test_add_enumMethod · 0.72
test_add_enum_badMethod · 0.72
test_delete_enumMethod · 0.72
test_addMethod · 0.72
test_deleteMethod · 0.72
enum1Function · 0.72
create_databaseMethod · 0.72
test_getitemMethod · 0.72
test_iterMethod · 0.72
test_enum_typeMethod · 0.72
test_enum_type_schemaMethod · 0.72