Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pubchempy.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ def get_all_sources(domain: str = "substance") -> list[str]:

def download(
outformat: str,
path: str,
path: str | os.PathLike,
identifier: str | int | list[str | int],
namespace: str = "cid",
domain: str = "compound",
Expand Down
33 changes: 9 additions & 24 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,23 @@

import csv
import os
import shutil
import tempfile

import pytest

from pubchempy import download


@pytest.fixture(scope="module")
def tmp_dir():
dir = tempfile.mkdtemp()
yield dir
shutil.rmtree(dir)
def test_image_download(tmp_path):
download("PNG", tmp_path / "aspirin.png", "Aspirin", "name")
with pytest.raises(OSError):
download("PNG", tmp_path / "aspirin.png", "Aspirin", "name")
download("PNG", tmp_path / "aspirin.png", "Aspirin", "name", overwrite=True)


def test_image_download(tmp_dir):
download("PNG", os.path.join(tmp_dir, "aspirin.png"), "Aspirin", "name")
with pytest.raises(IOError):
download("PNG", os.path.join(tmp_dir, "aspirin.png"), "Aspirin", "name")
download(
"PNG", os.path.join(tmp_dir, "aspirin.png"), "Aspirin", "name", overwrite=True
)


def test_csv_download(tmp_dir):
download(
"CSV",
os.path.join(tmp_dir, "s.csv"),
[1, 2, 3],
operation="property/ConnectivitySMILES,SMILES",
)
with open(os.path.join(tmp_dir, "s.csv")) as f:
def test_csv_download(tmp_path):
props = "property/ConnectivitySMILES,SMILES"
download("CSV", tmp_path / "s.csv", [1, 2, 3], operation=props)
with open(tmp_path / "s.csv") as f:
rows = list(csv.reader(f))
assert rows[0] == ["CID", "ConnectivitySMILES", "SMILES"]
assert rows[1][0] == "1"
Expand Down
Loading