How to use test_to_script method in pandera

Best Python code snippet using pandera_python

test_address.py

Source:test_address.py Github

copy

Full Screen

...94 assert address.to_string() == '1LXnPYpHTwQeWfBVnQZ4yDP23b57NwoyrP'95 raw = address.to_script_bytes()96 assert isinstance(raw, bytes)97 assert raw.hex() == '76a914d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c088ac'98 def test_to_script(self):99 address = P2PKH_Address(bytes.fromhex('d63cc1e3b6009e31d03bd5f8046cbe0f7e37e8c0'), Bitcoin)100 S = address.to_script()101 assert isinstance(S, Script)102 assert S == address.to_script_bytes()103 assert isinstance(classify_output_script(S, Bitcoin), P2PKH_Address)104 def test_hashable(self):105 {P2PKH_Address(bytes(20), Bitcoin)}106 def test_eq(self):107 address = P2PKH_Address(int_to_be_bytes(1, 20), Bitcoin)108 assert address == P2PKH_Address(int_to_be_bytes(1, 20), Bitcoin)109 assert address == P2PKH_Address(int_to_be_bytes(1, 20), BitcoinTestnet)110 assert address != '11111111111111111111BZbvjr'111 assert address != P2SH_Address(int_to_be_bytes(1, 20), Bitcoin)112class TestP2SH_Address:113 def test_constructor(self):114 address = P2SH_Address(bytes(20), Bitcoin)115 assert address.to_string() == '31h1vYVSYuKP6AhS86fbRdMw9XHieotbST'116 def test_constructor_bad(self):117 with pytest.raises(TypeError):118 P2SH_Address(bytes(20))119 with pytest.raises(TypeError):120 P2SH_Address(bytearray(20), Bitcoin)121 with pytest.raises(ValueError):122 P2SH_Address(bytes(21), Bitcoin)123 with pytest.raises(ValueError):124 P2SH_Address(bytes(19), Bitcoin)125 def test_coin(self):126 address = P2SH_Address(bytes(20), BitcoinTestnet)127 assert address.coin() is BitcoinTestnet128 def test_hash160(self):129 data = os.urandom(20)130 assert P2SH_Address(data, Bitcoin).hash160() is data131 def test_to_string(self):132 address = P2SH_Address(int_to_be_bytes(1, 20), Bitcoin)133 assert address.to_string() == '31h1vYVSYuKP6AhS86fbRdMw9XHiiQ93Mb'134 address = P2SH_Address(int_to_be_bytes(1, 20), BitcoinTestnet)135 assert address.to_string() == '2MsFDzHRUAMpjHxKyoEHU3aMCMsVtXMsfu8'136 def test_to_script_bytes(self):137 address = P2SH_Address(bytes.fromhex('ca9f1c4998bf46f66af34d949d8a8f189b6675b5'), Bitcoin)138 assert address.to_string() == '3LAP2V4pNJhZ11gwAFUZsDnvXDcyeeaQM5'139 raw = address.to_script_bytes()140 assert isinstance(raw, bytes)141 assert raw.hex() == 'a914ca9f1c4998bf46f66af34d949d8a8f189b6675b587'142 def test_to_script(self):143 address = P2SH_Address(bytes.fromhex('ca9f1c4998bf46f66af34d949d8a8f189b6675b5'), Bitcoin)144 S = address.to_script()145 assert isinstance(S, Script)146 assert S == address.to_script_bytes()147 assert isinstance(classify_output_script(S, Bitcoin), P2SH_Address)148 def test_hashable(self):149 {P2SH_Address(bytes(20), Bitcoin)}150 def test_eq(self):151 address = P2SH_Address(int_to_be_bytes(1, 20), Bitcoin)152 assert address == P2SH_Address(int_to_be_bytes(1, 20), Bitcoin)153 assert address != '31h1vYVSYuKP6AhS86fbRdMw9XHiiQ93Mb'154 assert address != P2PKH_Address(int_to_be_bytes(1, 20), Bitcoin)155class TestP2PK_Output:156 def test_constructor_bad(self):157 with pytest.raises(ValueError):158 P2PK_Output(b'', Bitcoin)159 def test_constructor_hex(self):160 h = '0363f75554e05e05a04551e59d78d78965ec6789f42199f7cbaa9fa4bd2df0a4b4'161 p = P2PK_Output(h, Bitcoin)162 assert p.public_key.to_hex() == h163 def test_eq(self):164 p = PrivateKey.from_random().public_key165 assert P2PK_Output(p, Bitcoin) == P2PK_Output(p, Bitcoin)166 assert P2PK_Output(p, Bitcoin) != p167 def test_hashable(self):168 p = PrivateKey.from_random().public_key169 {P2PK_Output(p, Bitcoin)}170 def test_hash160(self):171 pubkey_hex = '0363f75554e05e05a04551e59d78d78965ec6789f42199f7cbaa9fa4bd2df0a4b4'172 pubkey = PublicKey.from_hex(pubkey_hex)173 output = P2PK_Output(pubkey, Bitcoin)174 assert output.hash160() == hash160(bytes.fromhex(pubkey_hex))175 def test_to_script_bytes(self):176 pubkey_hex = '0363f75554e05e05a04551e59d78d78965ec6789f42199f7cbaa9fa4bd2df0a4b4'177 pubkey = PublicKey.from_hex(pubkey_hex)178 output = P2PK_Output(pubkey, Bitcoin)179 raw = output.to_script_bytes()180 assert isinstance(raw, bytes)181 assert raw == push_item(bytes.fromhex(pubkey_hex)) + pack_byte(OP_CHECKSIG)182 def test_to_script(self):183 pubkey_hex = '0363f75554e05e05a04551e59d78d78965ec6789f42199f7cbaa9fa4bd2df0a4b4'184 pubkey = PublicKey.from_hex(pubkey_hex)185 output = P2PK_Output(pubkey, Bitcoin)186 S = output.to_script()187 assert isinstance(S, Script)188 assert S == output.to_script_bytes()189 assert isinstance(classify_output_script(S, Bitcoin), P2PK_Output)190 def test_to_address_compressed(self):191 pubkey_hex = '036d6caac248af96f6afa7f904f550253a0f3ef3f5aa2fe6838a95b216691468e2'192 pubkey = PublicKey.from_hex(pubkey_hex)193 output = P2PK_Output(pubkey, Bitcoin)194 address = output.to_address()195 assert isinstance(address, P2PKH_Address)196 assert address.to_string() == '16ZbRYV2f1NNuNQ9FDYyUMC2d1cjGS2G3L'197 def test_to_address_uncompressed(self):198 pubkey_hex = (199 '046d6caac248af96f6afa7f904f550253a0f3ef3f5aa2fe6838a95b216691468e'200 '2487e6222a6664e079c8edf7518defd562dbeda1e7593dfd7f0be285880a24dab'201 )202 pubkey = PublicKey.from_hex(pubkey_hex)203 output = P2PK_Output(pubkey, Bitcoin)204 address = output.to_address()205 assert isinstance(address, P2PKH_Address)206 assert address.to_string() == '1G9f5Kdd5A8MeBN8jduUNfcAXUVvtFxVhP'207MS_PUBKEYS = [PrivateKey.from_random().public_key for n in range(5)]208multisig_scriptsig = (209 '004830450221009a8f3f87228213a66525137b59bb9884c5a6fce43128f0eaf81082c50b99c07b022030a2a4'210 '5a7b75b9d691370afc0e790ad17d971cfccb3da9c236e9aaa316973d0c41483045022100928b6b9b5e0d063f'211 'ff02d74a7fcc2fcc2ea5a9a1d4cf4e241302979fe0b976d102203f4aeac2959cf4f91742720c0c77b66c4883'212 '34d56e45486aecf46599af1f204941'213)214p2sh_multisig_scriptsig = (215 '004830450221009a8f3f87228213a66525137b59bb9884c5a6fce43128f0eaf81082c50b99c07b022030a2a4'216 '5a7b75b9d691370afc0e790ad17d971cfccb3da9c236e9aaa316973d0c41483045022100928b6b9b5e0d063f'217 'ff02d74a7fcc2fcc2ea5a9a1d4cf4e241302979fe0b976d102203f4aeac2959cf4f91742720c0c77b66c4883'218 '34d56e45486aecf46599af1f204941475221022812701688bc76ef3610b46c8e97f4b385241d5ed6eab6269b'219 '8af5f9bfd5a89c2103fa0879c543ac97f34daffdaeed808f3500811aa5070e4a1f7e2daed3dd22ef2052ae'220)221class TestP2MultiSig_Output:222 @pytest.mark.parametrize("threshold, count",223 [(m + 1, n + 1) for n in range(len(MS_PUBKEYS)) for m in range(n)]224 )225 def test_to_script_bytes(self, threshold, count):226 output = P2MultiSig_Output(MS_PUBKEYS[:count], threshold)227 assert output.public_key_count() == count228 raw = output.to_script_bytes()229 assert isinstance(raw, bytes)230 assert raw == b''.join((231 push_int(threshold),232 b''.join(push_item(public_key.to_bytes()) for public_key in MS_PUBKEYS[:count]),233 push_int(count),234 pack_byte(OP_CHECKMULTISIG),235 ))236 S = output.to_script()237 assert isinstance(S, Script)238 assert S == raw239 def test_constructor_copies(self):240 public_keys = list(MS_PUBKEYS[:2])241 script = P2MultiSig_Output(public_keys, 2)242 assert script.public_keys is not public_keys243 def test_eq(self):244 assert P2MultiSig_Output(MS_PUBKEYS[:1], 1) != P2MultiSig_Output(MS_PUBKEYS[:2], 1)245 assert P2MultiSig_Output(MS_PUBKEYS[:2], 1) != P2MultiSig_Output(MS_PUBKEYS[:2], 2)246 assert P2MultiSig_Output(MS_PUBKEYS[:2], 2) == P2MultiSig_Output(MS_PUBKEYS[:2], 2)247 def test_hashable(self):248 {P2MultiSig_Output(MS_PUBKEYS, 1)}249 def test_constructor_bad(self):250 with pytest.raises(ValueError):251 P2MultiSig_Output(MS_PUBKEYS + [b''], 2)252 with pytest.raises(ValueError):253 P2MultiSig_Output(MS_PUBKEYS, 0)254 with pytest.raises(ValueError):255 P2MultiSig_Output(MS_PUBKEYS, len(MS_PUBKEYS) + 1)256 @pytest.mark.parametrize("threshold, count",257 [(m + 1, n + 1) for n in range(len(MS_PUBKEYS)) for m in range(n)]258 )259 def test_from_template(self, threshold, count):260 good_output = P2MultiSig_Output(MS_PUBKEYS[:count], threshold)261 public_keys = [public_key.to_bytes() for public_key in MS_PUBKEYS[:count]]262 output = P2MultiSig_Output.from_template(pack_byte(threshold), *public_keys,263 pack_byte(count))264 assert list(output.public_keys) == MS_PUBKEYS[:count]265 assert output.threshold == threshold266 assert output == good_output267 def test_hash160(self):268 output = P2MultiSig_Output(MS_PUBKEYS, 1)269 assert output.hash160() == hash160(output.to_script_bytes())270 def test_from_template_bad(self):271 public_keys = [PrivateKey.from_random().public_key.to_bytes() for n in range(2)]272 with pytest.raises(ValueError):273 script = P2MultiSig_Output.from_template(pack_byte(1), *public_keys, pack_byte(1))274 with pytest.raises(ValueError):275 script = P2MultiSig_Output.from_template(pack_byte(1), *public_keys, pack_byte(3))276MS_SIGS = [bytes.fromhex(sig_hex) for sig_hex in (277 '30450221009a8f3f87228213a66525137b59bb9884c5a6fce43128f0eaf81082c50b99c07b022030a2a45a7b75b9d691370afc0e790ad17d971cfccb3da9c236e9aaa316973d0c41',278 '3045022100928b6b9b5e0d063fff02d74a7fcc2fcc2ea5a9a1d4cf4e241302979fe0b976d102203f4aeac2959cf4f91742720c0c77b66c488334d56e45486aecf46599af1f204941',279)]280class TestOP_RETURN_Output:281 def test_eq(self):282 assert OP_RETURN_Output() == OP_RETURN_Output()283 assert OP_RETURN_Output() != 2284 def test_hashable(self):285 {OP_RETURN_Output()}286 def test_to_script_bytes(self):287 raw = OP_RETURN_Output().to_script_bytes()288 assert isinstance(raw, bytes)289 assert raw == bytes([OP_RETURN])290 def test_to_script(self):291 S = OP_RETURN_Output().to_script()292 assert isinstance(S, Script)293 assert S == bytes([OP_RETURN])294 def test_from_template(self):295 output = OP_RETURN_Output.from_template(b'', b'bab')296 assert output == OP_RETURN_Output()297class TestUnknown_Output:298 def test_eq(self):299 a = Unknown_Output()300 assert a != Unknown_Output()301 assert a == a302 def test_hashable(self):303 {Unknown_Output()}304 def test_to_script_bytes(self):305 with pytest.raises(RuntimeError):306 Unknown_Output().to_script_bytes()307 def test_to_script(self):308 with pytest.raises(RuntimeError):309 Unknown_Output().to_script()310class TestClassification:311 def test_P2PKH(self):312 script_hex = '76a914a6dbba870185ab6689f386a40522ae6cb5c7b61a88ac'313 s = Script.from_hex(script_hex)314 sc = classify_output_script(s, Bitcoin)315 assert isinstance(sc, P2PKH_Address)316 prefix = push_item(b'foobar') + pack_byte(OP_DROP) + pack_byte(OP_NOP)317 s2 = Script.from_hex(prefix.hex() + script_hex)318 sc2 = classify_output_script(s2, Bitcoin)319 assert s2 != s320 assert isinstance(sc2, P2PKH_Address)321 def test_P2SH(self):...

Full Screen

Full Screen

test_tleed.py

Source:test_tleed.py Github

copy

Full Screen

...53 ],54 # Unit cell parameters55 [3.7676, 3.7676, 5.5180]56)57def test_to_script():58 struct = TEST_STRUCT59 with open("test/test_files/fese_answer.txt", "r") as f:60 answer = f.read()61 assert struct.to_script() == answer62def test_write_script():63 struct = TEST_STRUCT64 basedir = "test/test_files/FeSetest/"65 exe = os.path.join(basedir, "ref-calc.FeSe")66 rfact = os.path.join(basedir, "rf.x")67 template = os.path.join(basedir, "FIN")68 with open(template, "r") as f:69 answer = f.read()70 refcalc = tleed.RefCalc(struct, exe, answer, basedir)71 refcalc._write_script("test/test_files/FeSetest/comp_FIN")...

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run pandera 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