def test_deprecated_values(self): def make_config(): test_conf = AirflowConfigParser(default_config='') # Guarantee we have a deprecated setting, so we test the deprecation # lookup even if we remove this explicit fallback test_conf.deprecated_values = { 'core': { 'task_runner': (re.compile(r'\ABashTaskRunner\Z'), r'StandardTaskRunner', '2.0'), 'hostname_callable': (re.compile(r':'), r'.', '2.0'), }, } test_conf.read_dict({ 'core': { 'executor': 'SequentialExecutor', 'task_runner': 'BashTaskRunner', 'sql_alchemy_conn': 'sqlite://', 'hostname_callable': 'socket:getfqdn', }, }) return test_conf with self.assertWarns(FutureWarning): test_conf = make_config() self.assertEqual(test_conf.get('core', 'task_runner'), 'StandardTaskRunner') self.assertEqual(test_conf.get('core', 'hostname_callable'), 'socket.getfqdn') with self.assertWarns(FutureWarning): with unittest.mock.patch.dict('os.environ', AIRFLOW__CORE__TASK_RUNNER='BashTaskRunner'): test_conf = make_config() self.assertEqual(test_conf.get('core', 'task_runner'), 'StandardTaskRunner') with self.assertWarns(FutureWarning): with unittest.mock.patch.dict('os.environ', AIRFLOW__CORE__HOSTNAME_CALLABLE='socket:getfqdn'): test_conf = make_config() self.assertEqual(test_conf.get('core', 'hostname_callable'), 'socket.getfqdn') with reset_warning_registry(): with warnings.catch_warnings(record=True) as warning: with unittest.mock.patch.dict('os.environ', AIRFLOW__CORE__TASK_RUNNER='NotBashTaskRunner', AIRFLOW__CORE__HOSTNAME_CALLABLE='CarrierPigeon'): test_conf = make_config() self.assertEqual(test_conf.get('core', 'task_runner'), 'NotBashTaskRunner') self.assertEqual(test_conf.get('core', 'hostname_callable'), 'CarrierPigeon') self.assertListEqual([], warning)
def test_log(self): op = BashOperator(task_id='task-1', bash_command='exit 0') with reset_warning_registry(): with warnings.catch_warnings(record=True) as w: # Set to always, because the warning may have been thrown before # Trigger the warning op.logger.info('Some arbitrary line') self.assertEqual(len(w), 1) warning = w[0] self.assertTrue( issubclass(warning.category, DeprecationWarning)) self.assertEqual( 'Initializing logger for airflow.operators.bash_operator.BashOperator' ' using logger(), which will be replaced by .log in Airflow 2.0', str(warning.message))
def test_deprecated_values(self): def make_config(): test_conf = AirflowConfigParser() # Guarantee we have a deprecated setting, so we test the deprecation # lookup even if we remove this explicit fallback test_conf.deprecated_values = { 'core': { 'task_runner': ('BashTaskRunner', 'StandardTaskRunner', '2.0'), }, } test_conf.read_dict({ 'core': { 'executor': 'SequentialExecutor', 'task_runner': 'BashTaskRunner', 'sql_alchemy_conn': 'sqlite://', }, 'webserver': { 'authenticate': False, }, }) return test_conf with self.assertWarns(FutureWarning): test_conf = make_config() self.assertEqual(test_conf.get('core', 'task_runner'), 'StandardTaskRunner') with self.assertWarns(FutureWarning): with env_vars(AIRFLOW__CORE__TASK_RUNNER='BashTaskRunner'): test_conf = make_config() self.assertEqual(test_conf.get('core', 'task_runner'), 'StandardTaskRunner') with reset_warning_registry(): with warnings.catch_warnings(record=True) as w: with env_vars(AIRFLOW__CORE__TASK_RUNNER='NotBashTaskRunner'): test_conf = make_config() self.assertEqual(test_conf.get('core', 'task_runner'), 'NotBashTaskRunner') self.assertListEqual([], w)
def test_deprecated_values(self): def make_config(): test_conf = AirflowConfigParser(default_config='') # Guarantee we have a deprecated setting, so we test the deprecation # lookup even if we remove this explicit fallback test_conf.deprecated_values = { 'core': { 'hostname_callable': (re.compile(r':'), r'.', '2.1'), }, } test_conf.read_dict({ 'core': { 'executor': 'SequentialExecutor', 'sql_alchemy_conn': 'sqlite://', 'hostname_callable': 'socket:getfqdn', }, }) test_conf.validate() return test_conf with pytest.warns(FutureWarning): test_conf = make_config() assert test_conf.get('core', 'hostname_callable') == 'socket.getfqdn' with pytest.warns(FutureWarning): with unittest.mock.patch.dict( 'os.environ', AIRFLOW__CORE__HOSTNAME_CALLABLE='socket:getfqdn'): test_conf = make_config() assert test_conf.get('core', 'hostname_callable') == 'socket.getfqdn' with reset_warning_registry(): with warnings.catch_warnings(record=True) as warning: with unittest.mock.patch.dict( 'os.environ', AIRFLOW__CORE__HOSTNAME_CALLABLE='CarrierPigeon', ): test_conf = make_config() assert test_conf.get( 'core', 'hostname_callable') == 'CarrierPigeon' assert [] == warning
def test_log(self): op = BashOperator( task_id='task-1', bash_command='exit 0' ) with reset_warning_registry(): with warnings.catch_warnings(record=True) as w: # Set to always, because the warning may have been thrown before # Trigger the warning op.logger.info('Some arbitrary line') self.assertEqual(len(w), 1) warning = w[0] self.assertTrue(issubclass(warning.category, DeprecationWarning)) self.assertEqual( 'Initializing logger for airflow.operators.bash_operator.BashOperator' ' using logger(), which will be replaced by .log in Airflow 2.0', str(warning.message) )