Use pytest conventions consistently (#6337)
* Do not derive from unittest.TestCase (not needed for pytest) * assertRaises -> pytest.raises * Simplify test_empty_dmatrix with test parametrization * setUpClass -> setup_class, tearDownClass -> teardown_class * Don't import unittest; import pytest * Use plain assert * Use parametrized tests in more places * Fix test_gpu_with_sklearn.py * Put back run_empty_dmatrix_reg / run_empty_dmatrix_cls * Fix test_eta_decay_gpu_hist * Add parametrized tests for monotone constraints * Fix test names * Remove test parametrization * Revise test_slice to be not flaky
This commit is contained in:
committed by
GitHub
parent
c763b50dd0
commit
9c9070aea2
@@ -2,7 +2,6 @@
|
||||
import numpy as np
|
||||
import xgboost as xgb
|
||||
import testing as tm
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
try:
|
||||
@@ -18,7 +17,7 @@ dpath = 'demo/data/'
|
||||
rng = np.random.RandomState(1994)
|
||||
|
||||
|
||||
class TestModin(unittest.TestCase):
|
||||
class TestModin:
|
||||
|
||||
def test_modin(self):
|
||||
|
||||
@@ -43,7 +42,8 @@ class TestModin(unittest.TestCase):
|
||||
# incorrect dtypes
|
||||
df = md.DataFrame([[1, 2., 'x'], [2, 3., 'y']],
|
||||
columns=['a', 'b', 'c'])
|
||||
self.assertRaises(ValueError, xgb.DMatrix, df)
|
||||
with pytest.raises(ValueError):
|
||||
xgb.DMatrix(df)
|
||||
|
||||
# numeric columns
|
||||
df = md.DataFrame([[1, 2., True], [2, 3., False]])
|
||||
@@ -113,13 +113,13 @@ class TestModin(unittest.TestCase):
|
||||
def test_modin_label(self):
|
||||
# label must be a single column
|
||||
df = md.DataFrame({'A': ['X', 'Y', 'Z'], 'B': [1, 2, 3]})
|
||||
self.assertRaises(ValueError, xgb.data._transform_pandas_df, df,
|
||||
False, None, None, 'label', 'float')
|
||||
with pytest.raises(ValueError):
|
||||
xgb.data._transform_pandas_df(df, False, None, None, 'label', 'float')
|
||||
|
||||
# label must be supported dtype
|
||||
df = md.DataFrame({'A': np.array(['a', 'b', 'c'], dtype=object)})
|
||||
self.assertRaises(ValueError, xgb.data._transform_pandas_df, df,
|
||||
False, None, None, 'label', 'float')
|
||||
with pytest.raises(ValueError):
|
||||
xgb.data._transform_pandas_df(df, False, None, None, 'label', 'float')
|
||||
|
||||
df = md.DataFrame({'A': np.array([1, 2, 3], dtype=int)})
|
||||
result, _, _ = xgb.data._transform_pandas_df(df, False, None, None,
|
||||
|
||||
Reference in New Issue
Block a user