How to use _get_hash_from_file method in avocado

Best Python code snippet using avocado_python

test_download_hashes.py

Source:test_download_hashes.py Github

copy

Full Screen

...6from tests.lib import packages7def test_get_hash_from_file_md5():8 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")9 file_link = Link("http://testserver/gmpy-1.15.tar.gz#md5=d41d8cd98f00b204e9800998ecf8427e")10 download_hash = _get_hash_from_file(file_path, file_link)11 assert download_hash.digest_size == 1612 assert download_hash.hexdigest() == "d41d8cd98f00b204e9800998ecf8427e"13def test_get_hash_from_file_sha1():14 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")15 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709")16 download_hash = _get_hash_from_file(file_path, file_link)17 assert download_hash.digest_size == 2018 assert download_hash.hexdigest() == "da39a3ee5e6b4b0d3255bfef95601890afd80709"19def test_get_hash_from_file_sha224():20 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")21 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha224=d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f")22 download_hash = _get_hash_from_file(file_path, file_link)23 assert download_hash.digest_size == 2824 assert download_hash.hexdigest() == "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"25def test_get_hash_from_file_sha384():26 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")27 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha384=38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b")28 download_hash = _get_hash_from_file(file_path, file_link)29 assert download_hash.digest_size == 4830 assert download_hash.hexdigest() == "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"31def test_get_hash_from_file_sha256():32 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")33 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")34 download_hash = _get_hash_from_file(file_path, file_link)35 assert download_hash.digest_size == 3236 assert download_hash.hexdigest() == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"37def test_get_hash_from_file_sha512():38 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")39 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha512=cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")40 download_hash = _get_hash_from_file(file_path, file_link)41 assert download_hash.digest_size == 6442 assert download_hash.hexdigest() == "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"43def test_get_hash_from_file_unknown():44 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")45 file_link = Link("http://testserver/gmpy-1.15.tar.gz#unknown_hash=d41d8cd98f00b204e9800998ecf8427e")46 download_hash = _get_hash_from_file(file_path, file_link)47 assert download_hash is None48def test_check_hash_md5_valid():49 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")50 file_link = Link("http://testserver/gmpy-1.15.tar.gz#md5=d41d8cd98f00b204e9800998ecf8427e")51 download_hash = _get_hash_from_file(file_path, file_link)52 _check_hash(download_hash, file_link)53def test_check_hash_md5_invalid():54 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")55 file_link = Link("http://testserver/gmpy-1.15.tar.gz#md5=deadbeef")56 download_hash = _get_hash_from_file(file_path, file_link)57 assert_raises(InstallationError, _check_hash, download_hash, file_link)58def test_check_hash_sha1_valid():59 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")60 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709")61 download_hash = _get_hash_from_file(file_path, file_link)62 _check_hash(download_hash, file_link)63def test_check_hash_sha1_invalid():64 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")65 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha1=deadbeef")66 download_hash = _get_hash_from_file(file_path, file_link)67 assert_raises(InstallationError, _check_hash, download_hash, file_link)68def test_check_hash_sha224_valid():69 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")70 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha224=d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f'")71 download_hash = _get_hash_from_file(file_path, file_link)72 _check_hash(download_hash, file_link)73def test_check_hash_sha224_invalid():74 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")75 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha224=deadbeef")76 download_hash = _get_hash_from_file(file_path, file_link)77 assert_raises(InstallationError, _check_hash, download_hash, file_link)78def test_check_hash_sha384_valid():79 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")80 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha384=38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b")81 download_hash = _get_hash_from_file(file_path, file_link)82 _check_hash(download_hash, file_link)83def test_check_hash_sha384_invalid():84 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")85 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha384=deadbeef")86 download_hash = _get_hash_from_file(file_path, file_link)87 assert_raises(InstallationError, _check_hash, download_hash, file_link)88def test_check_hash_sha256_valid():89 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")90 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")91 download_hash = _get_hash_from_file(file_path, file_link)92 _check_hash(download_hash, file_link)93def test_check_hash_sha256_invalid():94 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")95 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha256=deadbeef")96 download_hash = _get_hash_from_file(file_path, file_link)97 assert_raises(InstallationError, _check_hash, download_hash, file_link)98def test_check_hash_sha512_valid():99 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")100 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha512=cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")101 download_hash = _get_hash_from_file(file_path, file_link)102 _check_hash(download_hash, file_link)103def test_check_hash_sha512_invalid():104 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")105 file_link = Link("http://testserver/gmpy-1.15.tar.gz#sha512=deadbeef")106 download_hash = _get_hash_from_file(file_path, file_link)107 assert_raises(InstallationError, _check_hash, download_hash, file_link)108def test_check_hasher_mismsatch():109 file_path = os.path.join(packages, "gmpy-1.15.tar.gz")110 file_link = Link("http://testserver/gmpy-1.15.tar.gz#md5=d41d8cd98f00b204e9800998ecf8427e")111 other_link = Link("http://testserver/gmpy-1.15.tar.gz#sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")112 download_hash = _get_hash_from_file(file_path, file_link)...

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 avocado 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