From 73f45294e2e2800aa068a243c82cdf00f1bfa831 Mon Sep 17 00:00:00 2001 From: Tomas Tomecek Date: Tue, 9 Apr 2019 12:38:46 +0200 Subject: [PATCH] fix last two test failures the problem was that methods were not mocked and picked data from the current working directory Signed-off-by: Tomas Tomecek --- tests/test_bot.py | 6 +++++- tests/test_load_local_conf.py | 14 ++++++++------ tests/test_load_release_conf.py | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/test_bot.py b/tests/test_bot.py index 3e15fa6..b320038 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -111,6 +111,10 @@ def mock_upload(self): """Mocks upload to PyPi""" flexmock(self.release_bot.pypi, upload=True) + @pytest.fixture() + def mock_get_latest_version(self): + flexmock(self.release_bot.pypi, latest_version=lambda: "0.0.0") + def test_load_release_conf(self): """Tests loading release configuration from repository""" self.release_bot.load_release_conf() @@ -151,7 +155,7 @@ def test_github_release(self, open_pr_fixture): self.release_bot.make_new_github_release() assert self.release_bot.github.latest_release() == "0.0.1" - def test_pypi_release(self, mock_upload, github_release): + def test_pypi_release(self, mock_upload, github_release, mock_get_latest_version): """Test PyPi release""" self.release_bot.load_release_conf() # Testing dry-run mode diff --git a/tests/test_load_local_conf.py b/tests/test_load_local_conf.py index 716a68a..3db23d1 100644 --- a/tests/test_load_local_conf.py +++ b/tests/test_load_local_conf.py @@ -13,17 +13,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from pathlib import Path + import pytest +from flexmock import flexmock -from pathlib import Path -from release_bot.configuration import configuration +from release_bot.configuration import configuration, Configuration class TestLoadLocalConf: """ This class contains tests for loading the release-bot configuration from conf.yaml""" - def setup_method(self): """ Setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. @@ -51,11 +52,12 @@ def non_existing_conf(self): """Return a non-existing configutation file""" return "" - def test_non_existing_conf(self, non_existing_conf): + def test_non_existing_conf(self): """Test if missing conf.yaml generates an error""" - configuration.configuration = non_existing_conf + flexmock(Path, is_file=lambda: False) + c = Configuration() with pytest.raises(SystemExit) as error: - configuration.load_configuration() + c.load_configuration() assert error.type == SystemExit assert error.value.code == 1 diff --git a/tests/test_load_release_conf.py b/tests/test_load_release_conf.py index 2c34f24..e230c07 100644 --- a/tests/test_load_release_conf.py +++ b/tests/test_load_release_conf.py @@ -14,6 +14,7 @@ # along with this program. If not, see . from pathlib import Path + import pytest from release_bot.configuration import configuration, Configuration