How to use fromString method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

map_unittest_pb2.pyi

Source:map_unittest_pb2.pyi Github

copy

Full Screen

1from google.protobuf.message import (2 Message,3)4from google.protobuf.unittest_no_arena_pb2 import (5 ForeignMessage,6)7from google.protobuf.unittest_pb2 import (8 ForeignMessage as ForeignMessage1,9 TestAllTypes,10 TestRequired,11)12from typing import (13 List,14 Mapping,15 MutableMapping,16 Optional,17 Text,18 Tuple,19 cast,20)21class MapEnum(int):22 @classmethod23 def Name(cls, number: int) -> str: ...24 @classmethod25 def Value(cls, name: str) -> MapEnum: ...26 @classmethod27 def keys(cls) -> List[str]: ...28 @classmethod29 def values(cls) -> List[MapEnum]: ...30 @classmethod31 def items(cls) -> List[Tuple[str, MapEnum]]: ...32MAP_ENUM_FOO: MapEnum33MAP_ENUM_BAR: MapEnum34MAP_ENUM_BAZ: MapEnum35class TestMap(Message):36 class MapInt32Int32Entry(Message):37 key = ... # type: int38 value = ... # type: int39 def __init__(self,40 key: Optional[int] = ...,41 value: Optional[int] = ...,42 ) -> None: ...43 @classmethod44 def FromString(cls, s: str) -> TestMap.MapInt32Int32Entry: ...45 class MapInt64Int64Entry(Message):46 key = ... # type: int47 value = ... # type: int48 def __init__(self,49 key: Optional[int] = ...,50 value: Optional[int] = ...,51 ) -> None: ...52 @classmethod53 def FromString(cls, s: str) -> TestMap.MapInt64Int64Entry: ...54 class MapUint32Uint32Entry(Message):55 key = ... # type: int56 value = ... # type: int57 def __init__(self,58 key: Optional[int] = ...,59 value: Optional[int] = ...,60 ) -> None: ...61 @classmethod62 def FromString(cls, s: str) -> TestMap.MapUint32Uint32Entry: ...63 class MapUint64Uint64Entry(Message):64 key = ... # type: int65 value = ... # type: int66 def __init__(self,67 key: Optional[int] = ...,68 value: Optional[int] = ...,69 ) -> None: ...70 @classmethod71 def FromString(cls, s: str) -> TestMap.MapUint64Uint64Entry: ...72 class MapSint32Sint32Entry(Message):73 key = ... # type: int74 value = ... # type: int75 def __init__(self,76 key: Optional[int] = ...,77 value: Optional[int] = ...,78 ) -> None: ...79 @classmethod80 def FromString(cls, s: str) -> TestMap.MapSint32Sint32Entry: ...81 class MapSint64Sint64Entry(Message):82 key = ... # type: int83 value = ... # type: int84 def __init__(self,85 key: Optional[int] = ...,86 value: Optional[int] = ...,87 ) -> None: ...88 @classmethod89 def FromString(cls, s: str) -> TestMap.MapSint64Sint64Entry: ...90 class MapFixed32Fixed32Entry(Message):91 key = ... # type: int92 value = ... # type: int93 def __init__(self,94 key: Optional[int] = ...,95 value: Optional[int] = ...,96 ) -> None: ...97 @classmethod98 def FromString(cls, s: str) -> TestMap.MapFixed32Fixed32Entry: ...99 class MapFixed64Fixed64Entry(Message):100 key = ... # type: int101 value = ... # type: int102 def __init__(self,103 key: Optional[int] = ...,104 value: Optional[int] = ...,105 ) -> None: ...106 @classmethod107 def FromString(cls, s: str) -> TestMap.MapFixed64Fixed64Entry: ...108 class MapSfixed32Sfixed32Entry(Message):109 key = ... # type: int110 value = ... # type: int111 def __init__(self,112 key: Optional[int] = ...,113 value: Optional[int] = ...,114 ) -> None: ...115 @classmethod116 def FromString(cls, s: str) -> TestMap.MapSfixed32Sfixed32Entry: ...117 class MapSfixed64Sfixed64Entry(Message):118 key = ... # type: int119 value = ... # type: int120 def __init__(self,121 key: Optional[int] = ...,122 value: Optional[int] = ...,123 ) -> None: ...124 @classmethod125 def FromString(cls, s: str) -> TestMap.MapSfixed64Sfixed64Entry: ...126 class MapInt32FloatEntry(Message):127 key = ... # type: int128 value = ... # type: float129 def __init__(self,130 key: Optional[int] = ...,131 value: Optional[float] = ...,132 ) -> None: ...133 @classmethod134 def FromString(cls, s: str) -> TestMap.MapInt32FloatEntry: ...135 class MapInt32DoubleEntry(Message):136 key = ... # type: int137 value = ... # type: float138 def __init__(self,139 key: Optional[int] = ...,140 value: Optional[float] = ...,141 ) -> None: ...142 @classmethod143 def FromString(cls, s: str) -> TestMap.MapInt32DoubleEntry: ...144 class MapBoolBoolEntry(Message):145 key = ... # type: bool146 value = ... # type: bool147 def __init__(self,148 key: Optional[bool] = ...,149 value: Optional[bool] = ...,150 ) -> None: ...151 @classmethod152 def FromString(cls, s: str) -> TestMap.MapBoolBoolEntry: ...153 class MapStringStringEntry(Message):154 key = ... # type: Text155 value = ... # type: Text156 def __init__(self,157 key: Optional[Text] = ...,158 value: Optional[Text] = ...,159 ) -> None: ...160 @classmethod161 def FromString(cls, s: str) -> TestMap.MapStringStringEntry: ...162 class MapInt32BytesEntry(Message):163 key = ... # type: int164 value = ... # type: str165 def __init__(self,166 key: Optional[int] = ...,167 value: Optional[str] = ...,168 ) -> None: ...169 @classmethod170 def FromString(cls, s: str) -> TestMap.MapInt32BytesEntry: ...171 class MapInt32EnumEntry(Message):172 key = ... # type: int173 value = ... # type: MapEnum174 def __init__(self,175 key: Optional[int] = ...,176 value: Optional[MapEnum] = ...,177 ) -> None: ...178 @classmethod179 def FromString(cls, s: str) -> TestMap.MapInt32EnumEntry: ...180 class MapInt32ForeignMessageEntry(Message):181 key = ... # type: int182 @property183 def value(self) -> ForeignMessage1: ...184 def __init__(self,185 key: Optional[int] = ...,186 value: Optional[ForeignMessage1] = ...,187 ) -> None: ...188 @classmethod189 def FromString(cls, s: str) -> TestMap.MapInt32ForeignMessageEntry: ...190 class MapStringForeignMessageEntry(Message):191 key = ... # type: Text192 @property193 def value(self) -> ForeignMessage1: ...194 def __init__(self,195 key: Optional[Text] = ...,196 value: Optional[ForeignMessage1] = ...,197 ) -> None: ...198 @classmethod199 def FromString(200 cls, s: str) -> TestMap.MapStringForeignMessageEntry: ...201 class MapInt32AllTypesEntry(Message):202 key = ... # type: int203 @property204 def value(self) -> TestAllTypes: ...205 def __init__(self,206 key: Optional[int] = ...,207 value: Optional[TestAllTypes] = ...,208 ) -> None: ...209 @classmethod210 def FromString(cls, s: str) -> TestMap.MapInt32AllTypesEntry: ...211 @property212 def map_int32_int32(self) -> MutableMapping[int, int]: ...213 @property214 def map_int64_int64(self) -> MutableMapping[int, int]: ...215 @property216 def map_uint32_uint32(self) -> MutableMapping[int, int]: ...217 @property218 def map_uint64_uint64(self) -> MutableMapping[int, int]: ...219 @property220 def map_sint32_sint32(self) -> MutableMapping[int, int]: ...221 @property222 def map_sint64_sint64(self) -> MutableMapping[int, int]: ...223 @property224 def map_fixed32_fixed32(self) -> MutableMapping[int, int]: ...225 @property226 def map_fixed64_fixed64(self) -> MutableMapping[int, int]: ...227 @property228 def map_sfixed32_sfixed32(self) -> MutableMapping[int, int]: ...229 @property230 def map_sfixed64_sfixed64(self) -> MutableMapping[int, int]: ...231 @property232 def map_int32_float(self) -> MutableMapping[int, float]: ...233 @property234 def map_int32_double(self) -> MutableMapping[int, float]: ...235 @property236 def map_bool_bool(self) -> MutableMapping[bool, bool]: ...237 @property238 def map_string_string(self) -> MutableMapping[Text, Text]: ...239 @property240 def map_int32_bytes(self) -> MutableMapping[int, str]: ...241 @property242 def map_int32_enum(self) -> MutableMapping[int, MapEnum]: ...243 @property244 def map_int32_foreign_message(245 self) -> MutableMapping[int, ForeignMessage1]: ...246 @property247 def map_string_foreign_message(248 self) -> MutableMapping[Text, ForeignMessage1]: ...249 @property250 def map_int32_all_types(self) -> MutableMapping[int, TestAllTypes]: ...251 def __init__(self,252 map_int32_int32: Optional[Mapping[int, int]]=...,253 map_int64_int64: Optional[Mapping[int, int]]=...,254 map_uint32_uint32: Optional[Mapping[int, int]]=...,255 map_uint64_uint64: Optional[Mapping[int, int]]=...,256 map_sint32_sint32: Optional[Mapping[int, int]]=...,257 map_sint64_sint64: Optional[Mapping[int, int]]=...,258 map_fixed32_fixed32: Optional[Mapping[int, int]]=...,259 map_fixed64_fixed64: Optional[Mapping[int, int]]=...,260 map_sfixed32_sfixed32: Optional[Mapping[int, int]]=...,261 map_sfixed64_sfixed64: Optional[Mapping[int, int]]=...,262 map_int32_float: Optional[Mapping[int, float]]=...,263 map_int32_double: Optional[Mapping[int, float]]=...,264 map_bool_bool: Optional[Mapping[bool, bool]]=...,265 map_string_string: Optional[Mapping[Text, Text]]=...,266 map_int32_bytes: Optional[Mapping[int, str]]=...,267 map_int32_enum: Optional[Mapping[int, MapEnum]]=...,268 map_int32_foreign_message: Optional[Mapping[int, ForeignMessage1]]=...,269 map_string_foreign_message: Optional[Mapping[Text, ForeignMessage1]]=...,270 map_int32_all_types: Optional[Mapping[int, TestAllTypes]]=...,271 ) -> None: ...272 @classmethod273 def FromString(cls, s: str) -> TestMap: ...274class TestMapSubmessage(Message):275 @property276 def test_map(self) -> TestMap: ...277 def __init__(self,278 test_map: Optional[TestMap] = ...,279 ) -> None: ...280 @classmethod281 def FromString(cls, s: str) -> TestMapSubmessage: ...282class TestMessageMap(Message):283 class MapInt32MessageEntry(Message):284 key = ... # type: int285 @property286 def value(self) -> TestAllTypes: ...287 def __init__(self,288 key: Optional[int] = ...,289 value: Optional[TestAllTypes] = ...,290 ) -> None: ...291 @classmethod292 def FromString(cls, s: str) -> TestMessageMap.MapInt32MessageEntry: ...293 @property294 def map_int32_message(self) -> MutableMapping[int, TestAllTypes]: ...295 def __init__(self,296 map_int32_message: Optional[Mapping[int, TestAllTypes]]=...,297 ) -> None: ...298 @classmethod299 def FromString(cls, s: str) -> TestMessageMap: ...300class TestSameTypeMap(Message):301 class Map1Entry(Message):302 key = ... # type: int303 value = ... # type: int304 def __init__(self,305 key: Optional[int] = ...,306 value: Optional[int] = ...,307 ) -> None: ...308 @classmethod309 def FromString(cls, s: str) -> TestSameTypeMap.Map1Entry: ...310 class Map2Entry(Message):311 key = ... # type: int312 value = ... # type: int313 def __init__(self,314 key: Optional[int] = ...,315 value: Optional[int] = ...,316 ) -> None: ...317 @classmethod318 def FromString(cls, s: str) -> TestSameTypeMap.Map2Entry: ...319 @property320 def map1(self) -> MutableMapping[int, int]: ...321 @property322 def map2(self) -> MutableMapping[int, int]: ...323 def __init__(self,324 map1: Optional[Mapping[int, int]]=...,325 map2: Optional[Mapping[int, int]]=...,326 ) -> None: ...327 @classmethod328 def FromString(cls, s: str) -> TestSameTypeMap: ...329class TestRequiredMessageMap(Message):330 class MapFieldEntry(Message):331 key = ... # type: int332 @property333 def value(self) -> TestRequired: ...334 def __init__(self,335 key: Optional[int] = ...,336 value: Optional[TestRequired] = ...,337 ) -> None: ...338 @classmethod339 def FromString(340 cls, s: str) -> TestRequiredMessageMap.MapFieldEntry: ...341 @property342 def map_field(self) -> MutableMapping[int, TestRequired]: ...343 def __init__(self,344 map_field: Optional[Mapping[int, TestRequired]]=...,345 ) -> None: ...346 @classmethod347 def FromString(cls, s: str) -> TestRequiredMessageMap: ...348class TestArenaMap(Message):349 class MapInt32Int32Entry(Message):350 key = ... # type: int351 value = ... # type: int352 def __init__(self,353 key: Optional[int] = ...,354 value: Optional[int] = ...,355 ) -> None: ...356 @classmethod357 def FromString(cls, s: str) -> TestArenaMap.MapInt32Int32Entry: ...358 class MapInt64Int64Entry(Message):359 key = ... # type: int360 value = ... # type: int361 def __init__(self,362 key: Optional[int] = ...,363 value: Optional[int] = ...,364 ) -> None: ...365 @classmethod366 def FromString(cls, s: str) -> TestArenaMap.MapInt64Int64Entry: ...367 class MapUint32Uint32Entry(Message):368 key = ... # type: int369 value = ... # type: int370 def __init__(self,371 key: Optional[int] = ...,372 value: Optional[int] = ...,373 ) -> None: ...374 @classmethod375 def FromString(cls, s: str) -> TestArenaMap.MapUint32Uint32Entry: ...376 class MapUint64Uint64Entry(Message):377 key = ... # type: int378 value = ... # type: int379 def __init__(self,380 key: Optional[int] = ...,381 value: Optional[int] = ...,382 ) -> None: ...383 @classmethod384 def FromString(cls, s: str) -> TestArenaMap.MapUint64Uint64Entry: ...385 class MapSint32Sint32Entry(Message):386 key = ... # type: int387 value = ... # type: int388 def __init__(self,389 key: Optional[int] = ...,390 value: Optional[int] = ...,391 ) -> None: ...392 @classmethod393 def FromString(cls, s: str) -> TestArenaMap.MapSint32Sint32Entry: ...394 class MapSint64Sint64Entry(Message):395 key = ... # type: int396 value = ... # type: int397 def __init__(self,398 key: Optional[int] = ...,399 value: Optional[int] = ...,400 ) -> None: ...401 @classmethod402 def FromString(cls, s: str) -> TestArenaMap.MapSint64Sint64Entry: ...403 class MapFixed32Fixed32Entry(Message):404 key = ... # type: int405 value = ... # type: int406 def __init__(self,407 key: Optional[int] = ...,408 value: Optional[int] = ...,409 ) -> None: ...410 @classmethod411 def FromString(cls, s: str) -> TestArenaMap.MapFixed32Fixed32Entry: ...412 class MapFixed64Fixed64Entry(Message):413 key = ... # type: int414 value = ... # type: int415 def __init__(self,416 key: Optional[int] = ...,417 value: Optional[int] = ...,418 ) -> None: ...419 @classmethod420 def FromString(cls, s: str) -> TestArenaMap.MapFixed64Fixed64Entry: ...421 class MapSfixed32Sfixed32Entry(Message):422 key = ... # type: int423 value = ... # type: int424 def __init__(self,425 key: Optional[int] = ...,426 value: Optional[int] = ...,427 ) -> None: ...428 @classmethod429 def FromString(430 cls, s: str) -> TestArenaMap.MapSfixed32Sfixed32Entry: ...431 class MapSfixed64Sfixed64Entry(Message):432 key = ... # type: int433 value = ... # type: int434 def __init__(self,435 key: Optional[int] = ...,436 value: Optional[int] = ...,437 ) -> None: ...438 @classmethod439 def FromString(440 cls, s: str) -> TestArenaMap.MapSfixed64Sfixed64Entry: ...441 class MapInt32FloatEntry(Message):442 key = ... # type: int443 value = ... # type: float444 def __init__(self,445 key: Optional[int] = ...,446 value: Optional[float] = ...,447 ) -> None: ...448 @classmethod449 def FromString(cls, s: str) -> TestArenaMap.MapInt32FloatEntry: ...450 class MapInt32DoubleEntry(Message):451 key = ... # type: int452 value = ... # type: float453 def __init__(self,454 key: Optional[int] = ...,455 value: Optional[float] = ...,456 ) -> None: ...457 @classmethod458 def FromString(cls, s: str) -> TestArenaMap.MapInt32DoubleEntry: ...459 class MapBoolBoolEntry(Message):460 key = ... # type: bool461 value = ... # type: bool462 def __init__(self,463 key: Optional[bool] = ...,464 value: Optional[bool] = ...,465 ) -> None: ...466 @classmethod467 def FromString(cls, s: str) -> TestArenaMap.MapBoolBoolEntry: ...468 class MapStringStringEntry(Message):469 key = ... # type: Text470 value = ... # type: Text471 def __init__(self,472 key: Optional[Text] = ...,473 value: Optional[Text] = ...,474 ) -> None: ...475 @classmethod476 def FromString(cls, s: str) -> TestArenaMap.MapStringStringEntry: ...477 class MapInt32BytesEntry(Message):478 key = ... # type: int479 value = ... # type: str480 def __init__(self,481 key: Optional[int] = ...,482 value: Optional[str] = ...,483 ) -> None: ...484 @classmethod485 def FromString(cls, s: str) -> TestArenaMap.MapInt32BytesEntry: ...486 class MapInt32EnumEntry(Message):487 key = ... # type: int488 value = ... # type: MapEnum489 def __init__(self,490 key: Optional[int] = ...,491 value: Optional[MapEnum] = ...,492 ) -> None: ...493 @classmethod494 def FromString(cls, s: str) -> TestArenaMap.MapInt32EnumEntry: ...495 class MapInt32ForeignMessageEntry(Message):496 key = ... # type: int497 @property498 def value(self) -> ForeignMessage1: ...499 def __init__(self,500 key: Optional[int] = ...,501 value: Optional[ForeignMessage1] = ...,502 ) -> None: ...503 @classmethod504 def FromString(505 cls, s: str) -> TestArenaMap.MapInt32ForeignMessageEntry: ...506 class MapInt32ForeignMessageNoArenaEntry(Message):507 key = ... # type: int508 @property509 def value(self) -> ForeignMessage: ...510 def __init__(self,511 key: Optional[int] = ...,512 value: Optional[ForeignMessage] = ...,513 ) -> None: ...514 @classmethod515 def FromString(516 cls, s: str) -> TestArenaMap.MapInt32ForeignMessageNoArenaEntry: ...517 @property518 def map_int32_int32(self) -> MutableMapping[int, int]: ...519 @property520 def map_int64_int64(self) -> MutableMapping[int, int]: ...521 @property522 def map_uint32_uint32(self) -> MutableMapping[int, int]: ...523 @property524 def map_uint64_uint64(self) -> MutableMapping[int, int]: ...525 @property526 def map_sint32_sint32(self) -> MutableMapping[int, int]: ...527 @property528 def map_sint64_sint64(self) -> MutableMapping[int, int]: ...529 @property530 def map_fixed32_fixed32(self) -> MutableMapping[int, int]: ...531 @property532 def map_fixed64_fixed64(self) -> MutableMapping[int, int]: ...533 @property534 def map_sfixed32_sfixed32(self) -> MutableMapping[int, int]: ...535 @property536 def map_sfixed64_sfixed64(self) -> MutableMapping[int, int]: ...537 @property538 def map_int32_float(self) -> MutableMapping[int, float]: ...539 @property540 def map_int32_double(self) -> MutableMapping[int, float]: ...541 @property542 def map_bool_bool(self) -> MutableMapping[bool, bool]: ...543 @property544 def map_string_string(self) -> MutableMapping[Text, Text]: ...545 @property546 def map_int32_bytes(self) -> MutableMapping[int, str]: ...547 @property548 def map_int32_enum(self) -> MutableMapping[int, MapEnum]: ...549 @property550 def map_int32_foreign_message(551 self) -> MutableMapping[int, ForeignMessage1]: ...552 @property553 def map_int32_foreign_message_no_arena(554 self) -> MutableMapping[int, ForeignMessage]: ...555 def __init__(self,556 map_int32_int32: Optional[Mapping[int, int]]=...,557 map_int64_int64: Optional[Mapping[int, int]]=...,558 map_uint32_uint32: Optional[Mapping[int, int]]=...,559 map_uint64_uint64: Optional[Mapping[int, int]]=...,560 map_sint32_sint32: Optional[Mapping[int, int]]=...,561 map_sint64_sint64: Optional[Mapping[int, int]]=...,562 map_fixed32_fixed32: Optional[Mapping[int, int]]=...,563 map_fixed64_fixed64: Optional[Mapping[int, int]]=...,564 map_sfixed32_sfixed32: Optional[Mapping[int, int]]=...,565 map_sfixed64_sfixed64: Optional[Mapping[int, int]]=...,566 map_int32_float: Optional[Mapping[int, float]]=...,567 map_int32_double: Optional[Mapping[int, float]]=...,568 map_bool_bool: Optional[Mapping[bool, bool]]=...,569 map_string_string: Optional[Mapping[Text, Text]]=...,570 map_int32_bytes: Optional[Mapping[int, str]]=...,571 map_int32_enum: Optional[Mapping[int, MapEnum]]=...,572 map_int32_foreign_message: Optional[Mapping[int, ForeignMessage1]]=...,573 map_int32_foreign_message_no_arena: Optional[Mapping[int, ForeignMessage]]=...,574 ) -> None: ...575 @classmethod576 def FromString(cls, s: str) -> TestArenaMap: ...577class MessageContainingEnumCalledType(Message):578 class Type(int):579 @classmethod580 def Name(cls, number: int) -> str: ...581 @classmethod582 def Value(cls, name: str) -> MessageContainingEnumCalledType.Type: ...583 @classmethod584 def keys(cls) -> List[str]: ...585 @classmethod586 def values(cls) -> List[MessageContainingEnumCalledType.Type]: ...587 @classmethod588 def items(cls) -> List[Tuple[str,589 MessageContainingEnumCalledType.Type]]: ...590 TYPE_FOO: Type591 class TypeEntry(Message):592 key = ... # type: Text593 @property594 def value(self) -> MessageContainingEnumCalledType: ...595 def __init__(self,596 key: Optional[Text] = ...,597 value: Optional[MessageContainingEnumCalledType] = ...,598 ) -> None: ...599 @classmethod600 def FromString(601 cls, s: str) -> MessageContainingEnumCalledType.TypeEntry: ...602 @property603 def type(self) -> MutableMapping[Text,604 MessageContainingEnumCalledType]: ...605 def __init__(self,606 type: Optional[Mapping[Text, MessageContainingEnumCalledType]]=...,607 ) -> None: ...608 @classmethod609 def FromString(cls, s: str) -> MessageContainingEnumCalledType: ...610class MessageContainingMapCalledEntry(Message):611 class EntryEntry(Message):612 key = ... # type: int613 value = ... # type: int614 def __init__(self,615 key: Optional[int] = ...,616 value: Optional[int] = ...,617 ) -> None: ...618 @classmethod619 def FromString(620 cls, s: str) -> MessageContainingMapCalledEntry.EntryEntry: ...621 @property622 def entry(self) -> MutableMapping[int, int]: ...623 def __init__(self,624 entry: Optional[Mapping[int, int]]=...,625 ) -> None: ...626 @classmethod627 def FromString(cls, s: str) -> MessageContainingMapCalledEntry: ...628class TestRecursiveMapMessage(Message):629 class AEntry(Message):630 key = ... # type: Text631 @property632 def value(self) -> TestRecursiveMapMessage: ...633 def __init__(self,634 key: Optional[Text] = ...,635 value: Optional[TestRecursiveMapMessage] = ...,636 ) -> None: ...637 @classmethod638 def FromString(cls, s: str) -> TestRecursiveMapMessage.AEntry: ...639 @property640 def a(self) -> MutableMapping[Text, TestRecursiveMapMessage]: ...641 def __init__(self,642 a: Optional[Mapping[Text, TestRecursiveMapMessage]]=...,643 ) -> None: ...644 @classmethod...

Full Screen

Full Screen

test_symbolic.py

Source:test_symbolic.py Github

copy

Full Screen

1from numpy.testing import assert_raises2from numpy.f2py.symbolic import (3 Expr, Op, ArithOp, Language,4 as_symbol, as_number, as_string, as_array, as_complex,5 as_terms, as_factors, eliminate_quotes, insert_quotes,6 fromstring, as_expr, as_apply,7 as_numer_denom, as_ternary, as_ref, as_deref,8 normalize, as_eq, as_ne, as_lt, as_gt, as_le, as_ge9 )10from . import util11class TestSymbolic(util.F2PyTest):12 def test_eliminate_quotes(self):13 def worker(s):14 r, d = eliminate_quotes(s)15 s1 = insert_quotes(r, d)16 assert s1 == s17 for kind in ['', 'mykind_']:18 worker(kind + '"1234" // "ABCD"')19 worker(kind + '"1234" // ' + kind + '"ABCD"')20 worker(kind + '"1234" // \'ABCD\'')21 worker(kind + '"1234" // ' + kind + '\'ABCD\'')22 worker(kind + '"1\\"2\'AB\'34"')23 worker('a = ' + kind + "'1\\'2\"AB\"34'")24 def test_sanity(self):25 x = as_symbol('x')26 y = as_symbol('y')27 z = as_symbol('z')28 assert x.op == Op.SYMBOL29 assert repr(x) == "Expr(Op.SYMBOL, 'x')"30 assert x == x31 assert x != y32 assert hash(x) is not None33 n = as_number(123)34 m = as_number(456)35 assert n.op == Op.INTEGER36 assert repr(n) == "Expr(Op.INTEGER, (123, 4))"37 assert n == n38 assert n != m39 assert hash(n) is not None40 fn = as_number(12.3)41 fm = as_number(45.6)42 assert fn.op == Op.REAL43 assert repr(fn) == "Expr(Op.REAL, (12.3, 4))"44 assert fn == fn45 assert fn != fm46 assert hash(fn) is not None47 c = as_complex(1, 2)48 c2 = as_complex(3, 4)49 assert c.op == Op.COMPLEX50 assert repr(c) == ("Expr(Op.COMPLEX, (Expr(Op.INTEGER, (1, 4)),"51 " Expr(Op.INTEGER, (2, 4))))")52 assert c == c53 assert c != c254 assert hash(c) is not None55 s = as_string("'123'")56 s2 = as_string('"ABC"')57 assert s.op == Op.STRING58 assert repr(s) == "Expr(Op.STRING, (\"'123'\", 1))", repr(s)59 assert s == s60 assert s != s261 a = as_array((n, m))62 b = as_array((n,))63 assert a.op == Op.ARRAY64 assert repr(a) == ("Expr(Op.ARRAY, (Expr(Op.INTEGER, (123, 4)),"65 " Expr(Op.INTEGER, (456, 4))))")66 assert a == a67 assert a != b68 t = as_terms(x)69 u = as_terms(y)70 assert t.op == Op.TERMS71 assert repr(t) == "Expr(Op.TERMS, {Expr(Op.SYMBOL, 'x'): 1})"72 assert t == t73 assert t != u74 assert hash(t) is not None75 v = as_factors(x)76 w = as_factors(y)77 assert v.op == Op.FACTORS78 assert repr(v) == "Expr(Op.FACTORS, {Expr(Op.SYMBOL, 'x'): 1})"79 assert v == v80 assert w != v81 assert hash(v) is not None82 t = as_ternary(x, y, z)83 u = as_ternary(x, z, y)84 assert t.op == Op.TERNARY85 assert t == t86 assert t != u87 assert hash(t) is not None88 e = as_eq(x, y)89 f = as_lt(x, y)90 assert e.op == Op.RELATIONAL91 assert e == e92 assert e != f93 assert hash(e) is not None94 def test_tostring_fortran(self):95 x = as_symbol('x')96 y = as_symbol('y')97 z = as_symbol('z')98 n = as_number(123)99 m = as_number(456)100 a = as_array((n, m))101 c = as_complex(n, m)102 assert str(x) == 'x'103 assert str(n) == '123'104 assert str(a) == '[123, 456]'105 assert str(c) == '(123, 456)'106 assert str(Expr(Op.TERMS, {x: 1})) == 'x'107 assert str(Expr(Op.TERMS, {x: 2})) == '2 * x'108 assert str(Expr(Op.TERMS, {x: -1})) == '-x'109 assert str(Expr(Op.TERMS, {x: -2})) == '-2 * x'110 assert str(Expr(Op.TERMS, {x: 1, y: 1})) == 'x + y'111 assert str(Expr(Op.TERMS, {x: -1, y: -1})) == '-x - y'112 assert str(Expr(Op.TERMS, {x: 2, y: 3})) == '2 * x + 3 * y'113 assert str(Expr(Op.TERMS, {x: -2, y: 3})) == '-2 * x + 3 * y'114 assert str(Expr(Op.TERMS, {x: 2, y: -3})) == '2 * x - 3 * y'115 assert str(Expr(Op.FACTORS, {x: 1})) == 'x'116 assert str(Expr(Op.FACTORS, {x: 2})) == 'x ** 2'117 assert str(Expr(Op.FACTORS, {x: -1})) == 'x ** -1'118 assert str(Expr(Op.FACTORS, {x: -2})) == 'x ** -2'119 assert str(Expr(Op.FACTORS, {x: 1, y: 1})) == 'x * y'120 assert str(Expr(Op.FACTORS, {x: 2, y: 3})) == 'x ** 2 * y ** 3'121 v = Expr(Op.FACTORS, {x: 2, Expr(Op.TERMS, {x: 1, y: 1}): 3})122 assert str(v) == 'x ** 2 * (x + y) ** 3', str(v)123 v = Expr(Op.FACTORS, {x: 2, Expr(Op.FACTORS, {x: 1, y: 1}): 3})124 assert str(v) == 'x ** 2 * (x * y) ** 3', str(v)125 assert str(Expr(Op.APPLY, ('f', (), {}))) == 'f()'126 assert str(Expr(Op.APPLY, ('f', (x,), {}))) == 'f(x)'127 assert str(Expr(Op.APPLY, ('f', (x, y), {}))) == 'f(x, y)'128 assert str(Expr(Op.INDEXING, ('f', x))) == 'f[x]'129 assert str(as_ternary(x, y, z)) == 'merge(y, z, x)'130 assert str(as_eq(x, y)) == 'x .eq. y'131 assert str(as_ne(x, y)) == 'x .ne. y'132 assert str(as_lt(x, y)) == 'x .lt. y'133 assert str(as_le(x, y)) == 'x .le. y'134 assert str(as_gt(x, y)) == 'x .gt. y'135 assert str(as_ge(x, y)) == 'x .ge. y'136 def test_tostring_c(self):137 language = Language.C138 x = as_symbol('x')139 y = as_symbol('y')140 z = as_symbol('z')141 n = as_number(123)142 assert Expr(Op.FACTORS, {x: 2}).tostring(language=language) == 'x * x'143 assert Expr(Op.FACTORS, {x + y: 2}).tostring(144 language=language) == '(x + y) * (x + y)'145 assert Expr(Op.FACTORS, {x: 12}).tostring(146 language=language) == 'pow(x, 12)'147 assert as_apply(ArithOp.DIV, x, y).tostring(148 language=language) == 'x / y'149 assert as_apply(ArithOp.DIV, x, x + y).tostring(150 language=language) == 'x / (x + y)'151 assert as_apply(ArithOp.DIV, x - y, x + y).tostring(152 language=language) == '(x - y) / (x + y)'153 assert (x + (x - y) / (x + y) + n).tostring(154 language=language) == '123 + x + (x - y) / (x + y)'155 assert as_ternary(x, y, z).tostring(language=language) == "(x?y:z)"156 assert as_eq(x, y).tostring(language=language) == "x == y"157 assert as_ne(x, y).tostring(language=language) == "x != y"158 assert as_lt(x, y).tostring(language=language) == "x < y"159 assert as_le(x, y).tostring(language=language) == "x <= y"160 assert as_gt(x, y).tostring(language=language) == "x > y"161 assert as_ge(x, y).tostring(language=language) == "x >= y"162 def test_operations(self):163 x = as_symbol('x')164 y = as_symbol('y')165 z = as_symbol('z')166 assert x + x == Expr(Op.TERMS, {x: 2})167 assert x - x == Expr(Op.INTEGER, (0, 4))168 assert x + y == Expr(Op.TERMS, {x: 1, y: 1})169 assert x - y == Expr(Op.TERMS, {x: 1, y: -1})170 assert x * x == Expr(Op.FACTORS, {x: 2})171 assert x * y == Expr(Op.FACTORS, {x: 1, y: 1})172 assert +x == x173 assert -x == Expr(Op.TERMS, {x: -1}), repr(-x)174 assert 2 * x == Expr(Op.TERMS, {x: 2})175 assert 2 + x == Expr(Op.TERMS, {x: 1, as_number(1): 2})176 assert 2 * x + 3 * y == Expr(Op.TERMS, {x: 2, y: 3})177 assert (x + y) * 2 == Expr(Op.TERMS, {x: 2, y: 2})178 assert x ** 2 == Expr(Op.FACTORS, {x: 2})179 assert (x + y) ** 2 == Expr(Op.TERMS,180 {Expr(Op.FACTORS, {x: 2}): 1,181 Expr(Op.FACTORS, {y: 2}): 1,182 Expr(Op.FACTORS, {x: 1, y: 1}): 2})183 assert (x + y) * x == x ** 2 + x * y184 assert (x + y) ** 2 == x ** 2 + 2 * x * y + y ** 2185 assert (x + y) ** 2 + (x - y) ** 2 == 2 * x ** 2 + 2 * y ** 2186 assert (x + y) * z == x * z + y * z187 assert z * (x + y) == x * z + y * z188 assert (x / 2) == as_apply(ArithOp.DIV, x, as_number(2))189 assert (2 * x / 2) == x190 assert (3 * x / 2) == as_apply(ArithOp.DIV, 3*x, as_number(2))191 assert (4 * x / 2) == 2 * x192 assert (5 * x / 2) == as_apply(ArithOp.DIV, 5*x, as_number(2))193 assert (6 * x / 2) == 3 * x194 assert ((3*5) * x / 6) == as_apply(ArithOp.DIV, 5*x, as_number(2))195 assert (30*x**2*y**4 / (24*x**3*y**3)) == as_apply(ArithOp.DIV,196 5*y, 4*x)197 assert ((15 * x / 6) / 5) == as_apply(198 ArithOp.DIV, x, as_number(2)), ((15 * x / 6) / 5)199 assert (x / (5 / x)) == as_apply(ArithOp.DIV, x**2, as_number(5))200 assert (x / 2.0) == Expr(Op.TERMS, {x: 0.5})201 s = as_string('"ABC"')202 t = as_string('"123"')203 assert s // t == Expr(Op.STRING, ('"ABC123"', 1))204 assert s // x == Expr(Op.CONCAT, (s, x))205 assert x // s == Expr(Op.CONCAT, (x, s))206 c = as_complex(1., 2.)207 assert -c == as_complex(-1., -2.)208 assert c + c == as_expr((1+2j)*2)209 assert c * c == as_expr((1+2j)**2)210 def test_substitute(self):211 x = as_symbol('x')212 y = as_symbol('y')213 z = as_symbol('z')214 a = as_array((x, y))215 assert x.substitute({x: y}) == y216 assert (x + y).substitute({x: z}) == y + z217 assert (x * y).substitute({x: z}) == y * z218 assert (x ** 4).substitute({x: z}) == z ** 4219 assert (x / y).substitute({x: z}) == z / y220 assert x.substitute({x: y + z}) == y + z221 assert a.substitute({x: y + z}) == as_array((y + z, y))222 assert as_ternary(x, y, z).substitute(223 {x: y + z}) == as_ternary(y + z, y, z)224 assert as_eq(x, y).substitute(225 {x: y + z}) == as_eq(y + z, y)226 def test_fromstring(self):227 x = as_symbol('x')228 y = as_symbol('y')229 z = as_symbol('z')230 f = as_symbol('f')231 s = as_string('"ABC"')232 t = as_string('"123"')233 a = as_array((x, y))234 assert fromstring('x') == x235 assert fromstring('+ x') == x236 assert fromstring('- x') == -x237 assert fromstring('x + y') == x + y238 assert fromstring('x + 1') == x + 1239 assert fromstring('x * y') == x * y240 assert fromstring('x * 2') == x * 2241 assert fromstring('x / y') == x / y242 assert fromstring('x ** 2',243 language=Language.Python) == x ** 2244 assert fromstring('x ** 2 ** 3',245 language=Language.Python) == x ** 2 ** 3246 assert fromstring('(x + y) * z') == (x + y) * z247 assert fromstring('f(x)') == f(x)248 assert fromstring('f(x,y)') == f(x, y)249 assert fromstring('f[x]') == f[x]250 assert fromstring('f[x][y]') == f[x][y]251 assert fromstring('"ABC"') == s252 assert normalize(fromstring('"ABC" // "123" ',253 language=Language.Fortran)) == s // t254 assert fromstring('f("ABC")') == f(s)255 assert fromstring('MYSTRKIND_"ABC"') == as_string('"ABC"', 'MYSTRKIND')256 assert fromstring('(/x, y/)') == a, fromstring('(/x, y/)')257 assert fromstring('f((/x, y/))') == f(a)258 assert fromstring('(/(x+y)*z/)') == as_array(((x+y)*z,))259 assert fromstring('123') == as_number(123)260 assert fromstring('123_2') == as_number(123, 2)261 assert fromstring('123_myintkind') == as_number(123, 'myintkind')262 assert fromstring('123.0') == as_number(123.0, 4)263 assert fromstring('123.0_4') == as_number(123.0, 4)264 assert fromstring('123.0_8') == as_number(123.0, 8)265 assert fromstring('123.0e0') == as_number(123.0, 4)266 assert fromstring('123.0d0') == as_number(123.0, 8)267 assert fromstring('123d0') == as_number(123.0, 8)268 assert fromstring('123e-0') == as_number(123.0, 4)269 assert fromstring('123d+0') == as_number(123.0, 8)270 assert fromstring('123.0_myrealkind') == as_number(123.0, 'myrealkind')271 assert fromstring('3E4') == as_number(30000.0, 4)272 assert fromstring('(1, 2)') == as_complex(1, 2)273 assert fromstring('(1e2, PI)') == as_complex(274 as_number(100.0), as_symbol('PI'))275 assert fromstring('[1, 2]') == as_array((as_number(1), as_number(2)))276 assert fromstring('POINT(x, y=1)') == as_apply(277 as_symbol('POINT'), x, y=as_number(1))278 assert (fromstring('PERSON(name="John", age=50, shape=(/34, 23/))')279 == as_apply(as_symbol('PERSON'),280 name=as_string('"John"'),281 age=as_number(50),282 shape=as_array((as_number(34), as_number(23)))))283 assert fromstring('x?y:z') == as_ternary(x, y, z)284 assert fromstring('*x') == as_deref(x)285 assert fromstring('**x') == as_deref(as_deref(x))286 assert fromstring('&x') == as_ref(x)287 assert fromstring('(*x) * (*y)') == as_deref(x) * as_deref(y)288 assert fromstring('(*x) * *y') == as_deref(x) * as_deref(y)289 assert fromstring('*x * *y') == as_deref(x) * as_deref(y)290 assert fromstring('*x**y') == as_deref(x) * as_deref(y)291 assert fromstring('x == y') == as_eq(x, y)292 assert fromstring('x != y') == as_ne(x, y)293 assert fromstring('x < y') == as_lt(x, y)294 assert fromstring('x > y') == as_gt(x, y)295 assert fromstring('x <= y') == as_le(x, y)296 assert fromstring('x >= y') == as_ge(x, y)297 assert fromstring('x .eq. y', language=Language.Fortran) == as_eq(x, y)298 assert fromstring('x .ne. y', language=Language.Fortran) == as_ne(x, y)299 assert fromstring('x .lt. y', language=Language.Fortran) == as_lt(x, y)300 assert fromstring('x .gt. y', language=Language.Fortran) == as_gt(x, y)301 assert fromstring('x .le. y', language=Language.Fortran) == as_le(x, y)302 assert fromstring('x .ge. y', language=Language.Fortran) == as_ge(x, y)303 def test_traverse(self):304 x = as_symbol('x')305 y = as_symbol('y')306 z = as_symbol('z')307 f = as_symbol('f')308 # Use traverse to substitute a symbol309 def replace_visit(s, r=z):310 if s == x:311 return r312 assert x.traverse(replace_visit) == z313 assert y.traverse(replace_visit) == y314 assert z.traverse(replace_visit) == z315 assert (f(y)).traverse(replace_visit) == f(y)316 assert (f(x)).traverse(replace_visit) == f(z)317 assert (f[y]).traverse(replace_visit) == f[y]318 assert (f[z]).traverse(replace_visit) == f[z]319 assert (x + y + z).traverse(replace_visit) == (2 * z + y)320 assert (x + f(y, x - z)).traverse(321 replace_visit) == (z + f(y, as_number(0)))322 assert as_eq(x, y).traverse(replace_visit) == as_eq(z, y)323 # Use traverse to collect symbols, method 1324 function_symbols = set()325 symbols = set()326 def collect_symbols(s):327 if s.op is Op.APPLY:328 oper = s.data[0]329 function_symbols.add(oper)330 if oper in symbols:331 symbols.remove(oper)332 elif s.op is Op.SYMBOL and s not in function_symbols:333 symbols.add(s)334 (x + f(y, x - z)).traverse(collect_symbols)335 assert function_symbols == {f}336 assert symbols == {x, y, z}337 # Use traverse to collect symbols, method 2338 def collect_symbols2(expr, symbols):339 if expr.op is Op.SYMBOL:340 symbols.add(expr)341 symbols = set()342 (x + f(y, x - z)).traverse(collect_symbols2, symbols)343 assert symbols == {x, y, z, f}344 # Use traverse to partially collect symbols345 def collect_symbols3(expr, symbols):346 if expr.op is Op.APPLY:347 # skip traversing function calls348 return expr349 if expr.op is Op.SYMBOL:350 symbols.add(expr)351 symbols = set()352 (x + f(y, x - z)).traverse(collect_symbols3, symbols)353 assert symbols == {x}354 def test_linear_solve(self):355 x = as_symbol('x')356 y = as_symbol('y')357 z = as_symbol('z')358 assert x.linear_solve(x) == (as_number(1), as_number(0))359 assert (x+1).linear_solve(x) == (as_number(1), as_number(1))360 assert (2*x).linear_solve(x) == (as_number(2), as_number(0))361 assert (2*x+3).linear_solve(x) == (as_number(2), as_number(3))362 assert as_number(3).linear_solve(x) == (as_number(0), as_number(3))363 assert y.linear_solve(x) == (as_number(0), y)364 assert (y*z).linear_solve(x) == (as_number(0), y * z)365 assert (x+y).linear_solve(x) == (as_number(1), y)366 assert (z*x+y).linear_solve(x) == (z, y)367 assert ((z+y)*x+y).linear_solve(x) == (z + y, y)368 assert (z*y*x+y).linear_solve(x) == (z * y, y)369 assert_raises(RuntimeError, lambda: (x*x).linear_solve(x))370 def test_as_numer_denom(self):371 x = as_symbol('x')372 y = as_symbol('y')373 n = as_number(123)374 assert as_numer_denom(x) == (x, as_number(1))375 assert as_numer_denom(x / n) == (x, n)376 assert as_numer_denom(n / x) == (n, x)377 assert as_numer_denom(x / y) == (x, y)378 assert as_numer_denom(x * y) == (x * y, as_number(1))379 assert as_numer_denom(n + x / y) == (x + n * y, y)380 assert as_numer_denom(n + x / (y - x / n)) == (y * n ** 2, y * n - x)381 def test_polynomial_atoms(self):382 x = as_symbol('x')383 y = as_symbol('y')384 n = as_number(123)385 assert x.polynomial_atoms() == {x}386 assert n.polynomial_atoms() == set()387 assert (y[x]).polynomial_atoms() == {y[x]}388 assert (y(x)).polynomial_atoms() == {y(x)}389 assert (y(x) + x).polynomial_atoms() == {y(x), x}390 assert (y(x) * x[y]).polynomial_atoms() == {y(x), x[y]}...

Full Screen

Full Screen

test_graph_duplicates.py

Source:test_graph_duplicates.py Github

copy

Full Screen

1import xml.etree.ElementTree as ET2from test.parser.pattern.base import PatternTestBaseClass3from programy.parser.exceptions import DuplicateGrammarException4from programy.parser.pattern.graph import PatternGraph5from programy.parser.template.nodes.base import TemplateNode6from programy.parser.pattern.nodes.bot import PatternBotNode7from programy.parser.pattern.nodes.word import PatternWordNode8class PatternGraphDuplicateTests(PatternTestBaseClass):9 def test_duplicate_pattern(self):10 graph = PatternGraph()11 pattern_element = ET.fromstring("<pattern>A # *</pattern>")12 topic_element = ET.fromstring("<topic>*</topic>")13 that_element = ET.fromstring("<that>*</that>")14 template_node = TemplateNode()15 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)16 pattern_element = ET.fromstring("<pattern>A # *</pattern>")17 topic_element = ET.fromstring("<topic>*</topic>")18 that_element = ET.fromstring("<that>*</that>")19 template_node = TemplateNode()20 with self.assertRaises(DuplicateGrammarException):21 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)22 def test_duplicate_pattern_same_topics(self):23 graph = PatternGraph()24 pattern_element = ET.fromstring("<pattern>A # *</pattern>")25 topic_element = ET.fromstring("<topic>X Y</topic>")26 that_element = ET.fromstring("<that>*</that>")27 template_node = TemplateNode()28 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)29 pattern_element = ET.fromstring("<pattern>A # *</pattern>")30 topic_element = ET.fromstring("<topic>X Y</topic>")31 that_element = ET.fromstring("<that>*</that>")32 template_node = TemplateNode()33 with self.assertRaises(DuplicateGrammarException):34 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)35 def test_duplicate_pattern_same_thats(self):36 graph = PatternGraph()37 pattern_element = ET.fromstring("<pattern>A # *</pattern>")38 topic_element = ET.fromstring("<topic>*</topic>")39 that_element = ET.fromstring("<that>X Y</that>")40 template_node = TemplateNode()41 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)42 pattern_element = ET.fromstring("<pattern>A # *</pattern>")43 topic_element = ET.fromstring("<topic>*</topic>")44 that_element = ET.fromstring("<that>X Y</that>")45 template_node = TemplateNode()46 with self.assertRaises(DuplicateGrammarException):47 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)48 def test_duplicate_pattern_different_topics(self):49 graph = PatternGraph()50 pattern_element = ET.fromstring("<pattern>A # *</pattern>")51 topic_element = ET.fromstring("<topic>A B</topic>")52 that_element = ET.fromstring("<that>*</that>")53 template_node = TemplateNode()54 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)55 pattern_element = ET.fromstring("<pattern>A # *</pattern>")56 topic_element = ET.fromstring("<topic>X Y</topic>")57 that_element = ET.fromstring("<that>*</that>")58 template_node = TemplateNode()59 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)60 def test_duplicate_pattern_different_thats(self):61 graph = PatternGraph()62 pattern_element = ET.fromstring("<pattern>A # *</pattern>")63 topic_element = ET.fromstring("<topic>*</topic>")64 that_element = ET.fromstring("<that>A B</that>")65 template_node = TemplateNode()66 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)67 pattern_element = ET.fromstring("<pattern>A # *</pattern>")68 topic_element = ET.fromstring("<topic>*</topic>")69 that_element = ET.fromstring("<that>X Y</that>")70 template_node = TemplateNode()71 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)72 def test_duplicate_priority(self):73 graph = PatternGraph()74 pattern_element = ET.fromstring("<pattern>$A</pattern>")75 topic_element = ET.fromstring("<topic>*</topic>")76 that_element = ET.fromstring("<that>*</that>")77 template_node = TemplateNode()78 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)79 pattern_element = ET.fromstring("<pattern>$A</pattern>")80 topic_element = ET.fromstring("<topic>*</topic>")81 that_element = ET.fromstring("<that>*</that>")82 template_node = TemplateNode()83 with self.assertRaises(DuplicateGrammarException):84 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)85 def test_duplicate_priority_and_word(self):86 graph = PatternGraph()87 pattern_element = ET.fromstring("<pattern>A</pattern>")88 topic_element = ET.fromstring("<topic>*</topic>")89 that_element = ET.fromstring("<that>*</that>")90 template_node = TemplateNode()91 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)92 pattern_element = ET.fromstring("<pattern>$A</pattern>")93 topic_element = ET.fromstring("<topic>*</topic>")94 that_element = ET.fromstring("<that>*</that>")95 template_node = TemplateNode()96 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)97 def test_duplicate_priority_and_word_otherwayround(self):98 graph = PatternGraph()99 pattern_element = ET.fromstring("<pattern>$A</pattern>")100 topic_element = ET.fromstring("<topic>*</topic>")101 that_element = ET.fromstring("<that>*</that>")102 template_node = TemplateNode()103 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)104 pattern_element = ET.fromstring("<pattern>A</pattern>")105 topic_element = ET.fromstring("<topic>*</topic>")106 that_element = ET.fromstring("<that>*</that>")107 template_node = TemplateNode()108 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)109 def test_duplicate_set(self):110 graph = PatternGraph()111 pattern_element = ET.fromstring("<pattern><set>A</set></pattern>")112 topic_element = ET.fromstring("<topic>*</topic>")113 that_element = ET.fromstring("<that>*</that>")114 template_node = TemplateNode()115 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)116 pattern_element = ET.fromstring("<pattern><set>A</set></pattern>")117 topic_element = ET.fromstring("<topic>*</topic>")118 that_element = ET.fromstring("<that>*</that>")119 template_node = TemplateNode()120 with self.assertRaises(DuplicateGrammarException):121 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)122 def test_duplicate_set_and_word(self):123 graph = PatternGraph()124 pattern_element = ET.fromstring("<pattern>A</pattern>")125 topic_element = ET.fromstring("<topic>*</topic>")126 that_element = ET.fromstring("<that>*</that>")127 template_node = TemplateNode()128 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)129 pattern_element = ET.fromstring("<pattern><set>A</set></pattern>")130 topic_element = ET.fromstring("<topic>*</topic>")131 that_element = ET.fromstring("<that>*</that>")132 template_node = TemplateNode()133 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)134 def test_duplicate_set_and_word_otherwayround(self):135 graph = PatternGraph()136 pattern_element = ET.fromstring("<pattern><set>A</set></pattern>")137 topic_element = ET.fromstring("<topic>*</topic>")138 that_element = ET.fromstring("<that>*</that>")139 template_node = TemplateNode()140 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)141 pattern_element = ET.fromstring("<pattern>A</pattern>")142 topic_element = ET.fromstring("<topic>*</topic>")143 that_element = ET.fromstring("<that>*</that>")144 template_node = TemplateNode()145 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)146 def test_duplicate_bot(self):147 graph = PatternGraph()148 pattern_element = ET.fromstring("<pattern><bot>A</bot></pattern>")149 topic_element = ET.fromstring("<topic>*</topic>")150 that_element = ET.fromstring("<that>*</that>")151 template_node = TemplateNode()152 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)153 pattern_element = ET.fromstring("<pattern><bot>A</bot></pattern>")154 topic_element = ET.fromstring("<topic>*</topic>")155 that_element = ET.fromstring("<that>*</that>")156 template_node = TemplateNode()157 with self.assertRaises(DuplicateGrammarException):158 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)159 def test_duplicate_bot_and_word(self):160 graph = PatternGraph()161 pattern_element = ET.fromstring("<pattern>A</pattern>")162 topic_element = ET.fromstring("<topic>*</topic>")163 that_element = ET.fromstring("<that>*</that>")164 template_node = TemplateNode()165 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)166 pattern_element = ET.fromstring("<pattern><bot>A</bot></pattern>")167 topic_element = ET.fromstring("<topic>*</topic>")168 that_element = ET.fromstring("<that>*</that>")169 template_node = TemplateNode()170 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)171 def test_duplicate_bot_and_word_otherwayround(self):172 graph = PatternGraph()173 pattern_element = ET.fromstring("<pattern><bot>A</bot></pattern>")174 topic_element = ET.fromstring("<topic>*</topic>")175 that_element = ET.fromstring("<that>*</that>")176 template_node = TemplateNode()177 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)178 pattern_element = ET.fromstring("<pattern>A</pattern>")179 topic_element = ET.fromstring("<topic>*</topic>")180 that_element = ET.fromstring("<that>*</that>")181 template_node = TemplateNode()182 graph.add_pattern_to_graph(pattern_element, topic_element, that_element, template_node)183 self.assertIsNotNone(graph.root.children)184 self.assertEqual(2, len(graph.root.children))185 self.assertIsInstance(graph.root.children[0], PatternWordNode)186 self.assertIsInstance(graph.root.children[1], PatternBotNode)187 self.assertEqual(1, len(graph.root._bot_properties))188 values = graph.root._bot_properties.values()...

Full Screen

Full Screen

unittest_custom_options_pb2.pyi

Source:unittest_custom_options_pb2.pyi Github

copy

Full Screen

1from google.protobuf.descriptor_pb2 import (2 FileOptions,3)4from google.protobuf.internal.containers import (5 RepeatedCompositeFieldContainer,6 RepeatedScalarFieldContainer,7)8from google.protobuf.message import (9 Message,10)11from typing import (12 Iterable,13 List,14 Optional,15 Text,16 Tuple,17 cast,18)19class MethodOpt1(int):20 @classmethod21 def Name(cls, number: int) -> str: ...22 @classmethod23 def Value(cls, name: str) -> MethodOpt1: ...24 @classmethod25 def keys(cls) -> List[str]: ...26 @classmethod27 def values(cls) -> List[MethodOpt1]: ...28 @classmethod29 def items(cls) -> List[Tuple[str, MethodOpt1]]: ...30METHODOPT1_VAL1: MethodOpt131METHODOPT1_VAL2: MethodOpt132class AggregateEnum(int):33 @classmethod34 def Name(cls, number: int) -> str: ...35 @classmethod36 def Value(cls, name: str) -> AggregateEnum: ...37 @classmethod38 def keys(cls) -> List[str]: ...39 @classmethod40 def values(cls) -> List[AggregateEnum]: ...41 @classmethod42 def items(cls) -> List[Tuple[str, AggregateEnum]]: ...43VALUE: AggregateEnum44class TestMessageWithCustomOptions(Message):45 class AnEnum(int):46 @classmethod47 def Name(cls, number: int) -> str: ...48 @classmethod49 def Value(cls, name: str) -> TestMessageWithCustomOptions.AnEnum: ...50 @classmethod51 def keys(cls) -> List[str]: ...52 @classmethod53 def values(cls) -> List[TestMessageWithCustomOptions.AnEnum]: ...54 @classmethod55 def items(cls) -> List[Tuple[str,56 TestMessageWithCustomOptions.AnEnum]]: ...57 ANENUM_VAL1: AnEnum58 ANENUM_VAL2: AnEnum59 field1 = ... # type: Text60 oneof_field = ... # type: int61 def __init__(self,62 field1: Optional[Text] = ...,63 oneof_field: Optional[int] = ...,64 ) -> None: ...65 @classmethod66 def FromString(cls, s: str) -> TestMessageWithCustomOptions: ...67class CustomOptionFooRequest(Message):68 def __init__(self,69 ) -> None: ...70 @classmethod71 def FromString(cls, s: str) -> CustomOptionFooRequest: ...72class CustomOptionFooResponse(Message):73 def __init__(self,74 ) -> None: ...75 @classmethod76 def FromString(cls, s: str) -> CustomOptionFooResponse: ...77class CustomOptionFooClientMessage(Message):78 def __init__(self,79 ) -> None: ...80 @classmethod81 def FromString(cls, s: str) -> CustomOptionFooClientMessage: ...82class CustomOptionFooServerMessage(Message):83 def __init__(self,84 ) -> None: ...85 @classmethod86 def FromString(cls, s: str) -> CustomOptionFooServerMessage: ...87class DummyMessageContainingEnum(Message):88 class TestEnumType(int):89 @classmethod90 def Name(cls, number: int) -> str: ...91 @classmethod92 def Value(cls, name: str) -> DummyMessageContainingEnum.TestEnumType: ...93 @classmethod94 def keys(cls) -> List[str]: ...95 @classmethod96 def values(cls) -> List[DummyMessageContainingEnum.TestEnumType]: ...97 @classmethod98 def items(cls) -> List[Tuple[str,99 DummyMessageContainingEnum.TestEnumType]]: ...100 TEST_OPTION_ENUM_TYPE1: TestEnumType101 TEST_OPTION_ENUM_TYPE2: TestEnumType102 def __init__(self,103 ) -> None: ...104 @classmethod105 def FromString(cls, s: str) -> DummyMessageContainingEnum: ...106class DummyMessageInvalidAsOptionType(Message):107 def __init__(self,108 ) -> None: ...109 @classmethod110 def FromString(cls, s: str) -> DummyMessageInvalidAsOptionType: ...111class CustomOptionMinIntegerValues(Message):112 def __init__(self,113 ) -> None: ...114 @classmethod115 def FromString(cls, s: str) -> CustomOptionMinIntegerValues: ...116class CustomOptionMaxIntegerValues(Message):117 def __init__(self,118 ) -> None: ...119 @classmethod120 def FromString(cls, s: str) -> CustomOptionMaxIntegerValues: ...121class CustomOptionOtherValues(Message):122 def __init__(self,123 ) -> None: ...124 @classmethod125 def FromString(cls, s: str) -> CustomOptionOtherValues: ...126class SettingRealsFromPositiveInts(Message):127 def __init__(self,128 ) -> None: ...129 @classmethod130 def FromString(cls, s: str) -> SettingRealsFromPositiveInts: ...131class SettingRealsFromNegativeInts(Message):132 def __init__(self,133 ) -> None: ...134 @classmethod135 def FromString(cls, s: str) -> SettingRealsFromNegativeInts: ...136class ComplexOptionType1(Message):137 foo = ... # type: int138 foo2 = ... # type: int139 foo3 = ... # type: int140 foo4 = ... # type: RepeatedScalarFieldContainer[int]141 def __init__(self,142 foo: Optional[int] = ...,143 foo2: Optional[int] = ...,144 foo3: Optional[int] = ...,145 foo4: Optional[Iterable[int]] = ...,146 ) -> None: ...147 @classmethod148 def FromString(cls, s: str) -> ComplexOptionType1: ...149class ComplexOptionType2(Message):150 class ComplexOptionType4(Message):151 waldo = ... # type: int152 def __init__(self,153 waldo: Optional[int] = ...,154 ) -> None: ...155 @classmethod156 def FromString(157 cls, s: str) -> ComplexOptionType2.ComplexOptionType4: ...158 baz = ... # type: int159 @property160 def bar(self) -> ComplexOptionType1: ...161 @property162 def fred(self) -> ComplexOptionType2.ComplexOptionType4: ...163 @property164 def barney(165 self) -> RepeatedCompositeFieldContainer[ComplexOptionType2.ComplexOptionType4]: ...166 def __init__(self,167 bar: Optional[ComplexOptionType1] = ...,168 baz: Optional[int] = ...,169 fred: Optional[ComplexOptionType2.ComplexOptionType4] = ...,170 barney: Optional[Iterable[ComplexOptionType2.ComplexOptionType4]] = ...,171 ) -> None: ...172 @classmethod173 def FromString(cls, s: str) -> ComplexOptionType2: ...174class ComplexOptionType3(Message):175 class ComplexOptionType5(Message):176 plugh = ... # type: int177 def __init__(self,178 plugh: Optional[int] = ...,179 ) -> None: ...180 @classmethod181 def FromString(182 cls, s: str) -> ComplexOptionType3.ComplexOptionType5: ...183 qux = ... # type: int184 @property185 def complexoptiontype5(self) -> ComplexOptionType3.ComplexOptionType5: ...186 def __init__(self,187 qux: Optional[int] = ...,188 complexoptiontype5: Optional[ComplexOptionType3.ComplexOptionType5] = ...,189 ) -> None: ...190 @classmethod191 def FromString(cls, s: str) -> ComplexOptionType3: ...192class ComplexOpt6(Message):193 xyzzy = ... # type: int194 def __init__(self,195 xyzzy: Optional[int] = ...,196 ) -> None: ...197 @classmethod198 def FromString(cls, s: str) -> ComplexOpt6: ...199class VariousComplexOptions(Message):200 def __init__(self,201 ) -> None: ...202 @classmethod203 def FromString(cls, s: str) -> VariousComplexOptions: ...204class AggregateMessageSet(Message):205 def __init__(self,206 ) -> None: ...207 @classmethod208 def FromString(cls, s: str) -> AggregateMessageSet: ...209class AggregateMessageSetElement(Message):210 s = ... # type: Text211 def __init__(self,212 s: Optional[Text] = ...,213 ) -> None: ...214 @classmethod215 def FromString(cls, s: str) -> AggregateMessageSetElement: ...216class Aggregate(Message):217 i = ... # type: int218 s = ... # type: Text219 @property220 def sub(self) -> Aggregate: ...221 @property222 def file(self) -> FileOptions: ...223 @property224 def mset(self) -> AggregateMessageSet: ...225 def __init__(self,226 i: Optional[int] = ...,227 s: Optional[Text] = ...,228 sub: Optional[Aggregate] = ...,229 file: Optional[FileOptions] = ...,230 mset: Optional[AggregateMessageSet] = ...,231 ) -> None: ...232 @classmethod233 def FromString(cls, s: str) -> Aggregate: ...234class AggregateMessage(Message):235 fieldname = ... # type: int236 def __init__(self,237 fieldname: Optional[int] = ...,238 ) -> None: ...239 @classmethod240 def FromString(cls, s: str) -> AggregateMessage: ...241class NestedOptionType(Message):242 class NestedEnum(int):243 @classmethod244 def Name(cls, number: int) -> str: ...245 @classmethod246 def Value(cls, name: str) -> NestedOptionType.NestedEnum: ...247 @classmethod248 def keys(cls) -> List[str]: ...249 @classmethod250 def values(cls) -> List[NestedOptionType.NestedEnum]: ...251 @classmethod252 def items(cls) -> List[Tuple[str, NestedOptionType.NestedEnum]]: ...253 NESTED_ENUM_VALUE: NestedEnum254 class NestedMessage(Message):255 nested_field = ... # type: int256 def __init__(self,257 nested_field: Optional[int] = ...,258 ) -> None: ...259 @classmethod260 def FromString(cls, s: str) -> NestedOptionType.NestedMessage: ...261 def __init__(self,262 ) -> None: ...263 @classmethod264 def FromString(cls, s: str) -> NestedOptionType: ...265class OldOptionType(Message):266 class TestEnum(int):267 @classmethod268 def Name(cls, number: int) -> str: ...269 @classmethod270 def Value(cls, name: str) -> OldOptionType.TestEnum: ...271 @classmethod272 def keys(cls) -> List[str]: ...273 @classmethod274 def values(cls) -> List[OldOptionType.TestEnum]: ...275 @classmethod276 def items(cls) -> List[Tuple[str, OldOptionType.TestEnum]]: ...277 OLD_VALUE: TestEnum278 value = ... # type: OldOptionType.TestEnum279 def __init__(self,280 value: OldOptionType.TestEnum,281 ) -> None: ...282 @classmethod283 def FromString(cls, s: str) -> OldOptionType: ...284class NewOptionType(Message):285 class TestEnum(int):286 @classmethod287 def Name(cls, number: int) -> str: ...288 @classmethod289 def Value(cls, name: str) -> NewOptionType.TestEnum: ...290 @classmethod291 def keys(cls) -> List[str]: ...292 @classmethod293 def values(cls) -> List[NewOptionType.TestEnum]: ...294 @classmethod295 def items(cls) -> List[Tuple[str, NewOptionType.TestEnum]]: ...296 OLD_VALUE: TestEnum297 NEW_VALUE: TestEnum298 value = ... # type: NewOptionType.TestEnum299 def __init__(self,300 value: NewOptionType.TestEnum,301 ) -> None: ...302 @classmethod303 def FromString(cls, s: str) -> NewOptionType: ...304class TestMessageWithRequiredEnumOption(Message):305 def __init__(self,306 ) -> None: ...307 @classmethod...

Full Screen

Full Screen

test_datastream.py

Source:test_datastream.py Github

copy

Full Screen

1"""Tests for DataStream objects."""2import pytest3from iotile.core.exceptions import InternalError4from iotile.sg import DataStream, DataStreamSelector5def test_stream_type_parsing():6 """Make sure we can parse each type of stream."""7 # Make sure parsing stream type works8 stream = DataStream.FromString('buffered 1')9 assert stream.stream_type == stream.BufferedType10 stream = DataStream.FromString(u'buffered 1')11 assert stream.stream_type == stream.BufferedType12 stream = DataStream.FromString('unbuffered 1')13 assert stream.stream_type == stream.UnbufferedType14 stream = DataStream.FromString(u'unbuffered 1')15 assert stream.stream_type == stream.UnbufferedType16 stream = DataStream.FromString('counter 1')17 assert stream.stream_type == stream.CounterType18 stream = DataStream.FromString(u'counter 1')19 assert stream.stream_type == stream.CounterType20 stream = DataStream.FromString('constant 1')21 assert stream.stream_type == stream.ConstantType22 stream = DataStream.FromString(u'constant 1')23 assert stream.stream_type == stream.ConstantType24 stream = DataStream.FromString('output 1')25 assert stream.stream_type == stream.OutputType26 stream = DataStream.FromString(u'output 1')27 assert stream.stream_type == stream.OutputType28def test_stream_id_parsing():29 """Make sure we can parse stream ids."""30 stream = DataStream.FromString('buffered 1')31 assert stream.stream_id == 132 stream = DataStream.FromString('buffered 0x100')33 assert stream.stream_id == 0x10034 stream = DataStream.FromString(u'buffered 1')35 assert stream.stream_id == 136 stream = DataStream.FromString(u'buffered 0x100')37 assert stream.stream_id == 0x10038def test_system_parsing():39 """Make sure we can parse the system prefix."""40 stream = DataStream.FromString('buffered 1')41 assert stream.system is False42 stream = DataStream.FromString(u'buffered 1')43 assert stream.system is False44 stream = DataStream.FromString('system buffered 1')45 assert stream.system is True46 stream = DataStream.FromString(u'system buffered 1')47 assert stream.system is True48def test_stringification():49 """Make sure we can stringify DataStream objects."""50 stream1 = DataStream.FromString('system buffered 1')51 stream2 = DataStream.FromString('buffered 0xF')52 assert str(stream1) == str('system buffered 1')53 assert str(stream2) == str('buffered 15')54def test_selector_parsing():55 """Make sure we can parse DataStreamSelector strings."""56 # Make sure parsing stream type works57 stream = DataStreamSelector.FromString('buffered 1')58 assert stream.match_type == DataStream.BufferedType59 stream = DataStreamSelector.FromString(u'buffered 1')60 assert stream.match_type == DataStream.BufferedType61 stream = DataStreamSelector.FromString('unbuffered 1')62 assert stream.match_type == DataStream.UnbufferedType63 stream = DataStreamSelector.FromString(u'unbuffered 1')64 assert stream.match_type == DataStream.UnbufferedType65 stream = DataStreamSelector.FromString('counter 1')66 assert stream.match_type == DataStream.CounterType67 stream = DataStreamSelector.FromString(u'counter 1')68 assert stream.match_type == DataStream.CounterType69 stream = DataStreamSelector.FromString('constant 1')70 assert stream.match_type == DataStream.ConstantType71 stream = DataStreamSelector.FromString(u'constant 1')72 assert stream.match_type == DataStream.ConstantType73 stream = DataStreamSelector.FromString('output 1')74 assert stream.match_type == DataStream.OutputType75 stream = DataStreamSelector.FromString(u'output 1')76 assert stream.match_type == DataStream.OutputType77def test_stream_selector_id_parsing():78 """Make sure we can parse stream ids."""79 stream = DataStreamSelector.FromString('buffered 1')80 assert stream.match_id == 181 assert stream.match_spec == DataStreamSelector.MatchUserOnly82 stream = DataStreamSelector.FromString('buffered 0x100')83 assert stream.match_id == 0x10084 assert stream.match_spec == DataStreamSelector.MatchUserOnly85 stream = DataStreamSelector.FromString(u'buffered 1')86 assert stream.match_id == 187 assert stream.match_spec == DataStreamSelector.MatchUserOnly88 stream = DataStreamSelector.FromString(u'buffered 0x100')89 assert stream.match_id == 0x10090 assert stream.match_spec == DataStreamSelector.MatchUserOnly91 stream = DataStreamSelector.FromString(u'system buffered 0x100')92 assert stream.match_id == 0x10093 assert stream.match_spec == DataStreamSelector.MatchSystemOnly94 stream = DataStreamSelector.FromString(u'all buffered')95 assert stream.match_id is None96 assert stream.match_spec == DataStreamSelector.MatchUserAndBreaks97 stream = DataStreamSelector.FromString(u'all user buffered')98 assert stream.match_id is None99 assert stream.match_spec == DataStreamSelector.MatchUserOnly100 stream = DataStreamSelector.FromString(u'all combined buffered')101 assert stream.match_id is None102 assert stream.match_spec == DataStreamSelector.MatchCombined103 stream = DataStreamSelector.FromString(u'all system buffered')104 assert stream.match_id is None105 assert stream.match_spec == DataStreamSelector.MatchSystemOnly106def test_matching():107 """Test selector stream matching."""108 sel = DataStreamSelector.FromString(u'all system buffered')109 assert sel.matches(DataStream.FromString('system buffered 1'))110 assert not sel.matches(DataStream.FromString('buffered 1'))111 assert not sel.matches(DataStream.FromString('counter 1'))112 sel = DataStreamSelector.FromString(u'all user outputs')113 assert sel.matches(DataStream.FromString('output 1'))114 assert not sel.matches(DataStream.FromString('system output 1'))115 assert not sel.matches(DataStream.FromString('counter 1'))116 sel = DataStreamSelector.FromString(u'all combined outputs')117 assert sel.matches(DataStream.FromString('output 1'))118 assert sel.matches(DataStream.FromString('system output 1'))119 assert not sel.matches(DataStream.FromString('counter 1'))120 sel = DataStreamSelector.FromString(u'all outputs')121 assert sel.matches(DataStream.FromString('output 1'))122 assert sel.matches(DataStream.FromString('system output 1024'))123 assert not sel.matches(DataStream.FromString('system output 1'))124 assert not sel.matches(DataStream.FromString('counter 1'))125def test_encoding():126 """Test data stream and selector encoding."""127 sel = DataStreamSelector.FromString(u'all system output')128 assert sel.encode() == 0x5FFF129 sel = DataStreamSelector.FromString(u'all user output')130 assert sel.encode() == 0x57FF131 sel = DataStreamSelector.FromString(u'all output')132 assert sel.encode() == 0xD7FF133 sel = DataStreamSelector.FromString(u'all combined output')134 assert sel.encode() == 0xDFFF135 stream = DataStream.FromString('output 1')136 assert stream.encode() == 0x5001137 stream = DataStream.FromString('unbuffered 10')138 assert stream.encode() == 0x100a139def test_selector_from_encoded():140 """Make sure we can create a selector from an encoded value."""141 sel = DataStreamSelector.FromEncoded(0x5FFF)142 assert str(sel) == 'all system outputs'143 sel = DataStreamSelector.FromEncoded(0xD7FF)144 assert str(sel) == 'all outputs'145 sel = DataStreamSelector.FromEncoded(0x100a)146 assert str(sel) == 'unbuffered 10'147 assert str(DataStreamSelector.FromEncoded(DataStreamSelector.FromString('all combined output').encode())) == 'all combined outputs'148def test_buffered_pluralization():149 """Make sure we don't incorrectly pluralize buffered streams."""150 sel = DataStreamSelector.FromString('all buffered')151 assert str(sel) == 'all buffered'152def test_important_inputs():153 """Make sure we support matching important inputs and outputs."""154 imp_stream = DataStream.FromString('system input 1024')155 imp_store_stream = DataStream.FromString('system input 1536')156 assert imp_stream.important is True157 assert imp_store_stream.important is True158 assert imp_stream.associated_stream() == DataStream.FromString('system output 1024')159 assert imp_store_stream.associated_stream() == DataStream.FromString('system buffered 1536')160 random_stream = DataStream.FromString('unbuffered 1024')161 assert random_stream.important is False162 with pytest.raises(InternalError):...

Full Screen

Full Screen

test_semver.py

Source:test_semver.py Github

copy

Full Screen

1"""Tests of SemanticVersion."""2import pkg_resources3from iotile.core.dev.semver import SemanticVersion4from iotile.core.exceptions import DataError5import pytest6def test_basic_parsing():7 ver1 = SemanticVersion.FromString('1.2.3')8 assert ver1.major == 1 and ver1.minor == 2 and ver1.patch == 39 assert ver1.release_type == 'release'10 assert ver1.is_release is True11 assert ver1.is_prerelease is False12def test_prerelease_parsing():13 reltype, relnum = SemanticVersion.ParsePrerelease('alpha1')14 assert reltype == 'alpha'15 assert relnum == 116 reltype, relnum = SemanticVersion.ParsePrerelease('beta10')17 assert reltype == 'beta'18 assert relnum == 1019 reltype, relnum = SemanticVersion.ParsePrerelease('rc20')20 assert reltype == 'rc'21 assert relnum == 2022 reltype, relnum = SemanticVersion.ParsePrerelease('build30')23 assert reltype == 'build'24 assert relnum == 3025 with pytest.raises(DataError):26 SemanticVersion.ParsePrerelease('30')27 with pytest.raises(DataError):28 SemanticVersion.ParsePrerelease('build')29 with pytest.raises(DataError):30 SemanticVersion.ParsePrerelease('unknown5')31 with pytest.raises(DataError):32 SemanticVersion.ParsePrerelease('unknown')33 with pytest.raises(DataError):34 SemanticVersion.ParsePrerelease('')35def test_advanced_parsing():36 ver = SemanticVersion.FromString('0.1.2-alpha2')37 assert ver.major == 038 assert ver.minor == 139 assert ver.patch == 240 assert ver.is_prerelease is True41 assert ver.release_type == 'alpha'42 assert ver.prerelease_number == 243def test_equality():44 ver1 = SemanticVersion.FromString('0.1.2-alpha2')45 ver2 = SemanticVersion.FromString('0.1.2-alpha2')46 assert ver1 == ver247 assert not ver1 < ver248def test_ordering_release_over_pre():49 ver1 = SemanticVersion.FromString('0.1.2')50 ver2 = SemanticVersion.FromString('0.1.2-rc1')51 assert ver2 < ver152 assert ver1 > ver253def test_ordering_prereleases():54 build = SemanticVersion.FromString('0.1.2-build10')55 alpha = SemanticVersion.FromString('0.1.2-alpha9')56 beta = SemanticVersion.FromString('0.1.2-beta8')57 rc = SemanticVersion.FromString('0.1.2-rc7')58 bump = SemanticVersion.FromString('0.1.3-build1')59 assert build < alpha < beta < rc < bump60def test_ordering_releases():61 major = SemanticVersion.FromString('1.0.0')62 minor = SemanticVersion.FromString('0.9.0')63 patch = SemanticVersion.FromString('0.8.9')64 assert patch < minor < major65def test_formatting():66 ver = SemanticVersion.FromString('0.1.2-alpha2')67 assert str(ver) == '0.1.2-alpha2'68 ver = SemanticVersion.FromString('1.142.2123')69 assert str(ver) == '1.142.2123'70def test_hash():71 """Make sure hashing SemanticVersions works72 """73 ver = SemanticVersion.FromString('0.1.2-alpha2')74 ver2 = SemanticVersion.FromString('0.1.2-alpha2')75 ver3 = SemanticVersion.FromString('0.2.2')76 assert hash(ver) == hash(ver2)77 assert hash(ver3) != hash(ver)78 assert ver == ver279 assert ver != ver380 version_set = set([ver, ver2, ver3])81 assert len(version_set) == 282def test_inc_nonzero():83 """Make sure incrementing the first nonzero release component works84 """85 ver = SemanticVersion.FromString('0.0.1')86 assert str(ver.inc_first_nonzero()) == '0.0.2'87 ver = SemanticVersion.FromString('0.0.1-rc2')88 assert str(ver.inc_first_nonzero()) == '0.0.2'89 ver = SemanticVersion.FromString('0.1.2')90 assert str(ver.inc_first_nonzero()) == '0.2.0'91 ver = SemanticVersion.FromString('1.2.3')92 assert str(ver.inc_first_nonzero()) == '2.0.0'93def test_inc_patch():94 ver = SemanticVersion.FromString('0.0.1')95 assert str(ver.inc_release()) == '0.0.2'96 ver = SemanticVersion.FromString('0.0.1-rc2')97 assert str(ver.inc_release()) == '0.0.2'98 ver = SemanticVersion.FromString('0.1.2')99 assert str(ver.inc_release()) == '0.1.3'100 ver = SemanticVersion.FromString('1.2.3')101 assert str(ver.inc_release()) == '1.2.4'102def test_coexistence():103 """Test to make sure that version coexistence determination works104 """105 ver = SemanticVersion.FromString('1.1.1')106 ver2 = SemanticVersion.FromString('1.2.3')107 ver3 = SemanticVersion.FromString('2.0.0')108 assert ver.coexistence_class == ver2.coexistence_class109 assert not ver3.coexistence_class == ver2.coexistence_class110 ver = SemanticVersion.FromString('0.1.1')111 ver2 = SemanticVersion.FromString('0.1.2')112 ver3 = SemanticVersion.FromString('0.2.0')113 ver4 = SemanticVersion.FromString('1.1.0')114 assert ver.coexistence_class == ver2.coexistence_class115 assert not ver3.coexistence_class == ver2.coexistence_class116 assert not ver4.coexistence_class == ver2.coexistence_class117 ver = SemanticVersion.FromString('0.0.1')118 ver2 = SemanticVersion.FromString('0.0.1')119 ver3 = SemanticVersion.FromString('0.1.0')120 ver4 = SemanticVersion.FromString('1.1.0')121 assert ver.coexistence_class == ver2.coexistence_class122 assert not ver3.coexistence_class == ver2.coexistence_class123 assert not ver4.coexistence_class == ver2.coexistence_class124 #Make sure prereleases are compat as well125 ver = SemanticVersion.FromString('0.1.0')126 ver2 = SemanticVersion.FromString('0.1.1-alpha2')127 assert ver.coexistence_class == ver2.coexistence_class128def test_pep440():129 """Make sure we can generate pep440 compliant strings."""130 assert SemanticVersion.FromString('1.2.3-alpha4').pep440_string() == '1.2.3a4'131 assert SemanticVersion.FromString('1.2.3-beta4').pep440_string() == '1.2.3b4'132 assert SemanticVersion.FromString('1.2.3-rc4').pep440_string() == '1.2.3rc4'133 assert SemanticVersion.FromString('1.2.3-build4').pep440_string() == '1.2.3.dev4'134def test_pep440_compat():135 """Make sure we can generate appropriate pep440 range specifiers."""136 assert SemanticVersion.FromString('1.2.3').pep440_compatibility_specifier() == '>= 1.2.3, == 1.*'137 assert SemanticVersion.FromString('1.2.3-alpha4').pep440_compatibility_specifier() == '>= 1.2.3a4, == 1.*'138 req_rel = pkg_resources.Requirement.parse('abc ' + SemanticVersion.FromString('1.2.3').pep440_compatibility_specifier())139 req_pre = pkg_resources.Requirement.parse('abc ' + SemanticVersion.FromString('1.2.3-alpha4').pep440_compatibility_specifier())140 print(str(req_rel))141 print(str(req_pre))142 assert not '1.2.2' in req_rel143 assert '1.2.3' in req_rel144 assert '1.3.0' in req_rel145 assert not '2.0.0' in req_rel146 assert '1.2.3' in req_pre147 assert '1.3.0' in req_pre148 assert '1.2.3b1' in req_pre...

Full Screen

Full Screen

test_semver_range.py

Source:test_semver_range.py Github

copy

Full Screen

1"""Tests for SemanticVersion and SemanticVersionRange classes."""2from iotile.core.dev.semver import SemanticVersion, SemanticVersionRange3from iotile.core.exceptions import ArgumentError4import pytest5def test_basic_parsing_exceptions():6 """Make sure we throw the righ parsing errors."""7 with pytest.raises(ArgumentError):8 SemanticVersionRange.FromString('')9 with pytest.raises(ArgumentError):10 SemanticVersionRange.FromString(' ')11def test_star():12 """Make sure wildcard matching works."""13 ver_range = SemanticVersionRange.FromString('*')14 ver = SemanticVersion.FromString('1.0.0')15 ver2 = SemanticVersion.FromString('0.0.1-alpha1')16 assert ver_range.check(ver)17 assert ver_range.check(ver2)18def test_equals():19 """Make sure =X.Y.Z version ranges work."""20 ver_range = SemanticVersionRange.FromString('=0.0.1')21 assert ver_range.check(SemanticVersion.FromString('0.0.1'))22 assert not ver_range.check(SemanticVersion.FromString('0.0.1-alpha2'))23 assert not ver_range.check(SemanticVersion.FromString('0.0.2'))24 assert not ver_range.check(SemanticVersion.FromString('0.1.1'))25 assert not ver_range.check(SemanticVersion.FromString('1.0.1'))26 ver_range = SemanticVersionRange.FromString('=0.1.1')27 assert ver_range.check(SemanticVersion.FromString('0.1.1'))28 assert not ver_range.check(SemanticVersion.FromString('0.1.1-alpha2'))29 assert not ver_range.check(SemanticVersion.FromString('0.2.1'))30 assert not ver_range.check(SemanticVersion.FromString('0.1.0'))31 assert not ver_range.check(SemanticVersion.FromString('1.1.1'))32 ver_range = SemanticVersionRange.FromString('=1.1.1')33 assert ver_range.check(SemanticVersion.FromString('1.1.1'))34 assert not ver_range.check(SemanticVersion.FromString('1.1.1-alpha2'))35 assert not ver_range.check(SemanticVersion.FromString('0.0.2'))36 assert not ver_range.check(SemanticVersion.FromString('0.1.1'))37 assert not ver_range.check(SemanticVersion.FromString('1.2.1'))38 ver_range = SemanticVersionRange.FromString('=1.1.1-alpha2')39 assert ver_range.check(SemanticVersion.FromString('1.1.1-alpha2'))40 assert not ver_range.check(SemanticVersion.FromString('1.1.1-alpha3'))41 assert not ver_range.check(SemanticVersion.FromString('1.1.1'))42 assert not ver_range.check(SemanticVersion.FromString('0.1.1'))43 assert not ver_range.check(SemanticVersion.FromString('1.0.1'))44def test_carrot():45 """Make sure semantic version operator works ^X.Y.Z."""46 ver_range = SemanticVersionRange.FromString('^0.0.1')47 print("Lower: %s" % ver_range._disjuncts[0][0][0])48 print("Upper: %s" % ver_range._disjuncts[0][0][1])49 assert ver_range.check(SemanticVersion.FromString('0.0.1'))50 assert not ver_range.check(SemanticVersion.FromString('0.0.2'))51 assert not ver_range.check(SemanticVersion.FromString('0.1.0'))52 assert not ver_range.check(SemanticVersion.FromString('0.0.2-alpha2'))53 assert not ver_range.check(SemanticVersion.FromString('1.0.0'))54 ver_range = SemanticVersionRange.FromString('^0.1.0')55 print("Lower: %s" % ver_range._disjuncts[0][0][0])56 print("Upper: %s" % ver_range._disjuncts[0][0][1])57 assert ver_range.check(SemanticVersion.FromString('0.1.0'))58 assert ver_range.check(SemanticVersion.FromString('0.1.1'))59 assert not ver_range.check(SemanticVersion.FromString('1.1.0'))60 assert not ver_range.check(SemanticVersion.FromString('0.1.1-alpha2'))61 assert not ver_range.check(SemanticVersion.FromString('1.0.0'))62 ver_range = SemanticVersionRange.FromString('^2.0.0')63 print("Lower: %s" % ver_range._disjuncts[0][0][0])64 print("Upper: %s" % ver_range._disjuncts[0][0][1])65 assert ver_range.check(SemanticVersion.FromString('2.0.0'))66 assert ver_range.check(SemanticVersion.FromString('2.1.1'))67 assert ver_range.check(SemanticVersion.FromString('2.0.1'))68 assert not ver_range.check(SemanticVersion.FromString('2.0.1-alpha1'))69 assert not ver_range.check(SemanticVersion.FromString('1.1.0'))70 assert not ver_range.check(SemanticVersion.FromString('0.1.1-alpha2'))71 assert not ver_range.check(SemanticVersion.FromString('1.0.0'))72 #Make sure prerelease checking works in lower bound73 ver_range = SemanticVersionRange.FromString('^2.0.0-alpha2')74 print("Lower: %s" % ver_range._disjuncts[0][0][0])75 print("Upper: %s" % ver_range._disjuncts[0][0][1])76 assert ver_range.check(SemanticVersion.FromString('2.0.0'))77 assert ver_range.check(SemanticVersion.FromString('2.1.1'))78 assert ver_range.check(SemanticVersion.FromString('2.0.1'))79 assert ver_range.check(SemanticVersion.FromString('2.0.0-alpha2'))80 assert ver_range.check(SemanticVersion.FromString('2.0.0-beta1'))81 assert not ver_range.check(SemanticVersion.FromString('2.0.0-alpha1'))82 assert not ver_range.check(SemanticVersion.FromString('2.0.1-alpha1'))83 assert not ver_range.check(SemanticVersion.FromString('1.1.0'))84 assert not ver_range.check(SemanticVersion.FromString('0.1.1-alpha2'))85 assert not ver_range.check(SemanticVersion.FromString('1.0.0'))86def test_filtering():87 """Make sure we can filter a range of versions against a spec."""88 ver_range = SemanticVersionRange.FromString('^2.0.0-alpha2')89 in1 = SemanticVersion.FromString('2.0.0')90 in2 = SemanticVersion.FromString('2.1.1')91 out1 = SemanticVersion.FromString('2.0.0-alpha1')92 inlist = [in1, in2, out1]93 outlist = ver_range.filter(inlist)94 outset = set(outlist)95 assert len(outset) == 296 assert in1 in outset97 assert in2 in outset98 assert out1 not in outset99def test_filtering_keys():100 """Make sure we can filter using a key."""101 ver_range = SemanticVersionRange.FromString('^2.0.0-alpha2')102 in1 = (SemanticVersion.FromString('2.0.0'), 'a')103 in2 = (SemanticVersion.FromString('2.1.1'), 'b')104 out1 = (SemanticVersion.FromString('2.0.0-alpha1'), 'c')105 inlist = [in1, in2, out1]106 outlist = ver_range.filter(inlist, key=lambda x: x[0])107 outset = set(outlist)108 assert len(outset) == 2109 assert in1 in outset110 assert in2 in outset...

Full Screen

Full Screen

parseprice.py

Source:parseprice.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3from price_parser import Price4from price_parser import parse_price5price = Price.fromstring("22,90 €")6print(price)7# numeric price amount8print(price.amount) 9# currency symbol, as appears in the string10print(price.currency) 11# price amount, as appears in the string12print(price.amount_text) 13# price amount as float, not Decimal14print(price.amount_float)15print(parse_price("22,90 €"))16print(Price.fromstring("Price: $119.00"))17print(Price.fromstring("15 130 Р"))18print(Price.fromstring("151,200 تومان"))19print(Price.fromstring("Rp 1.550.000"))20print(Price.fromstring("Běžná cena 75 990,00 Kč"))21print(Price.fromstring("1,235€ 99"))22print(Price.fromstring("24€99"))23print(Price.fromstring("99 € 95 €"))24print(Price.fromstring("35€ 999"))25print(Price.fromstring("€35,999"))26print(Price.fromstring("€35,999",currency_hint="€",decimal_separator=","))27print(Price.fromstring(""))28print(Price.fromstring("Foo"))29print(Price.fromstring("50% OFF"))30print(Price.fromstring("50"))31print(Price.fromstring("R$"))32print(Price.fromstring("34.99", currency_hint="руб. (шт)"))33price = Price.fromstring("1 000")34price.currency = 'EUR'35print(price)36print(Price.fromstring("Price: $140.600", decimal_separator="."))...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2client.getDevices().then(function(devices) {3 console.log(devices);4});5var stf = require('devicefarmer-stf-client');6client.getDevices().then(function(devices) {7 console.log(devices);8});9var stf = require('devicefarmer-stf-client');10client.getDevices().then(function(devices) {11 console.log(devices);12});13var stf = require('devicefarmer-stf-client');14client.getDevices().then(function(devices) {15 console.log(devices);16});17var stf = require('devicefarmer-stf-client');18client.getDevices().then(function(devices) {19 console.log(devices);20});21var stf = require('devicefarmer-stf-client');22client.getDevices().then(function(devices) {23 console.log(devices);24});25var stf = require('devicefarmer-stf-client');26client.getDevices().then(function(devices) {27 console.log(devices);28});29var stf = require('devicefarmer-stf-client');30client.getDevices().then(function(devices

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('./devicefarmer-stf-client');2var stf = require('devicefarmer-stf-client');3var util = require('util');4var fs = require('fs');5var device = client.allocateDevice();6var device = client.allocateDevice();

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var util = require('util');3var device = new stf.Device(client, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');4device.fromString('Hello World').then(function() {5 console.log('Done');6});7var stf = require('devicefarmer-stf-client');8var util = require('util');9var device = new stf.Device(client, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');10device.fromString('Hello World').then(function() {11 console.log('Done');12});13var stf = require('devicefarmer-stf-client');14var util = require('util');15var device = new stf.Device(client, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');16device.fromString('Hello World').then(function() {17 console.log('Done');18});19var stf = require('devicefarmer-stf-client');20var util = require('util');21var device = new stf.Device(client, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');22device.fromString('Hello World').then(function() {23 console.log('Done');24});25var stf = require('devicefarmer-stf-client');26var util = require('util');27var device = new stf.Device(client, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');28device.fromString('Hello World').then(function() {29 console.log('Done');30});31var stf = require('devicefarmer-stf-client');32var util = require('util');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var client = stf.connect({3});4var device = client.getDevice('4d0054a1');5device.then(function (device) {6 device.fromString('test4.js', 'console.log("test4.js content");');7});8var stf = require('devicefarmer-stf-client');9var client = stf.connect({10});11var device = client.getDevice('4d0054a1');12device.then(function (device) {13 device.fromFile('test5.js', 'test5.js');14});15var stf = require('devicefarmer-stf-client');16var client = stf.connect({17});18var device = client.getDevice('4d0054a1');19device.then(function (device) {20 device.fromFile('test6.js', 'test6.js');21});22var stf = require('devicefarmer-stf-client');23var client = stf.connect({24});25var device = client.getDevice('4d0054a1');26device.then(function (device) {27 device.fromFile('test7.js', 'test7.js');28});29var stf = require('devicefarmer-stf-client');30var client = stf.connect({31});32var device = client.getDevice('4d0054a1');33device.then(function (device) {34 device.fromFile('test8.js', 'test8.js');35});36var stf = require('devicefarmer-stf-client');37var client = stf.connect({

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = client.getDevice("device-serial");3device.shell('ls /sdcard');4device.shell('ls /sdcard/DCIM');5device.shell('ls /sdcard/DCIM/Camera');6var fs = require('fs');7var stream = fs.createWriteStream("test4.js");8stream.once('open', function(fd) {9 stream.write('var stf = require('devicefarmer-stf-client');');10 stream.write('var device = client.getDevice("device-serial");');11 stream.write('device.shell('ls /sdcard');');12 stream.write('device.shell('ls /sdcard/DCIM');');13 stream.write('device.shell('ls /sdcard/DCIM/Camera');');14 stream.end();15});16var stf = require('devicefarmer-stf-client');17var device = client.getDevice("device-serial");18device.shell('ls /sdcard');19device.shell('ls /sdcard/DCIM');20device.shell('ls /sdcard/DCIM/Camera');21var fs = require('fs');22var stream = fs.createWriteStream("test5.js");23stream.once('open', function(fd) {24 stream.write('var stf = require('devicefarmer-stf-client');');25 stream.write('var device = client.getDevice("device-serial");');26 stream.write('device.shell('ls /sdcard');');27 stream.write('device.shell('ls /sdcard/DCIM');');28 stream.write('device.shell('ls /sdcard/DCIM/Camera');');29 stream.end();30});31var stf = require('devicefarmer-stf-client');32var device = client.getDevice("device-serial");33device.shell('ls /sdcard');

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 devicefarmer-stf 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