from __future__ import print_function
import sys
import traceback

sys.path.insert(1, "../../")
import h2o
from tests import pyunit_utils
import os
from h2o.exceptions import H2OResponseError


def test_parser_svmlight_column_skip_not_supported():
    print("Test that functions calling fail if skipped_columns is passed with svm file.")
    # generate a big frame with all datatypes and save it to svmlight
    nrow = 10
    ncol = 10
    seed = 12345

    f1 = h2o.create_frame(rows=nrow, cols=ncol, real_fraction=0.5, integer_fraction=0.5, missing_fraction=0.2,
                          has_response=False, seed=seed)
    f2 = h2o.create_frame(rows=nrow, cols=1, real_fraction=1, integer_fraction=0, missing_fraction=0,
                          has_response=False, seed=seed)
    f1.set_name(0, "target")
    f1 = f2.cbind(f1)

    tmpdir = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath('__file__')), "..", "results"))
    if not (os.path.isdir(tmpdir)):
        os.mkdir(tmpdir)
    savefilenamewithpath = os.path.join(tmpdir, 'out.svm')
    pyunit_utils.write_H2OFrame_2_SVMLight(savefilenamewithpath, f1)  # write h2o frame to svm format

    try:
        print("Test upload SVM file")
        h2o.upload_file(savefilenamewithpath, skipped_columns=[5])
        assert False, "Test should have thrown an exception due skipped_columns parameter is present"  # should have failed here
    except H2OResponseError:
        print("Test OK, finished with H2OResponseError")
        pass
    except Exception as e:
        assert False, "Test finish with unexpected exception." + str(e)

    try:
        print("Test import SVM file")
        h2o.import_file(savefilenamewithpath, skipped_columns=[5])
        assert False, "Test should have thrown an exception due skipped_columns parameter is present"  # should have failed here
    except H2OResponseError:
        print("Test OK, finished with H2OResponseError")
    except Exception as e:
        assert False, "Test finish with unexpected exception." + str(e)


if __name__ == "__main__":
    pyunit_utils.standalone_test(test_parser_svmlight_column_skip_not_supported)
else:
    test_parser_svmlight_column_skip_not_supported()

from __future__ import print_function
import sys
import traceback

sys.path.insert(1, "../../")
import h2o
from tests import pyunit_utils
import os
from h2o.exceptions import H2OResponseError


def test_parser_svmlight_column_skip_not_supported():
    print("Test that functions calling fail if skipped_columns is passed with svm file.")
    # generate a big frame with all datatypes and save it to svmlight
    nrow = 10
    ncol = 10
    seed = 12345

    f1 = h2o.create_frame(rows=nrow, cols=ncol, real_fraction=0.5, integer_fraction=0.5, missing_fraction=0.2,
                          has_response=False, seed=seed)

    tmpdir = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath('__file__')), "..", "results"))
    if not (os.path.isdir(tmpdir)):
        os.mkdir(tmpdir)
    savefilenamewithpath = os.path.join(tmpdir, 'out.svm')
    pyunit_utils.write_H2OFrame_2_SVMLight(savefilenamewithpath, f1)  # write h2o frame to svm format

    try:
        print("Test upload SVM file. "
              "Expected result is Java exception error: skipped_columns not supported for AVRO and SVMlight")
        h2o.upload_file(savefilenamewithpath, skipped_columns=[5])
        assert False, "Test should have thrown an exception due skipped_columns parameter is present"  # should have failed here
    except H2OResponseError as e:
        print("Test OK, finished with H2OResponseError")
        assert "skipped_columns are not supported" in str(e.args[0].exception_msg), "Exception message is different"

    try:
        print("Test import SVM file. "
              "Expected result is Java exception error: skipped_columns not supported for AVRO and SVMlight")
        h2o.import_file(savefilenamewithpath, skipped_columns=[5])
        assert False, "Test should have thrown an exception due skipped_columns parameter is present"  # should have failed here
    except H2OResponseError as e:
        print("Test OK, finished with H2OResponseError")
        assert "skipped_columns are not supported" in e.args[0].exception_msg


if __name__ == "__main__":
    pyunit_utils.standalone_test(test_parser_svmlight_column_skip_not_supported)
else:
    test_parser_svmlight_column_skip_not_supported()

Fix svm drop columns test - implement feedback from review