|
1 | | -# -*- coding: utf-8 -*- |
2 | 1 | # Author; alin m elena, alin@elena.re |
3 | 2 | # Contribs; |
4 | 3 | # Date: 26-07-2024 |
5 | 4 | # ©alin m elena, GPL v3 https://www.gnu.org/licenses/gpl-3.0.en.html |
6 | | -import pytest |
7 | | -from data_tutorials.data import get_data |
8 | | -import hashlib |
| 5 | + |
| 6 | +""" |
| 7 | +Tests various downloads. |
| 8 | +""" |
| 9 | + |
9 | 10 | from pathlib import Path |
| 11 | +import hashlib |
| 12 | +from data_tutorials.data import get_data |
| 13 | + |
10 | 14 |
|
11 | 15 | def test_download_file(): |
12 | | - get_data(filename="LiFePO4_supercell.cif",folder="data-test") |
13 | | - with open(Path("data-test")/"LiFePO4_supercell.cif", "rb") as fd: |
14 | | - try: |
15 | | - h = hashlib.file_digest(fd, "sha256") |
16 | | - except AttributeError: |
17 | | - h = hashlib.sha256() |
18 | | - h.update(fd.read()) |
19 | | - assert h.hexdigest() == "ea9a538dde5bb84b92e9478dbcc078bb560b28a4f5e4b0469d416bff36be272e" |
| 16 | + get_data(filename="LiFePO4_supercell.cif", folder="data-test") |
| 17 | + with open(Path("data-test") / "LiFePO4_supercell.cif", "rb") as fd: |
| 18 | + try: |
| 19 | + h = hashlib.file_digest(fd, "sha256") |
| 20 | + except AttributeError: |
| 21 | + h = hashlib.sha256() |
| 22 | + h.update(fd.read()) |
| 23 | + assert ( |
| 24 | + h.hexdigest() |
| 25 | + == "ea9a538dde5bb84b92e9478dbcc078bb560b28a4f5e4b0469d416bff36be272e" |
| 26 | + ) |
| 27 | + |
20 | 28 |
|
21 | 29 | def test_download_files(): |
22 | | - files = ["LiFePO4_supercell.cif","h2o.xyz"] |
23 | | - sha256={'LiFePO4_supercell.cif':"ea9a538dde5bb84b92e9478dbcc078bb560b28a4f5e4b0469d416bff36be272e", |
24 | | - 'h2o.xyz': "522ab1d36d213e48ab6e08517ec3f648c378d4b9efd257feadc64a1d8f3e66d6"} |
25 | | - get_data(filename=files,folder="data-test") |
26 | | - for f in files: |
27 | | - with open(Path("data-test")/f, "rb") as fd: |
28 | | - try: |
29 | | - h = hashlib.file_digest(fd, "sha256") |
30 | | - except AttributeError: |
31 | | - h = hashlib.sha256() |
32 | | - h.update(fd.read()) |
33 | | - assert h.hexdigest() == sha256[f] |
| 30 | + files = ["LiFePO4_supercell.cif", "h2o.xyz"] |
| 31 | + sha256 = { |
| 32 | + "LiFePO4_supercell.cif": "ea9a538dde5bb84b92e9478dbcc078bb560b28a4f5e4b0469d416bff36be272e", |
| 33 | + "h2o.xyz": "522ab1d36d213e48ab6e08517ec3f648c378d4b9efd257feadc64a1d8f3e66d6", |
| 34 | + } |
| 35 | + get_data(filename=files, folder="data-test") |
| 36 | + for f in files: |
| 37 | + with open(Path("data-test") / f, "rb") as fd: |
| 38 | + try: |
| 39 | + h = hashlib.file_digest(fd, "sha256") |
| 40 | + except AttributeError: |
| 41 | + h = hashlib.sha256() |
| 42 | + h.update(fd.read()) |
| 43 | + assert h.hexdigest() == sha256[f] |
0 commit comments