コード例 #1
0
def test_fetch_cvimage_from_url(monkeypatch):
    fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures', '1920x1080.png')
    with open(fixture_path, 'rb') as f:
        image = f.read()
    monkeypatch.setattr(requests, 'get', mocks.mock_get(image))
    image = bot.fetch_cvimage_from_url('this url is ignored')
    assert image is not None
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)
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)
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)
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)
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
コード例 #7
0
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 = name_extractor.get_top_n_shows(100)
        assert shows['items'] == expected
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
コード例 #9
0
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 = name_extractor.list_characters(shows)['items']
        assert list(characters) == expected
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')
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)
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
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
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')
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
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
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)