diff --git a/tests/test_files/test.csv b/tests/test_files/test.csv new file mode 100644 index 0000000..0702d44 --- /dev/null +++ b/tests/test_files/test.csv @@ -0,0 +1,19 @@ +"Name", "Sex", "Age", "Height (in)", "Weight (lbs)" +"Alex", "M", 41, 74, 170 +"Bert", "M", 42, 68, 166 +"Carl", "M", 32, 70, 155 +"Dave", "M", 39, 72, 167 +"Elly", "F", 30, 66, 124 +"Fran", "F", 33, 66, 115 +"Gwen", "F", 26, 64, 121 +"Hank", "M", 30, 71, 158 +"Ivan", "M", 53, 72, 175 +"Jake", "M", 32, 69, 143 +"Kate", "F", 47, 69, 139 +"Luke", "M", 34, 72, 163 +"Myra", "F", 23, 62, 98 +"Neil", "M", 36, 75, 160 +"Omar", "M", 38, 70, 145 +"Page", "F", 31, 67, 135 +"Quin", "M", 29, 71, 176 +"Ruth", "F", 28, 65, 131 \ No newline at end of file diff --git a/tests/test_ppsql_hiveconnection.py b/tests/test_ppsql_hiveconnection.py new file mode 100644 index 0000000..de46d41 --- /dev/null +++ b/tests/test_ppsql_hiveconnection.py @@ -0,0 +1,13 @@ +from ppextensions.ppsql.connection.hiveconnection import HiveConnection +from thriftpy.transport import TTransportException +import unittest + +class TestPPSqlHiveConnection(unittest.TestCase): + + def test_invalid_hive_connection(self): + with self.assertRaises(TTransportException): + hc = HiveConnection("fake", "fake", 1234, "GSSAPI", "fake") + self.assertTrue(hc != None) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_pputils_configuration.py b/tests/test_pputils_configuration.py new file mode 100644 index 0000000..247161c --- /dev/null +++ b/tests/test_pputils_configuration.py @@ -0,0 +1,18 @@ +from ppextensions.pputils.utils.configuration import * +import unittest + +class TestPPUtilsConfiguration(unittest.TestCase): + + def setUp(self): + pass + + def test_load_config(self): + conf = load_conf(PATH) + self.assertTrue(isinstance(conf, dict)) + + def test_conf_info(self): + config_info = conf_info("test-engine") + self.assertTrue(isinstance(config_info, dict)) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_pputils_csvconnection.py b/tests/test_pputils_csvconnection.py new file mode 100644 index 0000000..79a0bdb --- /dev/null +++ b/tests/test_pputils_csvconnection.py @@ -0,0 +1,13 @@ +from ppextensions.ppsql.connection.csvconnection import CSVConnection +import unittest + +class TestPPSqlCSVConnection(unittest.TestCase): + + def setUp(self): + self.csvconn = CSVConnection() + + def test_csv_query(self): + self.assertTrue(self.csvconn.execute("select * from test_files/test.csv") != None) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_pputils_fsreaderwriter.py b/tests/test_pputils_fsreaderwriter.py new file mode 100644 index 0000000..9cc2d49 --- /dev/null +++ b/tests/test_pputils_fsreaderwriter.py @@ -0,0 +1,18 @@ +from ppextensions.pputils.utils.filesystemreader import FileSystemReaderWriter +import unittest + +class TestPPUtilsFileSystemReaderWriter(unittest.TestCase): + + def setUp(self): + # In current implementation we will have two RM Objects + # One with invalid RM Url & One with Valid one + self.fsreadwriter = FileSystemReaderWriter("~") + + def test_ensure_path_exists(self): + self.assertTrue(self.fsreadwriter.ensure_path_exists() == None) + + def test_ensure_file_exists(self): + self.assertTrue(self.fsreadwriter.ensure_file_exists() == None) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_pputils_log.py b/tests/test_pputils_log.py new file mode 100644 index 0000000..803cc82 --- /dev/null +++ b/tests/test_pputils_log.py @@ -0,0 +1,22 @@ +from ppextensions.pputils.utils.log import Log +import unittest + +class TestPPUtilsLog(unittest.TestCase): + + def setUp(self): + self.logger = Log("test_logger") + + def test_log_debug(self): + self.assertTrue(self.logger.debug("test_debug") == None) + + def test_log_error(self): + self.assertTrue(self.logger.error("test_error") == None) + + def test_log_info(self): + self.assertTrue(self.logger.info("test_info") == None) + + def test_log_exception(self): + self.assertTrue(self.logger.exception("test_exception") == None) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_pputils_parameterargs.py b/tests/test_pputils_parameterargs.py new file mode 100644 index 0000000..027bb19 --- /dev/null +++ b/tests/test_pputils_parameterargs.py @@ -0,0 +1,28 @@ +from ppextensions.pputils.utils.parameterargs import * +from IPython.core.magic_arguments import argument, magic_arguments, parse_argstring +import unittest + +class TestPPUtilsParamArgs(unittest.TestCase): + + @magic_arguments() + @argument("-test", "--test", type=str, help="test1") + @argument("-test2", "--test2", type=str, help="test2") + def setUp(self): + args = "--test test --test2 testa:::testb:::testc" + self.param_args = ParameterArgs(parse_argstring(self.setUp, args)) + + def test_get_args(self): + self.assertTrue(self.param_args.get("test") == "test") + self.assertTrue(self.param_args.get("test2") == "testa:::testb:::testc") + + def test_has_args(self): + self.assertTrue(self.param_args.hasattr("test")) + self.assertTrue(self.param_args.hasattr("test2")) + + def test_get_list(self): + return_vals = self.param_args.get_list("test2") + self.assertTrue(isinstance(return_vals, list)) + self.assertTrue(len(return_vals) == 3) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_pputils_resultset.py b/tests/test_pputils_resultset.py new file mode 100644 index 0000000..a2597e6 --- /dev/null +++ b/tests/test_pputils_resultset.py @@ -0,0 +1,29 @@ +from ppextensions.pputils.utils.resultset import ResultSet, unduplicate_field_names +import unittest +import pandas as pd + +class TestPPUtilsResultSet(unittest.TestCase): + + def setUp(self): + data = {'col1': [1,2,3,4], 'col2': [3,4,5,6], 'col3': [4,5,6,7], 'col4': [5,6,7,8]} + cols = ['col1', 'col2', 'col3', 'col4'] + self.resultset = ResultSet(cols, data) + + def test_resultset_df(self): + df = self.resultset.DataFrame() + self.assertTrue(isinstance(df, pd.DataFrame)) + + def test_dict(self): + dictionary = self.resultset.dict() + self.assertTrue(isinstance(dictionary, dict)) + + def test_csv(self): + self.assertTrue(self.resultset.csv()) + + def test_unduplicate_field_names(self): + cols = ['col1', 'col2', 'col3', 'col4', 'col1'] + updated_cols = unduplicate_field_names(cols) + self.assertTrue(isinstance(updated_cols, list)) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_pputils_utils.py b/tests/test_pputils_utils.py new file mode 100644 index 0000000..068538a --- /dev/null +++ b/tests/test_pputils_utils.py @@ -0,0 +1,33 @@ +from ppextensions.pputils.utils import utils +import pandas as pd +import unittest + +class TestPPUtilsUtils(unittest.TestCase): + + def setUp(self): + self.test_df = utils.csv_to_df({}, {"csv":"test_files/test.csv"}) + + def test_renew_kerberos_ticket_negative(self): + self.assertFalse(utils.renew_kerberos_ticket("fake","fake")) + + def test_renew_kerberos_ticket_positive(self): + self.assertTrue(utils.renew_kerberos_ticket("pp_batch_opts_admin","~/PPExtensions/tests/test_files/.pp_batch_opts_admin.keytab")) + + def test_parse_run_str(self): + self.assertTrue(utils.parse_run_str("%%info")) + self.assertTrue(utils.parse_run_str("test_call_value=123")) + + def test_csv_to_df_and_back(self): + df = utils.csv_to_df({}, {"csv":"test_files/test.csv"}) + self.assertTrue(isinstance(df, pd.DataFrame)) + args = {"dataframe":"df"} + csv_file = utils.df_to_csv({"df":df}, args) + self.assertTrue(csv_file != None) + + def test_substitute_params(self): + substitute_cell = utils.substitute_params("test_cell_value = {}", {"test":"test"}) + self.assertTrue(substitute_cell != None) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_pputils_yarnapi.py b/tests/test_pputils_yarnapi.py new file mode 100644 index 0000000..7c64d1f --- /dev/null +++ b/tests/test_pputils_yarnapi.py @@ -0,0 +1,21 @@ +from ppextensions.pputils.utils.yarnapi import ResourceManager +import unittest +import requests + +class TestPPUtilsYarnAPI(unittest.TestCase): + + def setUp(self): + # In current implementation we will have two RM Objects + # One with invalid RM Url & One with Valid one + self.invalid_rm = ResourceManager("http://invalidrm.paypalinc.com") + + def test_invalid_rm_cluster_app(self): + with self.assertRaises(requests.exceptions.ConnectionError): + self.invalid_rm.cluster_application("fake_app") + + def test_invalid_rm_cluster_metrics(self): + with self.assertRaises(requests.exceptions.ConnectionError): + self.invalid_rm.cluster_metrics() + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..3b171cf --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,16 @@ +from pputils.utils import utils +import unittest + +class TestPPUtilsUtils(unittest.TestCase): + + def test_renew_kerberos_ticket(self): + self.assertFalse(utils.renew_kerberos_ticket("fake","fake")) + + def test_load_user_config(self): + user_config = utils.load_user_config() + self.assertTrue(user_config != None) + self.assertTrue(isinstance(user_config, dict)) + + +if __name__ == '__main__': + unittest.main()