Skip to content

Commit 5befb11

Browse files
committed
add test
1 parent 7167ad7 commit 5befb11

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

data_tutorials/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
default_url = "https://raw.githubusercontent.com/ddmms/data-tutorials/main/data/"
1111
def download_file(url: str, filename:str, dest: Path) -> None:
1212
save_file = dest/filename
13-
path, headers = urlretrieve(url, dest)
13+
print(f"try to download {filename} from {url} and save it in {save_file}")
14+
path, headers = urlretrieve(url+filename, save_file)
1415
if path.exists():
1516
print(f"saved in {save_file}")
1617
else:

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ build-backend = "setuptools.build_meta"
66
[project]
77
name = "data-tutorials"
88
dynamic = ["version"]
9-
9+
dependencies = [
10+
"pytest",
11+
]
1012
requires-python = ">=3.9"
1113
authors = [
1214
{name = "Alin M Elena", email = "alin@elena.re"}
@@ -35,3 +37,8 @@ packages = ["data_tutorials"]
3537

3638
[tool.setuptools_scm]
3739

40+
41+
[tool.pytest.ini_options]
42+
pythonpath = [
43+
"."
44+
]

tests/test_file.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
# Author; alin m elena, alin@elena.re
3+
# Contribs;
4+
# Date: 26-07-2024
5+
# ©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
9+
from pathlib import Path
10+
11+
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 f:
14+
h = hashlib.file_digest(f, "sha256")
15+
assert h.hexdigest() == "ea9a538dde5bb84b92e9478dbcc078bb560b28a4f5e4b0469d416bff36be272e"

0 commit comments

Comments
 (0)