示例#1
0
def test_preprocessor_error_message():
  """Tests whether the preprocessor returns a preprocessor error when there
  is a problem using the preprocessor
  """
  preprocessor = ArrayIndexer(np.array([[1.2, 3.3], [3.1, 3.2]]))

  # with tuples
  X = np.array([[[2, 3], [3, 3]], [[2, 3], [3, 2]]])
  # There are less samples than the max index we want to preprocess
  with pytest.raises(PreprocessorError):
    preprocess_tuples(X, preprocessor)

  # with points
  X = np.array([[1], [2], [3], [3]])
  with pytest.raises(PreprocessorError):
    preprocess_points(X, preprocessor)
示例#2
0
def test_preprocessor_error_message():
    """Tests whether the preprocessor returns a preprocessor error when there
  is a problem using the preprocessor
  """
    preprocessor = ArrayIndexer(np.array([[1.2, 3.3], [3.1, 3.2]]))

    # with tuples
    X = np.array([[[2, 3], [3, 3]], [[2, 3], [3, 2]]])
    # There are less samples than the max index we want to preprocess
    with pytest.raises(PreprocessorError):
        preprocess_tuples(X, preprocessor)

    # with points
    X = np.array([[1], [2], [3], [3]])
    with pytest.raises(PreprocessorError):
        preprocess_points(X, preprocessor)
示例#3
0
def test_preprocess_points_simple_example():
    """Test the preprocessor on very simple examples of points to ensure the
  result is as expected"""
    array = np.array([1, 2, 4])

    def fun(row):
        return [[1, 1], [3, 3], [4, 4]]

    expected_result = np.array([[1, 1], [3, 3], [4, 4]])

    assert (preprocess_points(array, fun) == expected_result).all()
示例#4
0
def test_preprocess_points_simple_example():
  """Test the preprocessor on very simple examples of points to ensure the
  result is as expected"""
  array = np.array([1, 2, 4])

  def fun(row):
    return [[1, 1], [3, 3], [4, 4]]

  expected_result = np.array([[1, 1],
                              [3, 3],
                              [4, 4]])

  assert (preprocess_points(array, fun) == expected_result).all()
示例#5
0
def test_check_classic_invalid_n_samples(estimator, context, load_points,
                                         preprocessor):
  """Checks that the right warning is printed if n_samples is too small"""
  points = load_points()
  msg = ("Found array with 2 sample(s) (shape={}) while a minimum of 3 "
         "is required{}.".format((preprocess_points(points,
                                                    preprocessor)
                                 if preprocessor is not None and
                                 points.ndim == 1 else
                                 points).shape,
                                 context))
  with pytest.raises(ValueError) as raised_error:
    check_input(points, type_of_inputs='classic', preprocessor=preprocessor,
                ensure_min_samples=3,
                estimator=estimator)
  assert str(raised_error.value) == msg
示例#6
0
def test_check_classic_invalid_n_samples(estimator, context, load_points,
                                         preprocessor):
    """Checks that the right warning is printed if n_samples is too small"""
    points = load_points()
    msg = ("Found array with 2 sample(s) (shape={}) while a minimum of 3 "
           "is required{}.".format((preprocess_points(points, preprocessor)
                                    if preprocessor is not None
                                    and points.ndim == 1 else points).shape,
                                   context))
    with pytest.raises(ValueError) as raised_error:
        check_input(points,
                    type_of_inputs='classic',
                    preprocessor=preprocessor,
                    ensure_min_samples=3,
                    estimator=estimator)
    assert str(raised_error.value) == msg