def test_getboolean(self): """Test AirflowConfigParser.getboolean""" TEST_CONFIG = """ [type_validation] key1 = non_bool_value [true] key2 = t key3 = true key4 = 1 [false] key5 = f key6 = false key7 = 0 [inline-comment] key8 = true #123 """ test_conf = AirflowConfigParser(default_config=TEST_CONFIG) with self.assertRaises(ValueError): test_conf.getboolean('type_validation', 'key1') self.assertTrue(isinstance(test_conf.getboolean('true', 'key3'), bool)) self.assertEqual(True, test_conf.getboolean('true', 'key2')) self.assertEqual(True, test_conf.getboolean('true', 'key3')) self.assertEqual(True, test_conf.getboolean('true', 'key4')) self.assertEqual(False, test_conf.getboolean('false', 'key5')) self.assertEqual(False, test_conf.getboolean('false', 'key6')) self.assertEqual(False, test_conf.getboolean('false', 'key7')) self.assertEqual(True, test_conf.getboolean('inline-comment', 'key8'))
def test_getboolean(self): """Test AirflowConfigParser.getboolean""" test_config = """ [type_validation] key1 = non_bool_value [true] key2 = t key3 = true key4 = 1 [false] key5 = f key6 = false key7 = 0 [inline-comment] key8 = true #123 """ test_conf = AirflowConfigParser(default_config=test_config) with self.assertRaisesRegex( AirflowConfigException, re.escape( 'Failed to convert value to bool. Please check "key1" key in "type_validation" section. ' 'Current value: "non_bool_value".'), ): test_conf.getboolean('type_validation', 'key1') self.assertTrue(isinstance(test_conf.getboolean('true', 'key3'), bool)) self.assertEqual(True, test_conf.getboolean('true', 'key2')) self.assertEqual(True, test_conf.getboolean('true', 'key3')) self.assertEqual(True, test_conf.getboolean('true', 'key4')) self.assertEqual(False, test_conf.getboolean('false', 'key5')) self.assertEqual(False, test_conf.getboolean('false', 'key6')) self.assertEqual(False, test_conf.getboolean('false', 'key7')) self.assertEqual(True, test_conf.getboolean('inline-comment', 'key8'))
def test_command_precedence(self): test_config = '''[test] key1 = hello key2_cmd = printf cmd_result key3 = airflow key4_cmd = printf key4_result ''' test_config_default = '''[test] key1 = awesome key2 = airflow [another] key6 = value6 ''' test_conf = AirflowConfigParser( default_config=parameterized_config(test_config_default)) test_conf.read_string(test_config) test_conf.sensitive_config_values = test_conf.sensitive_config_values | { ('test', 'key2'), ('test', 'key4'), } self.assertEqual('hello', test_conf.get('test', 'key1')) self.assertEqual('cmd_result', test_conf.get('test', 'key2')) self.assertEqual('airflow', test_conf.get('test', 'key3')) self.assertEqual('key4_result', test_conf.get('test', 'key4')) self.assertEqual('value6', test_conf.get('another', 'key6')) self.assertEqual('hello', test_conf.get('test', 'key1', fallback='fb')) self.assertEqual('value6', test_conf.get('another', 'key6', fallback='fb')) self.assertEqual('fb', test_conf.get('another', 'key7', fallback='fb')) self.assertEqual( True, test_conf.getboolean('another', 'key8_boolean', fallback='True')) self.assertEqual( 10, test_conf.getint('another', 'key8_int', fallback='10')) self.assertEqual( 1.0, test_conf.getfloat('another', 'key8_float', fallback='1')) self.assertTrue(test_conf.has_option('test', 'key1')) self.assertTrue(test_conf.has_option('test', 'key2')) self.assertTrue(test_conf.has_option('test', 'key3')) self.assertTrue(test_conf.has_option('test', 'key4')) self.assertFalse(test_conf.has_option('test', 'key5')) self.assertTrue(test_conf.has_option('another', 'key6')) cfg_dict = test_conf.as_dict(display_sensitive=True) self.assertEqual('cmd_result', cfg_dict['test']['key2']) self.assertNotIn('key2_cmd', cfg_dict['test']) # If we exclude _cmds then we should still see the commands to run, not # their values cfg_dict = test_conf.as_dict(include_cmds=False, display_sensitive=True) self.assertNotIn('key4', cfg_dict['test']) self.assertEqual('printf key4_result', cfg_dict['test']['key4_cmd'])
def test_command_precedence(self): TEST_CONFIG = '''[test] key1 = hello key2_cmd = printf cmd_result key3 = airflow key4_cmd = printf key4_result ''' TEST_CONFIG_DEFAULT = '''[test] key1 = awesome key2 = airflow [another] key6 = value6 ''' test_conf = AirflowConfigParser( default_config=parameterized_config(TEST_CONFIG_DEFAULT)) test_conf.read_string(TEST_CONFIG) test_conf.as_command_stdout = test_conf.as_command_stdout | { ('test', 'key2'), ('test', 'key4'), } self.assertEqual('hello', test_conf.get('test', 'key1')) self.assertEqual('cmd_result', test_conf.get('test', 'key2')) self.assertEqual('airflow', test_conf.get('test', 'key3')) self.assertEqual('key4_result', test_conf.get('test', 'key4')) self.assertEqual('value6', test_conf.get('another', 'key6')) self.assertEqual('hello', test_conf.get('test', 'key1', fallback='fb')) self.assertEqual('value6', test_conf.get('another', 'key6', fallback='fb')) self.assertEqual('fb', test_conf.get('another', 'key7', fallback='fb')) self.assertEqual( True, test_conf.getboolean('another', 'key8_boolean', fallback='True')) self.assertEqual( 10, test_conf.getint('another', 'key8_int', fallback='10')) self.assertEqual( 1.0, test_conf.getfloat('another', 'key8_float', fallback='1')) self.assertTrue(test_conf.has_option('test', 'key1')) self.assertTrue(test_conf.has_option('test', 'key2')) self.assertTrue(test_conf.has_option('test', 'key3')) self.assertTrue(test_conf.has_option('test', 'key4')) self.assertFalse(test_conf.has_option('test', 'key5')) self.assertTrue(test_conf.has_option('another', 'key6')) cfg_dict = test_conf.as_dict(display_sensitive=True) self.assertEqual('cmd_result', cfg_dict['test']['key2']) self.assertNotIn('key2_cmd', cfg_dict['test'])
def test_command_precedence(self): TEST_CONFIG = '''[test] key1 = hello key2_cmd = printf cmd_result key3 = airflow key4_cmd = printf key4_result ''' TEST_CONFIG_DEFAULT = '''[test] key1 = awesome key2 = airflow [another] key6 = value6 ''' test_conf = AirflowConfigParser( default_config=parameterized_config(TEST_CONFIG_DEFAULT)) test_conf.read_string(TEST_CONFIG) test_conf.as_command_stdout = test_conf.as_command_stdout | { ('test', 'key2'), ('test', 'key4'), } self.assertEqual('hello', test_conf.get('test', 'key1')) self.assertEqual('cmd_result', test_conf.get('test', 'key2')) self.assertEqual('airflow', test_conf.get('test', 'key3')) self.assertEqual('key4_result', test_conf.get('test', 'key4')) self.assertEqual('value6', test_conf.get('another', 'key6')) self.assertEqual('hello', test_conf.get('test', 'key1', fallback='fb')) self.assertEqual('value6', test_conf.get('another', 'key6', fallback='fb')) self.assertEqual('fb', test_conf.get('another', 'key7', fallback='fb')) self.assertEqual(True, test_conf.getboolean('another', 'key8_boolean', fallback='True')) self.assertEqual(10, test_conf.getint('another', 'key8_int', fallback='10')) self.assertEqual(1.0, test_conf.getfloat('another', 'key8_float', fallback='1')) self.assertTrue(test_conf.has_option('test', 'key1')) self.assertTrue(test_conf.has_option('test', 'key2')) self.assertTrue(test_conf.has_option('test', 'key3')) self.assertTrue(test_conf.has_option('test', 'key4')) self.assertFalse(test_conf.has_option('test', 'key5')) self.assertTrue(test_conf.has_option('another', 'key6')) cfg_dict = test_conf.as_dict(display_sensitive=True) self.assertEqual('cmd_result', cfg_dict['test']['key2']) self.assertNotIn('key2_cmd', cfg_dict['test'])