def test_keras_model_train():
    model = Mock()
    layer = Mock
    criterion = Mock()
    optimizer = Mock()
    metrics = Mock()

    sizes = [(1, 24, 24), (24, 10)]

    l1 = layer()
    l1.get_input_shape_at.return_value = sizes[0]
    l2 = layer()
    l2.get_output_shape_at.return_value = sizes[1]
    model.layers = [l1, l2]

    batch = 32
    epoch = 2
    kdpm = DeepLearningModel(model, criterion, optimizer, batch, epoch, metrics)

    num_data = 30
    data = np.array([np.random.rand(24, 24) for i in range(num_data)])
    labels = np.array([np.zeros(10) for i in range(num_data)])
    for l in labels:
        l[np.random.randint(0, len(l))] = 1

    kdpm.train(data, labels)

    kdpm._model.fit.assert_called_once()
    params = kdpm._model.fit.call_args_list[0][1]

    assert np.array_equal(params['x'], data)
    assert np.array_equal(params['y'], labels)
    assert params['batch_size'] == batch
    assert params['epochs'] == epoch
def test_train_wrong_data():
    model = Mock()
    layer = Mock
    criterion = Mock()
    optimizer = Mock()
    metrics = Mock()

    sizes = [(30, 24, 24), (24, 10)]

    l1 = layer()
    l1.get_input_shape_at.return_value = sizes[0]
    l2 = layer()
    l2.get_output_shape_at.return_value = sizes[1]
    model.layers = [l1, l2]

    batch = 32
    epoch = 2
    kdpl = DeepLearningModel(model, criterion, optimizer, batch, epoch, metrics)

    num_data = 30
    data = np.array([np.random.rand(16, 16) for i in range(num_data)])
    label = np.array([np.zeros(10) for i in range(num_data)])
    for l in label:
        l[np.random.randint(0, len(l))] = 1

    with pytest.raises(AssertionError):
        kdpl.train(data, label)

    data = np.array([np.random.rand(24, 24) for i in range(num_data)])
    label = np.array([np.zeros(8) for i in range(num_data)])
    for l in label:
        l[np.random.randint(0, len(l))] = 1
    with pytest.raises(AssertionError):
        kdpl.train(data, label)