# Path: deepanimebot/classifiers.py
# def fetch_cvimage_from_url(url, maxsize=10 * 1024 * 1024):
#     def classify(self, *args, **kwargs):
#     def __init__(self, dataset_path, input_shape, model_name='model'):
#     def classify(self, cvimage):
#     def __init__(self, image_classifier):
#     def classify(self, url=None):
#     def __init__(self, base_url):
#     def classify(self, **params):
# class MockClassifier(object):
# class ImageClassifier(object):
# class URLClassifier(object):
# class RemoteClassifier(object):
# 
# Path: deepanimebot/exceptions.py
# class NotImage(Exception): pass
# class RemoteError(Exception): pass


import os
import time
import json
import h5py
import cv2
import pytest
import requests
import six
import deploy
import data
import mocks
from multiprocessing import TimeoutError
from deepanimebot import classifiers
from deepanimebot import exceptions as exc
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_none(monkeypatch):
    monkeypatch.setattr(classifiers, 'fetch_cvimage_from_url', lambda url: None)
    url_classifier = create_url_classifier(monkeypatch)
    with pytest.raises(exc.NotImage):
        url_classifier.classify(TEST_IMAGE_PATH)


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(error='something went wrong expectedly'))
    monkeypatch.setattr(requests, 'get', mocks.mock_get(response))
    classifier = classifiers.RemoteClassifier('base url')

# Path: deepanimebot/classifiers.py
# def fetch_cvimage_from_url(url, maxsize=10 * 1024 * 1024):
#     def classify(self, *args, **kwargs):
#     def __init__(self, dataset_path, input_shape, model_name='model'):
#     def classify(self, cvimage):
#     def __init__(self, image_classifier):
#     def classify(self, url=None):
#     def __init__(self, base_url):
#     def classify(self, **params):
# class MockClassifier(object):
# class ImageClassifier(object):
# class URLClassifier(object):
# class RemoteClassifier(object):
# 
# Path: deepanimebot/exceptions.py
# class NotImage(Exception): pass
# class RemoteError(Exception): pass


# Path: tests/test_deepanimebot_classifiers.py
import os
import time
import json
import h5py
import cv2
import pytest
import requests
import six
import deploy
import data
import mocks
from multiprocessing import TimeoutError
from deepanimebot import classifiers
from deepanimebot import exceptions as exc

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_none(monkeypatch):
    monkeypatch.setattr(classifiers, 'fetch_cvimage_from_url', lambda url: None)
    url_classifier = create_url_classifier(monkeypatch)
    with pytest.raises(exc.NotImage):
        url_classifier.classify(TEST_IMAGE_PATH)


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(error='something went wrong expectedly'))
    monkeypatch.setattr(requests, 'get', mocks.mock_get(response))
    classifier = classifiers.RemoteClassifier('base url')

    with pytest.raises(exc.RemoteError):