"src/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "5b355b00a38494de99dbe4bfcf280438b81aa98a"
Commit 5fd47b36 authored by Nikita Titov's avatar Nikita Titov Committed by Guolin Ke
Browse files

[test] slight C_API test refactoring (#1655)

* renamed functions

* updated find_lib function
parent f83e4aa4
...@@ -7,7 +7,6 @@ import sys ...@@ -7,7 +7,6 @@ import sys
from platform import system from platform import system
import numpy as np import numpy as np
import pytest
from scipy import sparse from scipy import sparse
...@@ -17,8 +16,13 @@ def find_lib_path(): ...@@ -17,8 +16,13 @@ def find_lib_path():
return [] return []
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
dll_path = [curr_path, os.path.join(curr_path, '../../'), os.path.join(curr_path, '../../lib/')] dll_path = [curr_path, os.path.join(curr_path, '../../'),
os.path.join(curr_path, '../../python-package/lightgbm/compile'),
os.path.join(curr_path, '../../python-package/compile'),
os.path.join(curr_path, '../../lib/')]
if system() in ('Windows', 'Microsoft'): if system() in ('Windows', 'Microsoft'):
dll_path.append(os.path.join(curr_path, '../../python-package/compile/Release/'))
dll_path.append(os.path.join(curr_path, '../../python-package/compile/windows/x64/DLL/'))
dll_path.append(os.path.join(curr_path, '../../Release/')) dll_path.append(os.path.join(curr_path, '../../Release/'))
dll_path.append(os.path.join(curr_path, '../../windows/x64/DLL/')) dll_path.append(os.path.join(curr_path, '../../windows/x64/DLL/'))
dll_path = [os.path.join(p, 'lib_lightgbm.dll') for p in dll_path] dll_path = [os.path.join(p, 'lib_lightgbm.dll') for p in dll_path]
...@@ -57,8 +61,7 @@ def c_str(string): ...@@ -57,8 +61,7 @@ def c_str(string):
return ctypes.c_char_p(string.encode('ascii')) return ctypes.c_char_p(string.encode('ascii'))
@pytest.mark.skip def load_from_file(filename, reference):
def test_load_from_file(filename, reference):
ref = None ref = None
if reference is not None: if reference is not None:
ref = reference ref = reference
...@@ -76,13 +79,11 @@ def test_load_from_file(filename, reference): ...@@ -76,13 +79,11 @@ def test_load_from_file(filename, reference):
return handle return handle
@pytest.mark.skip def save_to_binary(handle, filename):
def test_save_to_binary(handle, filename):
LIB.LGBM_DatasetSaveBinary(handle, c_str(filename)) LIB.LGBM_DatasetSaveBinary(handle, c_str(filename))
@pytest.mark.skip def load_from_csr(filename, reference):
def test_load_from_csr(filename, reference):
data = [] data = []
label = [] label = []
inp = open(filename, 'r') inp = open(filename, 'r')
...@@ -119,8 +120,7 @@ def test_load_from_csr(filename, reference): ...@@ -119,8 +120,7 @@ def test_load_from_csr(filename, reference):
return handle return handle
@pytest.mark.skip def load_from_csc(filename, reference):
def test_load_from_csc(filename, reference):
data = [] data = []
label = [] label = []
inp = open(filename, 'r') inp = open(filename, 'r')
...@@ -157,8 +157,7 @@ def test_load_from_csc(filename, reference): ...@@ -157,8 +157,7 @@ def test_load_from_csc(filename, reference):
return handle return handle
@pytest.mark.skip def load_from_mat(filename, reference):
def test_load_from_mat(filename, reference):
data = [] data = []
label = [] label = []
inp = open(filename, 'r') inp = open(filename, 'r')
...@@ -192,28 +191,27 @@ def test_load_from_mat(filename, reference): ...@@ -192,28 +191,27 @@ def test_load_from_mat(filename, reference):
return handle return handle
@pytest.mark.skip def free_dataset(handle):
def test_free_dataset(handle):
LIB.LGBM_DatasetFree(handle) LIB.LGBM_DatasetFree(handle)
def test_dataset(): def test_dataset():
train = test_load_from_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.train'), None) train = load_from_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.train'), None)
test = test_load_from_mat(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.test'), train) test = load_from_mat(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.test'), train)
test_free_dataset(test) free_dataset(test)
test = test_load_from_csr(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.test'), train) test = load_from_csr(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.test'), train)
test_free_dataset(test) free_dataset(test)
test = test_load_from_csc(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.test'), train) test = load_from_csc(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.test'), train)
test_free_dataset(test) free_dataset(test)
test_save_to_binary(train, 'train.binary.bin') save_to_binary(train, 'train.binary.bin')
test_free_dataset(train) free_dataset(train)
train = test_load_from_file('train.binary.bin', None) train = load_from_file('train.binary.bin', None)
test_free_dataset(train) free_dataset(train)
def test_booster(): def test_booster():
train = test_load_from_mat(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.train'), None) train = load_from_mat(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.train'), None)
test = test_load_from_mat(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.test'), train) test = load_from_mat(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../examples/binary_classification/binary.test'), train)
booster = ctypes.c_void_p() booster = ctypes.c_void_p()
LIB.LGBM_BoosterCreate(train, c_str("app=binary metric=auc num_leaves=31 verbose=0"), ctypes.byref(booster)) LIB.LGBM_BoosterCreate(train, c_str("app=binary metric=auc num_leaves=31 verbose=0"), ctypes.byref(booster))
LIB.LGBM_BoosterAddValidData(booster, test) LIB.LGBM_BoosterAddValidData(booster, test)
...@@ -227,8 +225,8 @@ def test_booster(): ...@@ -227,8 +225,8 @@ def test_booster():
print('%d Iteration test AUC %f' % (i, result[0])) print('%d Iteration test AUC %f' % (i, result[0]))
LIB.LGBM_BoosterSaveModel(booster, 0, -1, c_str('model.txt')) LIB.LGBM_BoosterSaveModel(booster, 0, -1, c_str('model.txt'))
LIB.LGBM_BoosterFree(booster) LIB.LGBM_BoosterFree(booster)
test_free_dataset(train) free_dataset(train)
test_free_dataset(test) free_dataset(test)
booster2 = ctypes.c_void_p() booster2 = ctypes.c_void_p()
num_total_model = ctypes.c_long() num_total_model = ctypes.c_long()
LIB.LGBM_BoosterCreateFromModelfile(c_str('model.txt'), ctypes.byref(num_total_model), ctypes.byref(booster2)) LIB.LGBM_BoosterCreateFromModelfile(c_str('model.txt'), ctypes.byref(num_total_model), ctypes.byref(booster2))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment