This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch v2-8-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 41c86522f0abde692cc250fe9a8185723a256409 Author: Jarek Potiuk <[email protected]> AuthorDate: Tue Feb 13 15:30:57 2024 +0100 Bring back accidentally commented out tests (#37386) (cherry picked from commit a5c65405673ed4cacc5006d629893cb66e295cfc) --- tests/core/test_configuration.py | 120 +++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/tests/core/test_configuration.py b/tests/core/test_configuration.py index 9a69a1b28e..0c8af1baab 100644 --- a/tests/core/test_configuration.py +++ b/tests/core/test_configuration.py @@ -1684,63 +1684,63 @@ class TestWriteDefaultAirflowConfigurationIfNeeded: finally: self.test_airflow_config.unlink() - # @pytest.mark.parametrize( - # "relative_to_airflow_home", - # [ - # pytest.param(True, id="relative-to-airflow-home"), - # pytest.param(False, id="non-relative-to-airflow-home"), - # ], - # ) - # def test_config_already_created(self, relative_to_airflow_home): - # if relative_to_airflow_home: - # test_airflow_config = self.test_airflow_home / "test-existed-config" - # else: - # test_airflow_config = self.test_non_relative_path / "test-existed-config" - # - # test_airflow_config.write_text("foo=bar") - # write_default_airflow_configuration_if_needed() - # assert test_airflow_config.read_text() == "foo=bar" - # - # def test_config_path_relative(self): - # """Test write default config in path relative to ${AIRFLOW_HOME}.""" - # test_airflow_config_parent = self.test_airflow_home / "config" - # test_airflow_config = test_airflow_config_parent / "test-airflow.config" - # self.patch_airflow_config(test_airflow_config) - # - # assert not test_airflow_config_parent.exists() - # assert not test_airflow_config.exists() - # write_default_airflow_configuration_if_needed() - # assert test_airflow_config.exists() - # - # def test_config_path_non_relative_directory_exists(self): - # """Test write default config in path non-relative to ${AIRFLOW_HOME} and directory exists.""" - # test_airflow_config_parent = self.test_non_relative_path - # test_airflow_config = test_airflow_config_parent / "test-airflow.cfg" - # self.patch_airflow_config(test_airflow_config) - # - # assert test_airflow_config_parent.exists() - # assert not test_airflow_config.exists() - # write_default_airflow_configuration_if_needed() - # assert test_airflow_config.exists() - - # def test_config_path_non_relative_directory_not_exists(self): - # """Test raise an error if path to config non-relative to ${AIRFLOW_HOME} and directory not exists.""" - # test_airflow_config_parent = self.test_non_relative_path / "config" - # test_airflow_config = test_airflow_config_parent / "test-airflow.cfg" - # self.patch_airflow_config(test_airflow_config) - # - # assert not test_airflow_config_parent.exists() - # assert not test_airflow_config.exists() - # with pytest.raises(FileNotFoundError, match="not exists and it is not relative to"): - # write_default_airflow_configuration_if_needed() - # assert not test_airflow_config.exists() - # assert not test_airflow_config_parent.exists() - - # def test_config_paths_is_directory(self): - # """Test raise an error if AIRFLOW_CONFIG is a directory.""" - # test_airflow_config = self.test_airflow_home / "config-dir" - # test_airflow_config.mkdir() - # self.patch_airflow_config(test_airflow_config) - # - # with pytest.raises(IsADirectoryError, match="configuration file, but got a directory"): - # write_default_airflow_configuration_if_needed() + @pytest.mark.parametrize( + "relative_to_airflow_home", + [ + pytest.param(True, id="relative-to-airflow-home"), + pytest.param(False, id="non-relative-to-airflow-home"), + ], + ) + def test_config_already_created(self, relative_to_airflow_home): + if relative_to_airflow_home: + test_airflow_config = self.test_airflow_home / "test-existed-config" + else: + test_airflow_config = self.test_non_relative_path / "test-existed-config" + + test_airflow_config.write_text("foo=bar") + write_default_airflow_configuration_if_needed() + assert test_airflow_config.read_text() == "foo=bar" + + def test_config_path_relative(self): + """Test write default config in path relative to ${AIRFLOW_HOME}.""" + test_airflow_config_parent = self.test_airflow_home / "config" + test_airflow_config = test_airflow_config_parent / "test-airflow.config" + self.patch_airflow_config(test_airflow_config) + + assert not test_airflow_config_parent.exists() + assert not test_airflow_config.exists() + write_default_airflow_configuration_if_needed() + assert test_airflow_config.exists() + + def test_config_path_non_relative_directory_exists(self): + """Test write default config in path non-relative to ${AIRFLOW_HOME} and directory exists.""" + test_airflow_config_parent = self.test_non_relative_path + test_airflow_config = test_airflow_config_parent / "test-airflow.cfg" + self.patch_airflow_config(test_airflow_config) + + assert test_airflow_config_parent.exists() + assert not test_airflow_config.exists() + write_default_airflow_configuration_if_needed() + assert test_airflow_config.exists() + + def test_config_path_non_relative_directory_not_exists(self): + """Test raise an error if path to config non-relative to ${AIRFLOW_HOME} and directory not exists.""" + test_airflow_config_parent = self.test_non_relative_path / "config" + test_airflow_config = test_airflow_config_parent / "test-airflow.cfg" + self.patch_airflow_config(test_airflow_config) + + assert not test_airflow_config_parent.exists() + assert not test_airflow_config.exists() + with pytest.raises(FileNotFoundError, match="not exists and it is not relative to"): + write_default_airflow_configuration_if_needed() + assert not test_airflow_config.exists() + assert not test_airflow_config_parent.exists() + + def test_config_paths_is_directory(self): + """Test raise an error if AIRFLOW_CONFIG is a directory.""" + test_airflow_config = self.test_airflow_home / "config-dir" + test_airflow_config.mkdir() + self.patch_airflow_config(test_airflow_config) + + with pytest.raises(IsADirectoryError, match="configuration file, but got a directory"): + write_default_airflow_configuration_if_needed()
