mocks.mock_get

Here are the examples of the python api mocks.mock_get taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

Example 1

Project: DeepClassificationBot Source File: test_deepanimebot_classifiers.py
def test_fetch_cvimage_from_url(monkeypatch):
    with open(TEST_IMAGE_PATH, 'rb') as f:
        image = f.read()
    monkeypatch.setattr(requests, 'get', mocks.mock_get(image))
    image = classifiers.fetch_cvimage_from_url('this url is ignored')
    assert image is not None

Example 2

Project: DeepClassificationBot Source File: test_deepanimebot_classifiers.py
def test_url_classifier_classify(monkeypatch):
    with open(TEST_IMAGE_PATH, 'rb') as f:
        image = f.read()
    monkeypatch.setattr(requests, 'get', mocks.mock_get(image))
    url_classifier = create_url_classifier(monkeypatch)
    y = url_classifier.classify(TEST_IMAGE_PATH)
    assert isinstance(y, list)
    assert isinstance(y[0], deploy.Prediction)

Example 3

Project: DeepClassificationBot Source File: test_deepanimebot_classifiers.py
def test_remote_classifier_classify(monkeypatch):
    response = json.dumps(dict(y=[dict(rank=1, category='noein', probability=1.0)]))
    monkeypatch.setattr(requests, 'get', mocks.mock_get(response))
    classifier = classifiers.RemoteClassifier('base url')
    y = classifier.classify(url='param')
    assert isinstance(y, list)
    assert isinstance(y[0], deploy.Prediction)

Example 4

Project: DeepClassificationBot Source File: test_deepanimebot_classifiers.py
def test_remote_classifier_classify(monkeypatch):
    response = json.dumps(dict(error='something went wrong expectedly'))
    monkeypatch.setattr(requests, 'get', mocks.mock_get(response))
    classifier = classifiers.RemoteClassifier('base url')
    with pytest.raises(exc.RemoteError):
        classifier.classify(url='param')

Example 5

Project: DeepClassificationBot Source File: test_examples_anime_names.py
def test_top_n_shows(monkeypatch):
    for report, expected in [
            (two_shows, [
                {'id': '11770', 'name': 'Steins;Gate'},
                {'id': '10216', 'name': 'Fullmetal Alchemist: Brotherhood'}]),
            (no_shows, []),
    ]:
        monkeypatch.setattr(requests, 'get', mocks.mock_get(report))
        shows = anime_names.get_top_n_shows(100)
        assert shows['items'] == expected

Example 6

Project: DeepClassificationBot Source File: test_examples_anime_names.py
def test_list_characters(monkeypatch):
    for xml, expected in [
            (two_details, [
                {'anime_id': '11770', 'anime_name': 'Steins;Gate', 'name': 'Mayuri Shiina'},
                {'anime_id': '9701', 'anime_name': 'Clannad After Story', 'name': 'Fuuko Ibuki'},
            ]),
            (no_details, [])
    ]:
        monkeypatch.setattr(requests, 'get', mocks.mock_get(xml))
        shows = {
            'fields': ['show'],
            'items': [{'id': '11770'}, {'id': '10216'}],
        }
        characters = anime_names.list_characters(shows)['items']
        assert list(characters) == expected

Example 7

Project: DeepClassificationBot Source File: test_deepanimebot_classifiers.py
def test_fetch_cvimage_from_url_non_image(monkeypatch):
    monkeypatch.setattr(requests, 'get', mocks.mock_get('non-image string'))
    image = classifiers.fetch_cvimage_from_url('this url is ignored')
    assert image is None

Example 8

Project: DeepClassificationBot Source File: test_deepanimebot_classifiers.py
def test_fetch_cvimage_from_url_too_large(monkeypatch):
    monkeypatch.setattr(requests, 'get', mocks.mock_get('12'))
    with pytest.raises(ValueError):
        classifiers.fetch_cvimage_from_url('this url is ignored', maxsize=1)