Skip to content

Commit 5cf54a4

Browse files
committed
update ci
1 parent 36ba2d6 commit 5cf54a4

6 files changed

Lines changed: 22 additions & 28 deletions

File tree

.github/build.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/python-package.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ jobs:
2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
30-
python -m pip install flake8 pytest
30+
python -m pip install flake8 tox
3131
- name: Lint with flake8
3232
run: |
3333
# stop the build if there are Python syntax errors or undefined names
3434
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3535
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3636
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37-
- name: Test with pytest
37+
- name: Test with tox
3838
run: |
39-
pytest
39+
tox

data_tutorials/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
>>> from data_tutorials.data import get_data
66
>>> get_data(url="my_file_url", filename="mycif", folder="data")
77
8-
98
"""
109

1110
from importlib.metadata import version

data_tutorials/data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from urllib.request import urlretrieve
88
from pathlib import Path
9+
# this is only for python 3.9 once done use str| list[str]
10+
from typing import Union
911

1012
default_url = "https://raw.githubusercontent.com/ddmms/data-tutorials/main/data/"
1113
def download_file(url: str, filename:str, dest: Path) -> None:
@@ -17,7 +19,7 @@ def download_file(url: str, filename:str, dest: Path) -> None:
1719
else:
1820
print(f"{save_file} could not be downloaded, check url.")
1921

20-
def get_data(url: str=default_url, filename: str| list[str] = "", folder: str="data") -> None:
22+
def get_data(url: str=default_url, filename: Union[str, list[str]] = "", folder: str="data") -> None:
2123
p = Path(folder)
2224
p.mkdir(parents=True, exist_ok=True)
2325
if isinstance(filename,str):

tests/test_file.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
def test_download_file():
1212
get_data(filename="LiFePO4_supercell.cif",folder="data-test")
1313
with open(Path("data-test")/"LiFePO4_supercell.cif", "rb") as fd:
14-
h = hashlib.file_digest(fd, "sha256")
14+
try:
15+
h = hashlib.file_digest(fd, "sha256")
16+
except AttributeError:
17+
h = hashlib.sha256()
18+
h.update(fd.read())
1519
assert h.hexdigest() == "ea9a538dde5bb84b92e9478dbcc078bb560b28a4f5e4b0469d416bff36be272e"
1620

1721
def test_download_files():
@@ -21,5 +25,9 @@ def test_download_files():
2125
get_data(filename=files,folder="data-test")
2226
for f in files:
2327
with open(Path("data-test")/f, "rb") as fd:
24-
h = hashlib.file_digest(fd, "sha256")
28+
try:
29+
h = hashlib.file_digest(fd, "sha256")
30+
except AttributeError:
31+
h = hashlib.sha256()
32+
h.update(fd.read())
2533
assert h.hexdigest() == sha256[f]

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[tox]
2+
envlist = py3
3+
4+
[testenv]
5+
deps = pytest
6+
commands = pytest

0 commit comments

Comments
 (0)