Best Python code snippet using localstack_python
test_session_log_json.py
Source:test_session_log_json.py
...9 encoder = JsonEncoder(options=options)10 log = SessionLog(11 log_entries=[12 VRCPlayerJoinEntry(13 timestamp=parse_timestamp("2022.03.04 21:50:19"),14 user_name=UserName("E.HOBA"),15 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")16 ),17 VRCPlayerJoinEntry(18 timestamp=parse_timestamp("2022.03.04 21:50:19"),19 user_name=UserName("E.HOBA"),20 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")21 ),22 VRCPlayerJoinEntry(23 timestamp=parse_timestamp("2022.03.04 21:50:19"),24 user_name=UserName("E.HOBA"),25 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")26 )27 ])28 assert encoder.encode(log) == (29 '{"log_entries": [{"timestamp": 1646430619.0, "pseudo_user_name": "E.HOBA '30 'Pseudo", "type_id": "vrc/player_join"}, {"timestamp": 1646430619.0, '31 '"pseudo_user_name": "E.HOBA Pseudo", "type_id": "vrc/player_join"}, '32 '{"timestamp": 1646430619.0, "pseudo_user_name": "E.HOBA Pseudo", "type_id": '33 '"vrc/player_join"}], "metadata": null}')34 def test__output_all_personal_info(self):35 options = JsonEncoder.Options.default()36 options.output_user_name = True37 encoder = JsonEncoder(options=options)38 log = SessionLog(39 log_entries=[40 VRCPlayerJoinEntry(41 timestamp=parse_timestamp("2022.03.04 21:50:19"),42 user_name=UserName("E.HOBA"),43 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")44 ),45 VRCPlayerJoinEntry(46 timestamp=parse_timestamp("2022.03.04 21:50:19"),47 user_name=UserName("E.HOBA"),48 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")49 ),50 VRCPlayerJoinEntry(51 timestamp=parse_timestamp("2022.03.04 21:50:19"),52 user_name=UserName("E.HOBA"),53 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")54 )55 ])56 assert encoder.encode(log) == (57 '{"log_entries": [{"timestamp": 1646430619.0, "user_name": "E.HOBA", '58 '"pseudo_user_name": "E.HOBA Pseudo", "type_id": "vrc/player_join"}, '59 '{"timestamp": 1646430619.0, "user_name": "E.HOBA", "pseudo_user_name": '60 '"E.HOBA Pseudo", "type_id": "vrc/player_join"}, {"timestamp": 1646430619.0, '61 '"user_name": "E.HOBA", "pseudo_user_name": "E.HOBA Pseudo", "type_id": '62 '"vrc/player_join"}], "metadata": null}')63 def test__strict_output_option(self):64 options = JsonEncoder.Options.default()65 options.output_timestamp = False66 options.output_pseudo_user_name = False67 options.output_vrc_player_id = False68 options.output_user_name = False69 encoder = JsonEncoder(options=options)70 log = SessionLog(71 log_entries=[72 VRCPlayerJoinEntry(73 timestamp=parse_timestamp("2022.03.04 21:50:19"),74 user_name=UserName("E.HOBA"),75 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")76 ),77 VRCPlayerJoinEntry(78 timestamp=parse_timestamp("2022.03.04 21:50:19"),79 user_name=UserName("E.HOBA"),80 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")81 ),82 VRCPlayerJoinEntry(83 timestamp=parse_timestamp("2022.03.04 21:50:19"),84 user_name=UserName("E.HOBA"),85 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")86 )87 ])88 assert encoder.encode(log) == (89 '{"log_entries": [{"type_id": "vrc/player_join"}, {"type_id": '90 '"vrc/player_join"}, {"type_id": "vrc/player_join"}], "metadata": null}')91class TestJsonDecoder:92 def test__normal(self):93 decoder = JsonDecoder()94 output = decoder.decode(95 '{"log_entries": [{"timestamp": 1646430619.0, "user_name": "E.HOBA", '96 '"pseudo_user_name": "E.HOBA Pseudo", "type_id": "vrc/player_join"}, '97 '{"timestamp": 1646430619.0, "user_name": "E.HOBA", "pseudo_user_name": '98 '"E.HOBA Pseudo", "type_id": "vrc/player_join"}, {"timestamp": 1646430619.0, '99 '"user_name": "E.HOBA", "pseudo_user_name": "E.HOBA Pseudo", "type_id": '100 '"vrc/player_join"}], "metadata": null}')101 assert output == SessionLog(102 log_entries=[103 VRCPlayerJoinEntry(104 timestamp=parse_timestamp("2022.03.04 21:50:19"),105 user_name=UserName("E.HOBA"),106 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")107 ),108 VRCPlayerJoinEntry(109 timestamp=parse_timestamp("2022.03.04 21:50:19"),110 user_name=UserName("E.HOBA"),111 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")112 ),113 VRCPlayerJoinEntry(114 timestamp=parse_timestamp("2022.03.04 21:50:19"),115 user_name=UserName("E.HOBA"),116 pseudo_user_name=PseudoUserName("E.HOBA Pseudo")117 )...
types.py
Source:types.py
...31 def __str__(self) -> str:32 return self.symbol33 def __repr__(self) -> str:34 return "Market(%r, %r)" % (self._exchange, self._instrument)35def parse_timestamp(t: TimestampLike) -> Timestamp:36 """37 Convert values to timestamp. If the value is already a timestamp, it will be returned as-is.38 >>> t1 = Timestamp("2017-03-07")39 >>> parse_timestamp(t1)40 Timestamp('2017-03-07 00:00:00')41 >>> parse_timestamp(t1) == t142 True43 >>> parse_timestamp("2017-03-07")44 Timestamp('2017-03-07 00:00:00+0000', tz='UTC')45 >>> parse_timestamp("2017-03Z")46 Timestamp('2017-03-01 00:00:00+0000', tz='UTC')47 >>> parse_timestamp(1488844800000000000)48 Timestamp('2017-03-07 00:00:00+0000', tz='UTC')49 """50 if isinstance(t, Timestamp):51 return t52 if isinstance(t, str):53 return Timestamp(t.replace("Z", ""), tz="UTC")54 return Timestamp(t, tz="UTC")55def format_timestamp(t: Timestamp) -> str:56 """57 Displays a timestamp in a short ISO8601-compatible format by leaving out "null" elements.58 >>> format_timestamp(parse_timestamp("2020-03-24 15:34:55"))59 '2020-03-24T15:34:55Z'60 >>> format_timestamp(parse_timestamp("2020-03-24 15:34:00"))61 '2020-03-24T15:34Z'62 >>> format_timestamp(parse_timestamp("2020-03-24 15:00:00"))63 '2020-03-24T15Z'64 >>> format_timestamp(parse_timestamp("2020-03-24 00:00:00"))65 '2020-03-24Z'66 >>> format_timestamp(parse_timestamp("2020-03-01 00:00:00"))67 '2020-03Z'68 >>> format_timestamp(parse_timestamp("2020-01-01 00:00:00"))69 '2020Z'70 """71 return (72 t.isoformat()73 .replace("+00:00", "Z")74 .replace(":00Z", "Z")75 .replace(":00Z", "Z")76 .replace("T00Z", "Z")77 .replace("-01Z", "Z")78 .replace("-01Z", "Z")79 )80def format_timestamp_full(t: Timestamp) -> str:81 return t.strftime("%Y-%m-%dT%H:%M:%S.%f") + ("%03d" % t.nanosecond) + "Z"82class TimeInterval(Interval):83 """84 Represents an open time interval [start; end).85 The start is inclusive, the end is exclusive.86 >>> TimeInterval(Timestamp("2019-08-20"), Timestamp("2019-11-03"))87 TimeInterval('2019-08-20T00:00:00', '2019-11-03T00:00:00')88 >>> august = TimeInterval("2019-08-01", "2019-09-01")89 >>> august90 TimeInterval('2019-08Z', '2019-09Z')91 >>> august == TimeInterval('2019-08Z', '2019-09Z')92 True93 >>> str(august)94 '2019-08Z/2019-09Z'95 >>> august.start96 Timestamp('2019-08-01 00:00:00+0000', tz='UTC')97 >>> august.start.asm898 numpy.datetime64('2019-08-01T00:00:00.000000000')99 >>> august.end100 Timestamp('2019-09-01 00:00:00+0000', tz='UTC')101 >>> august.end.asm8102 numpy.datetime64('2019-09-01T00:00:00.000000000')103 >>> august.closed104 'left'105 """106 def __init__(self, start: TimestampLike, end: TimestampLike):107 super().__init__(parse_timestamp(start), parse_timestamp(end), closed="left")108 @property109 def start(self) -> Timestamp:110 return self.left111 @property112 def end(self) -> Timestamp:113 return self.right114 def with_start(self, start: Timestamp) -> "TimeInterval":115 return TimeInterval(start, self.end)116 def with_end(self, end: Timestamp) -> "TimeInterval":117 return TimeInterval(self.start, end)118 def format(self, short=False) -> str:119 if short:120 start = format_timestamp(self.start).replace("Z", "")121 end = format_timestamp(self.end).replace("Z", "")...
test_parsing_utils.py
Source:test_parsing_utils.py
...4from pepys_import.core.formats import rep_line5def test_nmea_timestamp_parsing():6 parse_timestamp = NMEAImporter.parse_timestamp7 # Invalid day in date8 result = parse_timestamp("20201045", "111456")9 assert not result10 # Invalid hour in time11 result = parse_timestamp("20201006", "340738")12 assert not result13def test_etrac_timestamp_parsing():14 parse_timestamp = ETracImporter.parse_timestamp15 # Invalid day in date16 result = parse_timestamp("2020/04/57", "11:46:23")17 assert not result18 # Invalid hour in time19 result = parse_timestamp("2020/04/07", "34:07:38")20 assert not result21def test_rep_timestamp_parsing():22 parse_timestamp = rep_line.parse_timestamp23 date = "20201001"24 time = "12010" # missing minute in time25 result = parse_timestamp(date, time)26 assert not result27 time = "340100" # invalid hour in time28 result = parse_timestamp(date, time)29 assert not result30 time = "120105"31 result = parse_timestamp(date, time)32 assert result == datetime(2020, 10, 1, 12, 1, 5)33 time = "120105.1"34 result = parse_timestamp(date, time)35 assert result == datetime(2020, 10, 1, 12, 1, 5, 100000)36 time = "120105.11"37 result = parse_timestamp(date, time)38 assert result == datetime(2020, 10, 1, 12, 1, 5, 110000)39 time = "120105.111"40 result = parse_timestamp(date, time)41 assert result == datetime(2020, 10, 1, 12, 1, 5, 111000)42 time = "120105.1111"43 result = parse_timestamp(date, time)44 assert result == datetime(2020, 10, 1, 12, 1, 5, 111100)45 time = "120105.11111"46 result = parse_timestamp(date, time)47 assert result == datetime(2020, 10, 1, 12, 1, 5, 111110)48 time = "120105.111111"49 result = parse_timestamp(date, time)50 assert result == datetime(2020, 10, 1, 12, 1, 5, 111111)51 time = "120101.1234567" # invalid decimals in time52 result = parse_timestamp(date, time)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!