def test_get_conf_string(self): conf = queue.QueueConf() conf.setConf("a", 1) conf.setConf("b", None) self.assertEqual(conf.getConfString("a"), "1") self.assertEqual(conf.getConfString("b"), "None") self.assertEqual(conf.getConfString("c"), "None")
def test_contains(self): conf = queue.QueueConf() conf.setConf("a", 1) conf.setConf("b", None) self.assertEqual(conf.contains("a"), True) self.assertEqual(conf.contains("b"), True) self.assertEqual(conf.contains("c"), False)
def test_get_conf(self): conf = queue.QueueConf() conf.setConf("a", 1) conf.setConf("b", None) self.assertEqual(conf.getConf("a"), 1) self.assertEqual(conf.getConf("b"), None) self.assertEqual(conf.getConf("c"), None)
def test_get_conf_boolean(self): conf = queue.QueueConf() conf.setConf("a", 1) conf.setConf("b", None) conf.setConf("c", False) self.assertEqual(conf.getConfBoolean("a"), True) self.assertEqual(conf.getConfBoolean("b"), False) self.assertEqual(conf.getConfBoolean("c"), False)
def test_set_all_conf(self): conf = queue.QueueConf() with self.assertRaises(TypeError): conf.setAllConf(None) with self.assertRaises(TypeError): conf.setAllConf([]) conf.setAllConf({"a": 1, "b": True}) self.assertEqual(conf.getConf("a"), 1) self.assertEqual(conf.getConf("b"), True)
def test_set_conf(self): conf = queue.QueueConf() with self.assertRaises(AttributeError): conf.setConf(None, None) with self.assertRaises(AttributeError): conf.setConf("", None) # non-empty key and None value should succeed conf.setConf("key", None) self.assertEqual(conf.getConf("key"), None)
def test_get_conf_float(self): conf = queue.QueueConf() conf.setConf("a", 1) conf.setConf("b", "2.0") conf.setConf("c", None) conf.setConf("d", False) self.assertEqual(conf.getConfFloat("a"), 1.0) self.assertEqual(conf.getConfFloat("b"), 2.0) with self.assertRaises(TypeError): conf.getConfFloat("c") self.assertEqual(conf.getConfFloat("d"), 0.0)
def test_get_conf_int(self): conf = queue.QueueConf() conf.setConf("a", 1) conf.setConf("b", "2") conf.setConf("c", None) conf.setConf("d", False) self.assertEqual(conf.getConfInt("a"), 1) self.assertEqual(conf.getConfInt("b"), 2) with self.assertRaises(TypeError): conf.getConfInt("c") self.assertEqual(conf.getConfInt("d"), 0)
def test_create_session(self, mock_session, mock_pymongo, mock_util): controller = queue.QueueController(args=self.args) with self.assertRaises(AttributeError): controller._create_session(None) with self.assertRaises(AttributeError): controller._create_session({"a": 1}) conf = queue.QueueConf() with self.assertRaises(StandardError): controller._create_session(conf) # check spark session conf.setAllConf(self.args) session = controller._create_session(conf) self.assertTrue(isinstance(session, spark.SparkSession)) # check simple session conf = queue.QueueConf() conf.setConf(const.OPT_SYSTEM_CODE, simple.SIMPLE_SYSTEM_CODE) conf.setConf(const.OPT_SCHEDULER_TIMEOUT, 1.0) conf.setConf(const.OPT_NUM_PARALLEL_TASKS, 1) session = controller._create_session(conf) self.assertTrue(isinstance(session, simple.SimpleSession))
def test_copy(self): conf = queue.QueueConf() opts = {"a": 1, "b": True, "c": 1.0} conf.setAllConf(opts) self.assertEqual(conf.copy(), opts)