How to use from_str method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

genius_song.py

Source:genius_song.py Github

copy

Full Screen

...1819T = TypeVar("T")202122def from_str(x: Any) -> str:23 assert isinstance(x, str)24 return x252627def from_none(x: Any) -> Any:28 assert x is None29 return x303132def from_union(fs, x):33 for f in fs:34 try:35 return f(x)36 except: ...

Full Screen

Full Screen

release.py

Source:release.py Github

copy

Full Screen

...17T = TypeVar("T")18def from_none(x: Any) -> Any:19 assert x is None20 return x21def from_str(x: Any) -> str:22 assert isinstance(x, str)23 return x24def from_stringified_bool(x: str) -> bool:25 if x == "true":26 return True27 if x == "false":28 return False29 assert False30def from_union(fs, x):31 for f in fs:32 try:33 return f(x)34 except Exception as e:35 # print(e)36 pass37 assert False38def is_type(t: Type[T], x: Any) -> T:39 assert isinstance(x, t)40 return x41def from_list(f: Callable[[Any], T], x: Any) -> List[T]:42 assert isinstance(x, list)43 return [f(y) for y in x]44def from_int(x: Any) -> int:45 assert isinstance(x, int) and not isinstance(x, bool)46 return x47def to_class(c: Type[T], x: Any) -> dict:48 assert isinstance(x, c)49 return cast(Any, x).to_dict()50def from_datetime(x: Any) -> datetime:51 return dateutil.parser.parse(x)52@dataclass53class CoverArtArchive:54 artwork: Optional[bool] = None55 count: Optional[int] = None56 front: Optional[bool] = None57 back: Optional[bool] = None58 @staticmethod59 def from_dict(obj: Any) -> 'CoverArtArchive':60 assert isinstance(obj, dict)61 artwork = from_union([from_none, lambda x: from_stringified_bool(from_str(x))], obj.get("artwork"))62 count = from_union([from_none, lambda x: int(from_str(x))], obj.get("count"))63 front = from_union([from_none, lambda x: from_stringified_bool(from_str(x))], obj.get("front"))64 back = from_union([from_none, lambda x: from_stringified_bool(from_str(x))], obj.get("back"))65 return CoverArtArchive(artwork, count, front, back)66 def to_dict(self) -> dict:67 result: dict = {}68 result["artwork"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)), lambda x: from_str(69 (lambda x: str((lambda x: is_type(bool, x))(x)).lower())(x))], self.artwork)70 result["count"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),71 lambda x: from_str((lambda x: str((lambda x: is_type(int, x))(x)))(x))],72 self.count)73 result["front"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),74 lambda x: from_str((lambda x: str((lambda x: is_type(bool, x))(x)).lower())(x))],75 self.front)76 result["back"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),77 lambda x: from_str((lambda x: str((lambda x: is_type(bool, x))(x)).lower())(x))],78 self.back)79 return result80@dataclass81class Label:82 label_code: Optional[int] = None83 id: Optional[UUID] = None84 type: Optional[str] = None85 name: Optional[str] = None86 sort_name: Optional[str] = None87 @staticmethod88 def from_dict(obj: Any) -> 'Label':89 assert isinstance(obj, dict)90 label_code = from_union([from_none, lambda x: int(from_str(x))], obj.get("label-code"))91 id = from_union([lambda x: UUID(x), from_none], obj.get("id"))92 type = from_union([from_str, from_none], obj.get("type"))93 name = from_union([from_str, from_none], obj.get("name"))94 sort_name = from_union([from_str, from_none], obj.get("sort-name"))95 return Label(label_code, id, type, name, sort_name)96 def to_dict(self) -> dict:97 result: dict = {}98 result["label-code"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),99 lambda x: from_str((lambda x: str((lambda x: is_type(int, x))(x)))(x))],100 self.label_code)101 result["id"] = from_union([lambda x: str(x), from_none], self.id)102 result["type"] = from_union([from_str, from_none], self.type)103 result["name"] = from_union([from_str, from_none], self.name)104 result["sort-name"] = from_union([from_str, from_none], self.sort_name)105 return result106@dataclass107class LabelInfoList:108 catalog_number: Optional[Any] = None109 label: Optional[Label] = None110 @staticmethod111 def from_dict(obj: Any) -> 'LabelInfoList':112 assert isinstance(obj, dict)113 catalog_number = obj.get("catalog-number")114 label = from_union([Label.from_dict, from_none], obj.get("label"))115 return LabelInfoList(catalog_number, label)116 def to_dict(self) -> dict:117 result: dict = {}118 result["catalog-number"] = self.catalog_number119 result["label"] = from_union([lambda x: to_class(Label, x), from_none], self.label)120 return result121@dataclass122class DiscList:123 sectors: Optional[int] = None124 id: Optional[str] = None125 offset_list: Optional[List[int]] = None126 offset_count: Optional[int] = None127 @staticmethod128 def from_dict(obj: Any) -> 'DiscList':129 assert isinstance(obj, dict)130 sectors = from_union([from_none, lambda x: int(from_str(x))], obj.get("sectors"))131 id = from_union([from_str, from_none], obj.get("id"))132 offset_list = from_union([lambda x: from_list(from_int, x), from_none], obj.get("offset-list"))133 offset_count = from_union([from_int, from_none], obj.get("offset-count"))134 return DiscList(sectors, id, offset_list, offset_count)135 def to_dict(self) -> dict:136 result: dict = {}137 result["sectors"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),138 lambda x: from_str((lambda x: str((lambda x: is_type(int, x))(x)))(x))],139 self.sectors)140 result["id"] = from_union([from_str, from_none], self.id)141 result["offset-list"] = from_union([lambda x: from_list(from_int, x), from_none], self.offset_list)142 result["offset-count"] = from_union([from_int, from_none], self.offset_count)143 return result144@dataclass145class Recording:146 length: Optional[int] = None147 id: Optional[UUID] = None148 title: Optional[str] = None149 disambiguation: Optional[str] = None150 @staticmethod151 def from_dict(obj: Any) -> 'Recording':152 assert isinstance(obj, dict)153 length = from_union([from_none, lambda x: int(from_str(x))], obj.get("length"))154 id = from_union([lambda x: UUID(x), from_none], obj.get("id"))155 title = from_union([from_str, from_none], obj.get("title"))156 disambiguation = from_union([from_str, from_none], obj.get("disambiguation"))157 return Recording(length, id, title, disambiguation)158 def to_dict(self) -> dict:159 result: dict = {}160 result["length"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),161 lambda x: from_str((lambda x: str((lambda x: is_type(int, x))(x)))(x))],162 self.length)163 result["id"] = from_union([lambda x: str(x), from_none], self.id)164 result["title"] = from_union([from_str, from_none], self.title)165 result["disambiguation"] = from_union([from_str, from_none], self.disambiguation)166 return result167@dataclass168class TrackList:169 position: Optional[int] = None170 number: Optional[int] = None171 length: Optional[int] = None172 track_or_recording_length: Optional[int] = None173 id: Optional[UUID] = None174 recording: Optional[Recording] = None175 title: Optional[str] = None176 @staticmethod177 def from_dict(obj: Any) -> 'TrackList':178 assert isinstance(obj, dict)179 position = from_union([from_none, lambda x: int(from_str(x))], obj.get("position"))180 number = from_union([from_none, lambda x: int(from_str(x))], obj.get("number"))181 length = from_union([from_none, lambda x: int(from_str(x))], obj.get("length"))182 track_or_recording_length = from_union([from_none, lambda x: int(from_str(x))],183 obj.get("track_or_recording_length"))184 id = from_union([lambda x: UUID(x), from_none], obj.get("id"))185 recording = from_union([Recording.from_dict, from_none], obj.get("recording"))186 title = from_union([from_str, from_none], obj.get("title"))187 return TrackList(position, number, length, track_or_recording_length, id, recording, title)188 def to_dict(self) -> dict:189 result: dict = {}190 result["position"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),191 lambda x: from_str((lambda x: str((lambda x: is_type(int, x))(x)))(x))],192 self.position)193 result["number"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),194 lambda x: from_str((lambda x: str((lambda x: is_type(int, x))(x)))(x))],195 self.number)196 result["length"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),197 lambda x: from_str((lambda x: str((lambda x: is_type(int, x))(x)))(x))],198 self.length)199 result["track_or_recording_length"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),200 lambda x: from_str(201 (lambda x: str((lambda x: is_type(int, x))(x)))(x))],202 self.track_or_recording_length)203 result["id"] = from_union([lambda x: str(x), from_none], self.id)204 result["recording"] = from_union([lambda x: to_class(Recording, x), from_none], self.recording)205 result["title"] = from_union([from_str, from_none], self.title)206 return result207@dataclass208class MediumList:209 position: Optional[int] = None210 format: Optional[str] = None211 disc_list: Optional[List[DiscList]] = None212 disc_count: Optional[int] = None213 track_list: Optional[List[TrackList]] = None214 track_count: Optional[int] = None215 @staticmethod216 def from_dict(obj: Any) -> 'MediumList':217 assert isinstance(obj, dict)218 position = from_union([from_none, lambda x: int(from_str(x))], obj.get("position"))219 format = from_union([from_str, from_none], obj.get("format"))220 disc_list = from_union([lambda x: from_list(DiscList.from_dict, x), from_none], obj.get("disc-list"))221 disc_count = from_union([from_int, from_none], obj.get("disc-count"))222 track_list = from_union([lambda x: from_list(TrackList.from_dict, x), from_none], obj.get("track-list"))223 track_count = from_union([from_int, from_none], obj.get("track-count"))224 return MediumList(position, format, disc_list, disc_count, track_list, track_count)225 def to_dict(self) -> dict:226 result: dict = {}227 result["position"] = from_union([lambda x: from_none((lambda x: is_type(type(None), x))(x)),228 lambda x: from_str((lambda x: str((lambda x: is_type(int, x))(x)))(x))],229 self.position)230 result["format"] = from_union([from_str, from_none], self.format)231 result["disc-list"] = from_union([lambda x: from_list(lambda x: to_class(DiscList, x), x), from_none],232 self.disc_list)233 result["disc-count"] = from_union([from_int, from_none], self.disc_count)234 result["track-list"] = from_union([lambda x: from_list(lambda x: to_class(TrackList, x), x), from_none],235 self.track_list)236 result["track-count"] = from_union([from_int, from_none], self.track_count)237 return result238@dataclass239class Area:240 id: Optional[UUID] = None241 name: Optional[str] = None242 sort_name: Optional[str] = None...

Full Screen

Full Screen

IOTag_dto.py

Source:IOTag_dto.py Github

copy

Full Screen

...17 Description: str18 @staticmethod19 def from_dict(obj: Any) -> 'IOTag':20 assert isinstance(obj, dict)21 Name = from_str(obj.get("Name"))22 SignalType = from_str(obj.get("Signal Type"))23 Conversion = from_str(obj.get("Conversion"))24 Address = from_str(obj.get("Address"))25 SpanHigh = from_str(obj.get("Span High"))26 SpanLow = from_str(obj.get("Span Low"))27 UnitHigh = from_str(obj.get("Unit High"))28 UnitLow = from_str(obj.get("Unit Low"))29 InitialValue = from_str(obj.get("Initial Value"))30 ScanRate = from_str(obj.get("Scan Rate"))31 ReadWrite = from_str(obj.get("Read Write"))32 initvalue = from_str(obj.get("initvalue"))33 Description = from_str(obj.get("Description"))34 return IOTag(Name, SignalType, Conversion, Address, SpanHigh, SpanLow,UnitHigh, UnitLow, InitialValue, ScanRate, ReadWrite, initvalue, Description)35 def to_dict(self) -> dict:36 result: dict = {}37 result["Name"] = from_str(self.Name)38 result["Signal Type"] = from_str(self.SignalType)39 result["Conversion"] = from_str(self.Conversion)40 result["Address"] = from_str(self.Address)41 result["Span High"] = from_str(self.SpanHigh)42 result["Span Low"] = from_str(self.SpanLow)43 result["Unit High"] = from_str(self.UnitHigh)44 result["Unit Low"] = from_str(self.UnitLow)45 result["Initial Value"] = from_str(self.InitialValue)46 result["Scan Rate"] = from_str(self.ScanRate)47 result["Read Write"] = from_str(self.ReadWrite)48 result["initvalue"] = from_str(self.initvalue)49 result["Description"] = from_str(self.Description)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful