File: test_errors.py

package info (click to toggle)
python-pubchempy 1.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: python: 1,377; makefile: 147
file content (41 lines) | stat: -rw-r--r-- 1,060 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
37
38
39
40
41
# -*- coding: utf-8 -*-
"""
test_errors
~~~~~~~~~~~~~

Test errors.

"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pytest

from pubchempy import *


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 identifier is a positive integer but 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)