How to use parse_value method in Playwright Python

Best Python code snippet using playwright-python

test_xs_types.py

Source:test_xs_types.py Github

copy

Full Screen

...110# def test_any_uri():111# pass112#113def test_Base64BinaryType_parse():114 assert Base64BinaryType().parse_value(b'FPucA9l+') == b'\x14\xfb\x9c\x03\xd9\x7e'115 assert Base64BinaryType().parse_value(b'FPucA9k=') == b'\x14\xfb\x9c\x03\xd9'116 assert Base64BinaryType().parse_value(b'FPucAw==') == b'\x14\xfb\x9c\x03'117def test_Base64BinaryType_produce():118 assert Base64BinaryType().produce_value(b'\x14\xfb\x9c\x03\xd9\x7e') == b'FPucA9l+'119 assert Base64BinaryType().produce_value(b'\x14\xfb\x9c\x03\xd9') == b'FPucA9k='120 assert Base64BinaryType().produce_value(b'\x14\xfb\x9c\x03') == b'FPucAw=='121def test_BooleanType_parse():122 assert BooleanType().parse_value('1') == True123 assert BooleanType().parse_value('0') == False124 assert BooleanType().parse_value('true') == True125 assert BooleanType().parse_value('false') == False126def test_BooleanType_produce():127 assert BooleanType().produce_value(True) == 'True'128 assert BooleanType().produce_value(False) == 'False'129def test_ByteType_parse():130 assert ByteType().parse_value('127') == 127131def test_ByteType_produce():132 assert ByteType().produce_value(127) == '127'133def test_DateType_parse():134 assert DateType().parse_value('2017-05-16Z') == SevenPropertyModel(year=2017, month=5, day=16, timezoneOffset=0)135def test_DateType_produce():136 assert DateType().produce_value(SevenPropertyModel(year=2017, month=5, day=16, timezoneOffset=0)) == '2017-05-16Z'137def test_DateTimeType_parse():138 assert DateTimeType().parse_value('2017-05-16T12:42:42Z') == SevenPropertyModel(year=2017, month=5, day=16, hour=12, minute=42, second=42, timezoneOffset=0)139def test_DateTimeType_produce():140 assert DateTimeType().produce_value(SevenPropertyModel(year=2017, month=5, day=16, hour=12, minute=42, second=42, timezoneOffset=0)) == '2017-05-16T12:42:42Z'141def test_DateTimeStampType_parse():142 assert DateTimeStampType().parse_value('2017-05-16T12:42:42Z') == SevenPropertyModel(year=2017, month=5, day=16, hour=12, minute=42, second=42, timezoneOffset=0)143def test_DateTimeStampType_produce():144 assert DateTimeStampType().produce_value(SevenPropertyModel(year=2017, month=5, day=16, hour=12, minute=42, second=42, timezoneOffset=0)) == '2017-05-16T12:42:42Z'145def test_DayTimeDurationType_parse():146 assert DayTimeDurationType().parse_value('P1DT1H1M1.1S') == (0, 90061.1)147 assert DayTimeDurationType().parse_value('P1D') == (0, 86400.0)148 assert DayTimeDurationType().parse_value('PT1H') == (0, 3600.0)149 assert DayTimeDurationType().parse_value('PT1M') == (0, 60.0)150 assert DayTimeDurationType().parse_value('PT1S') == (0, 1.0)151 assert DayTimeDurationType().parse_value('-P1D') == (0, -86400.0)152 assert DayTimeDurationType().parse_value('-PT1H') == (0, -3600.0)153 assert DayTimeDurationType().parse_value('-PT1M') == (0, -60.0)154 assert DayTimeDurationType().parse_value('-PT1S') == (0, -1.0)155 with pytest.raises(ValueError):156 DayTimeDurationType().parse_value('P1Y1M1DT1H1M1.1S')157def test_DayTimeDurationType_produce():158 assert DayTimeDurationType().produce_value((0, 90061.1)) == 'P1DT1H1M1.100000S'159 assert DayTimeDurationType().produce_value((0, 86400.0)) == 'P1D'160 assert DayTimeDurationType().produce_value((0, 3600.0)) == 'PT1H'161 assert DayTimeDurationType().produce_value((0, 60.0)) == 'PT1M'162 assert DayTimeDurationType().produce_value((0, 1.0)) == 'PT1S'163 assert DayTimeDurationType().produce_value((0, -86400.0)) == '-P1D'164 assert DayTimeDurationType().produce_value((0, -3600.0)) == '-PT1H'165 assert DayTimeDurationType().produce_value((0, -60.0)) == '-PT1M'166 assert DayTimeDurationType().produce_value((0, -1.0)) == '-PT1S'167 with pytest.raises(ValueError):168 DayTimeDurationType().produce_value((1, 1.0))169def test_DecimalType_parse():170 assert DecimalType().parse_value('1.1') == 1.1171def test_DecimalType_produce():172 assert DecimalType().produce_value(1.1) == '1.1'173def test_DoubleType_parse():174 assert DoubleType().parse_value('1.1') == 1.1175def test_DoubleType_produce():176 assert DoubleType().produce_value(1.1) == '1.1'177def test_DurationType_parse():178 assert DurationType().parse_value('P1Y1M1DT1H1M1.1S') == (13, 90061.1)179 assert DurationType().parse_value('P1Y') == (12, 0.0)180 assert DurationType().parse_value('P1M') == (1, 0.0)181 assert DurationType().parse_value('P1D') == (0, 86400.0)182 assert DurationType().parse_value('PT1H') == (0, 3600.0)183 assert DurationType().parse_value('PT1M') == (0, 60.0)184 assert DurationType().parse_value('PT1S') == (0, 1.0)185 assert DurationType().parse_value('-P1Y') == (-12, 0.0)186 assert DurationType().parse_value('-P1M') == (-1, 0.0)187 assert DurationType().parse_value('-P1D') == (0, -86400.0)188 assert DurationType().parse_value('-PT1H') == (0, -3600.0)189 assert DurationType().parse_value('-PT1M') == (0, -60.0)190 assert DurationType().parse_value('-PT1S') == (0, -1.0)191def test_DurationType_produce():192 assert DurationType().produce_value((13, 90061.1)) == 'P1Y1M1DT1H1M1.100000S'193 assert DurationType().produce_value((12, 0.0)) == 'P1Y'194 assert DurationType().produce_value((1, 0.0)) == 'P1M'195 assert DurationType().produce_value((0, 86400.0)) == 'P1D'196 assert DurationType().produce_value((0, 3600.0)) == 'PT1H'197 assert DurationType().produce_value((0, 60.0)) == 'PT1M'198 assert DurationType().produce_value((0, 1.0)) == 'PT1S'199 assert DurationType().produce_value((-12, 0.0)) == '-P1Y'200 assert DurationType().produce_value((-1, 0.0)) == '-P1M'201 assert DurationType().produce_value((0, -86400.0)) == '-P1D'202 assert DurationType().produce_value((0, -3600.0)) == '-PT1H'203 assert DurationType().produce_value((0, -60.0)) == '-PT1M'204 assert DurationType().produce_value((0, -1.0)) == '-PT1S'205def test_EntitiesType_parse():206 assert EntitiesType().parse_value('blah0 blah1 blah2') == ('blah0', 'blah1', 'blah2')207 with pytest.raises(ValueError):208 EntitiesType().parse_value('')209def test_EntitiesType_produce():210 assert EntitiesType().produce_value(('blah0', 'blah1', 'blah2')) == 'blah0 blah1 blah2'211def test_EntityType_parse():212 assert EntityType().parse_value('test_id_4') == 'test_id_4'213def test_EntityType_produce():214 assert EntityType().produce_value('test_id_4') == 'test_id_4'215def test_FloatType_parse():216 assert FloatType().parse_value('1.1') == 1.1217def test_FloatType_produce():218 assert FloatType().produce_value(1.1) == '1.1'219def test_GDayType_parse():220 assert GDayType().parse_value('---22') == SevenPropertyModel(day=22)221def test_GDayType_produce():222 assert GDayType().produce_value(SevenPropertyModel(day=22)) == '---22'223def test_GMonthType_parse():224 assert GMonthType().parse_value('--05') == SevenPropertyModel(month=5)225def test_GMonthType_produce():226 assert GMonthType().produce_value(SevenPropertyModel(month=5)) == '--05'227def test_GMonthDayType_day_parse():228 assert GMonthDayType().parse_value('--05-22') == SevenPropertyModel(month=5, day=22)229def test_GMonthDayType_produce():230 assert GMonthDayType().produce_value(SevenPropertyModel(month=5, day=22)) == '--05-22'231def test_GYearType_parse():232 assert GYearType().parse_value('2017') == SevenPropertyModel(year=2017)233def test_GYearType_produce():234 assert GYearType().produce_value(SevenPropertyModel(year=2017)) == '2017'235def test_GYearMonthType_parse():236 assert GYearMonthType().parse_value('2017-05') == SevenPropertyModel(year=2017, month=5)237def test_GYearMonthType_produce():238 assert GYearMonthType().produce_value(SevenPropertyModel(year=2017, month=5)) == '2017-05'239def test_HexBinaryType_parse():240 assert HexBinaryType().parse_value(b'14fb9c03d97e') == b'\x14\xfb\x9c\x03\xd9\x7e'241 assert HexBinaryType().parse_value(b'14fb9c03d9') == b'\x14\xfb\x9c\x03\xd9'242 assert HexBinaryType().parse_value(b'14fb9c03') == b'\x14\xfb\x9c\x03'243def test_HexBinaryType_produce():244 assert HexBinaryType().produce_value(b'\x14\xfb\x9c\x03\xd9\x7e') == b'14fb9c03d97e'245 assert HexBinaryType().produce_value(b'\x14\xfb\x9c\x03\xd9') == b'14fb9c03d9'246 assert HexBinaryType().produce_value(b'\x14\xfb\x9c\x03') == b'14fb9c03'247def test_IdType_parse():248 assert IdType().parse_value('test_id_4') == 'test_id_4'249def test_IdType_produce():250 assert IdType().produce_value('test_id_4') == 'test_id_4'251def test_IdRefType_parse():252 assert IdRefType().parse_value('test_id_4') == 'test_id_4'253def test_IdRefType_produce():254 assert IdRefType().produce_value('test_id_4') == 'test_id_4'255def test_IdRefsType_parse():256 assert IdRefsType().parse_value('blah0 blah1 blah2') == ('blah0', 'blah1', 'blah2')257 with pytest.raises(ValueError):258 IdRefsType().parse_value('')259 assert IdRefsType().produce_value(('blah0', 'blah1', 'blah2')) == 'blah0 blah1 blah2'260def test_IdRefsType_produce():261 assert IdRefsType().produce_value(('blah0', 'blah1', 'blah2')) == 'blah0 blah1 blah2'262def test_IntType_parse():263 assert IntType().parse_value('255') == 255264def test_IntType_produce():265 assert IntType().produce_value(255) == '255'266def test_IntegerType_parse():267 assert IntegerType().parse_value('255') == 255268def test_IntegerType_produce():269 assert IntegerType().produce_value(255) == '255'270def test_LanguageType_parse():271 assert LanguageType().parse_value('en') == 'en'272 assert LanguageType().parse_value('en-US') == 'en-US'273 assert LanguageType().parse_value('en-gb') == 'en-gb'274 with pytest.raises(ValueError):275 LanguageType().parse_value('')276def test_LanguageType_parse():277 assert LanguageType().produce_value('en') == 'en'278 assert LanguageType().produce_value('en-US') == 'en-US'279def test_LongType_parse():280 assert LongType().parse_value('255') == 255281def test_LongType_produce():282 assert LongType().produce_value(255) == '255'283def test_NameType_parse():284 assert NameType().parse_value('test_id_4') == 'test_id_4'285 with pytest.raises(ValueError):286 NameType().parse_value('4test_id_4')287def test_NameType_produce():288 assert NameType().produce_value('test_id_4') == 'test_id_4'289def test_NCNameType_parse():290 assert NCNameType().parse_value('test_id_4') == 'test_id_4'291 with pytest.raises(ValueError):292 NCNameType().parse_value('test:id_4')293def test_NCNameType_produce():294 assert NCNameType().produce_value('test_id_4') == 'test_id_4'295def test_NegativeIntegerType_parse():296 assert NegativeIntegerType().parse_value('-255') == -255297def test_NegativeIntegerType_produce():298 assert NegativeIntegerType().produce_value(-255) == '-255'299def test_NMTokenType_parse():300 assert NMTokenType().parse_value('xml_schema') == 'xml_schema'301 assert NMTokenType().parse_value('2xml_schema') == '2xml_schema'302 assert NMTokenType().parse_value('-xml_schema') == '-xml_schema'303 assert NMTokenType().parse_value('.xml_schema') == '.xml_schema'304 with pytest.raises(ValueError):305 NMTokenType().parse_value('\x0dtoken')306def test_NMTokenType_produce():307 assert NMTokenType().produce_value('xml_schema') == 'xml_schema'308def test_NMTokensType_parse():309 assert NMTokensType().parse_value('xml_schema') == ('xml_schema',)310 assert NMTokensType().parse_value('xml_schema xml_schema2') == ('xml_schema', 'xml_schema2')311 with pytest.raises(ValueError):312 NMTokensType().parse_value('\x0dtoken')313def test_NMTokensType_produce():314 assert NMTokensType().produce_value(('xml_schema',)) == 'xml_schema'315 assert NMTokensType().produce_value(('xml_schema', 'xml_schema2')) == 'xml_schema xml_schema2'316def test_NonNegativeIntegerType_parse():317 assert NonNegativeIntegerType().parse_value('255') == 255318def test_NonNegativeIntegerType_produce():319 assert NonNegativeIntegerType().produce_value(255) == '255'320def test_NonPositiveIntegerType_parse():321 assert NonPositiveIntegerType().parse_value('-255') == -255322def test_NonPositiveIntegerType_produce():323 assert NonPositiveIntegerType().produce_value(-255) == '-255'324def test_NormalizedStringType_parse():325 assert NormalizedStringType().parse_value('test_id_4') == 'test_id_4'326def test_NormalizedStringType_produce():327 assert NormalizedStringType().produce_value('test_id_4') == 'test_id_4'328def test_NotationType_parse():329 assert NotationType().parse_value('test_id_4') == 'test_id_4'330def test_NotationType_produce():331 assert NotationType().produce_value('test_id_4') == 'test_id_4'332def test_PositiveIntegerType_parse():333 assert PositiveIntegerType().parse_value('255') == 255334def test_PositiveIntegerType_produce():335 assert PositiveIntegerType().produce_value(255) == '255'336def test_QNameType_parse():337 assert QNameType().parse_value('test_id_4') == 'test_id_4'338def test_QNameType_produce():339 assert QNameType().produce_value('test_id_4') == 'test_id_4'340def test_ShortType_parse():341 assert ShortType().parse_value('255') == 255342def test_ShortType_produce():343 assert ShortType().produce_value(255) == '255'344def test_StringType_parse():345 assert StringType().parse_value('test') == 'test'346 with pytest.raises(TypeError):347 StringType().parse_value(2)348 with pytest.raises(TypeError):349 StringType().parse_value(2.0)350 with pytest.raises(TypeError):351 StringType().parse_value(StringType())352def test_StringType_produce():353 assert StringType().produce_value('255') == '255'354def test_TimeType_parse():355 assert TimeType().parse_value('12:42:42Z') == SevenPropertyModel(hour=12, minute=42, second=42, timezoneOffset=0)356def test_TimeType_produce():357 assert TimeType().produce_value(SevenPropertyModel(hour=12, minute=42, second=42, timezoneOffset=0)) == '12:42:42Z'358def test_TokenType_parse():359 assert TokenType().parse_value('test') == 'test'360def test_TokenType_produce():361 assert TokenType().produce_value('test') == 'test'362def test_UnsignedByteType_parse():363 assert UnsignedByteType().parse_value('255') == 255364def test_UnsignedByteType_produce():365 assert UnsignedByteType().produce_value(255) == '255'366def test_UnsignedIntType_parse():367 assert UnsignedIntType().parse_value('255') == 255368def test_UnsignedIntType_produce():369 assert UnsignedIntType().produce_value(255) == '255'370def test_UnsignedLongType_parse():371 assert UnsignedLongType().parse_value('255') == 255372def test_UnsignedLongType_produce():373 assert UnsignedLongType().produce_value(255) == '255'374def test_UnsignedShortType_parse():375 assert UnsignedShortType().parse_value('255') == 255376def test_UnsignedShortType_produce():377 assert UnsignedShortType().produce_value(255) == '255'378def test_YearMonthDurationType_parse():379 assert YearMonthDurationType().parse_value('P1Y1M') == (13, 0)380 assert YearMonthDurationType().parse_value('P1Y') == (12, 0.0)381 assert YearMonthDurationType().parse_value('P1M') == (1, 0.0)382 assert YearMonthDurationType().parse_value('-P1Y') == (-12, 0.0)383 assert YearMonthDurationType().parse_value('-P1M') == (-1, 0.0)384 with pytest.raises(ValueError):385 DayTimeDurationType().parse_value('P1Y1M1DT1H1M1.1S')386def test_YearMonthDurationType_produce():387 assert YearMonthDurationType().produce_value((13, 0)) == 'P1Y1M'388 assert YearMonthDurationType().produce_value((12, 0.0)) == 'P1Y'389 assert YearMonthDurationType().produce_value((1, 0.0)) == 'P1M'390 assert YearMonthDurationType().produce_value((-12, 0.0)) == '-P1Y'391 assert YearMonthDurationType().produce_value((-1, 0.0)) == '-P1M'392 with pytest.raises(ValueError):...

Full Screen

Full Screen

test_parser.py

Source:test_parser.py Github

copy

Full Screen

...40 expected_value = {'type': 0, 'ed25519': 'GAHLJSE6EQYQ3XE6UAUGWSB77JZNK7KBU4SIIIW4NY2GA2V5MMEV4LRB'}41 assert todict(public_key, False) == expected_value42def test_parse_value_int_starting_balance_raw_amount():43 from xdrparser.parser import parse_value44 assert parse_value(20000000, '.0.txSet.txs.0.tx.operations.0.body.createAccountOp.startingBalance',45 True) == 2000000046def test_parse_value_int_starting_balance_default():47 from xdrparser.parser import parse_value48 assert parse_value(20000000, '.0.txSet.txs.0.tx.operations.0.body.createAccountOp.startingBalance') == Decimal(200)49def test_parse_value_int_starting_balance_not_raw_amount():50 from xdrparser.parser import parse_value51 assert parse_value(20000000, '.0.txSet.txs.0.tx.operations.0.body.createAccountOp.startingBalance',52 False) == Decimal(200)53def test_parse_value_int_starting_balance_less_than_1():54 from xdrparser.parser import parse_value55 assert parse_value(200, '.0.txSet.txs.0.tx.operations.0.body.createAccountOp.startingBalance') == \56 Decimal((0, (0, 0, 2), -3))57def test_parse_value_int_payment_amount_default():58 from xdrparser.parser import parse_value59 assert parse_value(60000000, '.0.txSet.txs.8.tx.operations.0.body.paymentOp.amount') == Decimal(600)60def test_parse_value_int_other():61 from xdrparser.parser import parse_value62 assert parse_value(1000000, '.0.ledgerSeq') == 100000063def test_parse_value_bytes_text_final_key():64 from xdrparser.parser import parse_value65 assert parse_value(b'1-kik', '.0.txSet.txs.0.tx.memo.text') == '1-kik'66def test_parse_value_regular_bytes_hash():67 from xdrparser.parser import parse_value68 bytes_value = b'\x1cM\xa7~\xb28\x9f%\x04G~n\xfa\x80\xcd\x1b0T\xae\xe3>\xb6\xa4\xa3\x96\xb6\xfdJ\xbb(s\xb2'69 expected_result = '1c4da77eb2389f2504477e6efa80cd1b3054aee33eb6a4a396b6fd4abb2873b2'70 assert parse_value(bytes_value, '.0.txSet.previousLedgerHash') == expected_result71def test_parse_value_bytes_account():72 from xdrparser.parser import parse_value73 bytes_value = b'\x0e\xb4\xc8\x9e$1\r\xdc\x9e\xa0(kH?\xfar\xd5}A\xa7$\x84"\xdcn4`j\xbdc\t^'74 expected_result = 'GAHLJSE6EQYQ3XE6UAUGWSB77JZNK7KBU4SIIIW4NY2GA2V5MMEV4LRB'75 assert parse_value(bytes_value, '.0.txSet.txs.0.tx.sourceAccount.ed25519') == expected_result76def test_parse_value_bytes_hint():77 from xdrparser.parser import parse_value78 expected_result = 'G______________________________________________F5MME____'79 assert parse_value(b'\xbdc\t^', '.0.txSet.txs.0.signatures.0.hint') == expected_result80def test_parse_value_bytes_signature():81 from xdrparser.parser import parse_value82 signature = b'r\xc9\xd5\x8d\x16\x9c\x0e\t&\xf97\x08\xa8\x98i\xc4\x95\xab\xaf\xbc\x82Q\xad\xef,\x1d\xf2\xd2mS\xbau\x07\xd1\xacw\x97\xee-\xeb\x96\xc8\xaaX\x13\x87Zb\xc2\xc02i\xd1\x82\xd9\x00c\x90-Q\xc2l\xa3\n'83 expected_result = 'csnVjRacDgkm+TcIqJhpxJWrr7yCUa3vLB3y0m1TunUH0ax3l+4t65bIqlgTh1piwsAyadGC2QBjkC1RwmyjCg=='84 assert parse_value(signature, '.0.txSet.txs.0.signatures.0.signature') == expected_result85def test_parse_account():86 from xdrparser.parser import parse_account87 assert parse_account(b'\x0e\xb4\xc8\x9e$1\r\xdc\x9e\xa0(kH?\xfar\xd5}A\xa7$\x84"\xdcn4`j\xbdc\t^') == \88 'GAHLJSE6EQYQ3XE6UAUGWSB77JZNK7KBU4SIIIW4NY2GA2V5MMEV4LRB'89def test_parse_text():90 from xdrparser.parser import parse_text91 assert parse_text(b'1-kik') == '1-kik'92def test_parse_asset_code():93 from xdrparser.parser import parse_asset_code94 assert parse_asset_code(b'KIN') == 'KIN'95def test_parse_asset_code_remove_extra_bytes():96 from xdrparser.parser import parse_asset_code97 assert parse_asset_code(b'KIN\x00') == 'KIN'98def test_parse_hash():...

Full Screen

Full Screen

test_viewutil.py

Source:test_viewutil.py Github

copy

Full Screen

...14 self.runner1 = models.Runner.objects.create(name='trihex')15 self.runner2 = models.Runner.objects.create(name='PJ')16 def test_single_pk_fetch(self):17 self.assertEqual(18 parse_value(models.SpeedRun, 'event', self.event.pk), self.event19 )20 def test_single_pk_as_string_fetch(self):21 self.assertEqual(22 parse_value(models.SpeedRun, 'event', str(self.event.pk)), self.event23 )24 def test_single_natural_key_as_string_fetch(self):25 self.assertEqual(26 parse_value(models.SpeedRun, 'event', self.event.short), self.event27 )28 def test_single_natural_key_as_json_fetch(self):29 self.assertEqual(30 parse_value(models.SpeedRun, 'event', json.dumps(self.event.natural_key())),31 self.event,32 )33 def test_single_natural_key_as_string_create(self):34 runner = parse_value(35 models.Submission, 'runner', 'UraniumAnchor', self.super_user36 )37 self.assertTrue(runner.id)38 self.assertEqual(runner.name, 'UraniumAnchor')39 def test_single_natural_key_as_json_create(self):40 runner = parse_value(41 models.Submission, 'runner', '["UraniumAnchor"]', self.super_user42 )43 self.assertTrue(runner.id)44 self.assertEqual(runner.name, 'UraniumAnchor')45 def test_complex_natural_key_as_json_create(self):46 run = parse_value(47 models.Bid,48 'speedrun',49 '["Mega Man 3", ["%s"]]' % self.event.short,50 self.super_user,51 )52 self.assertTrue(run.id)53 self.assertEqual(run.name, 'Mega Man 3')54 self.assertEqual(run.event, self.event)55 def test_m2m_pk_csv_fetch(self):56 expected_runners = [self.runner1, self.runner2]57 runners = parse_value(58 models.SpeedRun, 'runners', ','.join(str(r.pk) for r in expected_runners)59 )60 self.assertEqual(runners, expected_runners)61 def test_m2m_pk_csv_bad_fetch(self):62 with self.assertRaises(models.Runner.DoesNotExist):63 parse_value(models.SpeedRun, 'runners', '1001,1002')64 def test_m2m_pk_json_fetch(self):65 expected_runners = [self.runner1, self.runner2]66 runners = parse_value(67 models.SpeedRun, 'runners', json.dumps([r.pk for r in expected_runners])68 )69 self.assertEqual(runners, expected_runners)70 def test_m2m_pk_json_bad_fetch(self):71 with self.assertRaises(models.Runner.DoesNotExist):72 parse_value(models.SpeedRun, 'runners', '[1001,1002]')73 def test_m2m_natural_key_csv_fetch(self):74 expected_runners = [self.runner1, self.runner2]75 runners = parse_value(76 models.SpeedRun, 'runners', ','.join(r.name for r in expected_runners)77 )78 self.assertEqual(runners, expected_runners)79 def test_m2m_natural_key_csv_bad_fetch(self):80 with self.assertRaises(models.Runner.DoesNotExist):81 parse_value(models.SpeedRun, 'runners', 'total,nonsense')82 def test_m2m_natural_key_flat_json_fetch(self):83 expected_runners = [self.runner1, self.runner2]84 runners = parse_value(85 models.SpeedRun, 'runners', json.dumps([r.name for r in expected_runners])86 )87 self.assertEqual(runners, expected_runners)88 def test_m2m_natural_key_flat_json_bad_fetch(self):89 with self.assertRaises(models.Runner.DoesNotExist):90 parse_value(models.SpeedRun, 'runners', '["total","nonsense"]')91 def test_m2m_natural_key_full_json_fetch(self):92 expected_runners = [self.runner1, self.runner2]93 runners = parse_value(94 models.SpeedRun,95 'runners',96 json.dumps([r.natural_key() for r in expected_runners]),97 )98 self.assertEqual(runners, expected_runners)99 def test_m2m_natural_key_full_json_bad_fetch(self):100 with self.assertRaises(models.Runner.DoesNotExist):...

Full Screen

Full Screen

custom_scalar.py

Source:custom_scalar.py Github

copy

Full Screen

1import sys2from dataclasses import dataclass3from typing import (4 Any,5 Callable,6 Mapping,7 NewType,8 Optional,9 Type,10 TypeVar,11 Union,12 overload,13)14from graphql import GraphQLScalarType15from strawberry.type import StrawberryType16from .utils.str_converters import to_camel_case17# in python 3.10+ NewType is a class18if sys.version_info >= (3, 10):19 _T = TypeVar("_T", bound=Union[type, NewType])20else:21 _T = TypeVar("_T", bound=type)22def identity(x):23 return x24@dataclass25class ScalarDefinition(StrawberryType):26 name: str27 description: Optional[str]28 specified_by_url: Optional[str]29 serialize: Optional[Callable]30 parse_value: Optional[Callable]31 parse_literal: Optional[Callable]32 # Optionally store the GraphQLScalarType instance so that we don't get33 # duplicates34 implementation: Optional[GraphQLScalarType] = None35 def copy_with(36 self, type_var_map: Mapping[TypeVar, Union[StrawberryType, type]]37 ) -> Union[StrawberryType, type]:38 return super().copy_with(type_var_map)39 @property40 def is_generic(self) -> bool:41 return False42class ScalarWrapper:43 _scalar_definition: ScalarDefinition44 def __init__(self, wrap):45 self.wrap = wrap46 def __call__(self, *args, **kwargs):47 return self.wrap(*args, **kwargs)48def _process_scalar(49 cls: Type[_T],50 *,51 name: Optional[str] = None,52 description: Optional[str] = None,53 specified_by_url: Optional[str] = None,54 serialize: Optional[Callable] = None,55 parse_value: Optional[Callable] = None,56 parse_literal: Optional[Callable] = None,57):58 name = name or to_camel_case(cls.__name__)59 wrapper = ScalarWrapper(cls)60 wrapper._scalar_definition = ScalarDefinition(61 name=name,62 description=description,63 specified_by_url=specified_by_url,64 serialize=serialize,65 parse_literal=parse_literal,66 parse_value=parse_value,67 )68 return wrapper69@overload70def scalar(71 *,72 name: Optional[str] = None,73 description: Optional[str] = None,74 specified_by_url: Optional[str] = None,75 serialize: Callable = identity,76 parse_value: Optional[Callable] = None,77 parse_literal: Optional[Callable] = None,78) -> Callable[[_T], _T]:79 ...80@overload81def scalar(82 cls: _T,83 *,84 name: Optional[str] = None,85 description: Optional[str] = None,86 specified_by_url: Optional[str] = None,87 serialize: Callable = identity,88 parse_value: Optional[Callable] = None,89 parse_literal: Optional[Callable] = None,90) -> _T:91 ...92# FIXME: We are tricking pyright into thinking that we are returning the given type93# here or else it won't let us use any custom scalar to annotate attributes in94# dataclasses/types. This should be properly solved when implementing StrawberryScalar95def scalar(96 cls=None,97 *,98 name: Optional[str] = None,99 description: Optional[str] = None,100 specified_by_url: Optional[str] = None,101 serialize: Callable = identity,102 parse_value: Optional[Callable] = None,103 parse_literal: Optional[Callable] = None,104) -> Any:105 """Annotates a class or type as a GraphQL custom scalar.106 Example usages:107 >>> strawberry.scalar(108 >>> datetime.date,109 >>> serialize=lambda value: value.isoformat(),110 >>> parse_value=datetime.parse_date111 >>> )112 >>> Base64Encoded = strawberry.scalar(113 >>> NewType("Base64Encoded", bytes),114 >>> serialize=base64.b64encode,115 >>> parse_value=base64.b64decode116 >>> )117 >>> @strawberry.scalar(118 >>> serialize=lambda value: ",".join(value.items),119 >>> parse_value=lambda value: CustomList(value.split(","))120 >>> )121 >>> class CustomList:122 >>> def __init__(self, items):123 >>> self.items = items124 """125 if parse_value is None:126 parse_value = cls127 def wrap(cls):128 return _process_scalar(129 cls,130 name=name,131 description=description,132 specified_by_url=specified_by_url,133 serialize=serialize,134 parse_value=parse_value,135 parse_literal=parse_literal,136 )137 if cls is None:138 return wrap...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python 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