File: test_errors.py

package info (click to toggle)
python-pubchempy 1.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 648 kB
  • sloc: python: 1,619; makefile: 13; sh: 5
file content (36 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Test errors."""

import pytest

from pubchempy import (
    BadRequestError,
    Compound,
    NotFoundError,
    Substance,
    get_compounds,
    get_substances,
)


def test_invalid_identifier():
    """BadRequestError should be raised if identifier is not a positive integer."""
    with pytest.raises(BadRequestError):
        Compound.from_cid("aergaerhg")
    with pytest.raises(BadRequestError):
        get_compounds("srthrthsr")
    with pytest.raises(BadRequestError):
        get_substances("grgrqjksa")


def test_notfound_identifier():
    """NotFoundError should be raised if the record doesn't exist."""
    with pytest.raises(NotFoundError):
        Compound.from_cid(999999999)
    with pytest.raises(NotFoundError):
        Substance.from_sid(999999999)


def test_notfound_search():
    """No error should be raised if a search returns no results."""
    get_compounds(999999999)
    get_substances(999999999)