From 8917ce6befc8cb69cefc7f11fd069fe2bd94aa8d Mon Sep 17 00:00:00 2001 From: Tanay Tummalapalli Date: Mon, 11 Feb 2019 15:23:55 +0530 Subject: [PATCH] [AIRFLOW-3742] Fix handling of "fallback" for AirflowConfigParsxer.getint/boolean (#4674) We added (and used) fallback as an argument on `getboolean` but didn't add it to the method, or add tests covering those "casting" accessors, so they broke. This fixes those methods, and adds tests covering them --- airflow/configuration.py | 20 ++++++++++---------- tests/test_configuration.py | 5 ++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/airflow/configuration.py b/airflow/configuration.py index 0de6bb9947e2a..c7fd3bd1417f8 100644 --- a/airflow/configuration.py +++ b/airflow/configuration.py @@ -260,27 +260,27 @@ def get(self, section, key, **kwargs): "section/key [{section}/{key}] not found " "in config".format(**locals())) - def getboolean(self, section, key): - val = str(self.get(section, key)).lower().strip() + def getboolean(self, section, key, **kwargs): + val = str(self.get(section, key, **kwargs)).lower().strip() if '#' in val: val = val.split('#')[0].strip() - if val.lower() in ('t', 'true', '1'): + if val in ('t', 'true', '1'): return True - elif val.lower() in ('f', 'false', '0'): + elif val in ('f', 'false', '0'): return False else: raise AirflowConfigException( 'The value for configuration option "{}:{}" is not a ' 'boolean (received "{}").'.format(section, key, val)) - def getint(self, section, key): - return int(self.get(section, key)) + def getint(self, section, key, **kwargs): + return int(self.get(section, key, **kwargs)) - def getfloat(self, section, key): - return float(self.get(section, key)) + def getfloat(self, section, key, **kwargs): + return float(self.get(section, key, **kwargs)) - def read(self, filenames): - super(AirflowConfigParser, self).read(filenames) + def read(self, filenames, **kwargs): + super(AirflowConfigParser, self).read(filenames, **kwargs) self._validate() def read_dict(self, *args, **kwargs): diff --git a/tests/test_configuration.py b/tests/test_configuration.py index ba160f768bcc9..2c6489c04d032 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -139,7 +139,7 @@ def test_conf_as_dict_raw(self): self.assertEqual(cfg_dict['testsection']['testpercent'], 'with%%percent') self.assertEqual(cfg_dict['core']['percent'], 'with%%inside') - def test_command_config(self): + def test_command_precedence(self): TEST_CONFIG = '''[test] key1 = hello key2_cmd = printf cmd_result @@ -170,6 +170,9 @@ def test_command_config(self): 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'))