From 940ee78aa4a921e947e5a79c4bf0af6f03c2f62c Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Wed, 27 Sep 2023 16:16:14 +0200 Subject: [PATCH] Add tests (cherry picked from commit 70061c2e934a770443774c0d89ead02bc3f39038) --- tests/test_util.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_util.py b/tests/test_util.py index ac674140..7054fa57 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -11,6 +11,7 @@ import yaml from sinol_make import util, configure_parsers +from sinol_make.helpers import paths from tests import util as test_util from tests.fixtures import create_package from tests.commands.run import util as run_util @@ -79,6 +80,9 @@ def test_check_version(**kwargs): version_file = data_dir.joinpath("version") if not data_dir.is_dir(): data_dir.mkdir() + data_dir.chmod(0o777) + if version_file.is_file(): + version_file.unlink() # Test correct request mocker.get("https://pypi.python.org/pypi/sinol-make/json", json={"info": {"version": "1.0.0"}}) @@ -97,6 +101,37 @@ def test_check_version(**kwargs): util.check_version() assert not version_file.is_file() + with tempfile.TemporaryDirectory() as tmpdir: + os.chdir(tmpdir) + with open("config.yml", "w") as config_file: + config_file.write("") + + # No permission to write + version_file.write_text("0.0.0") + version_file.chmod(0o000) + mocker.get("https://pypi.python.org/pypi/sinol-make/json", json={"info": {"version": "1.0.0"}}) + util.check_version() + assert version_file.is_file() + version_file.chmod(0o777) + assert version_file.read_text() == "0.0.0" + assert os.path.exists(paths.get_cache_path("sinol_make_version")) + with open(paths.get_cache_path("sinol_make_version"), "r") as f: + assert f.read() == "1.0.0" + + # No permission to write to cache and data dir + with open(paths.get_cache_path("sinol_make_version"), "w") as f: + f.write("0.0.0") + os.chmod(paths.get_cache_path("sinol_make_version"), 0o000) + os.chmod(paths.get_cache_path(), 0o000) + os.chmod(data_dir, 0o000) + version_file.chmod(0o000) + mocker.get("https://pypi.python.org/pypi/sinol-make/json", json={"info": {"version": "1.0.0"}}) + util.check_version() + os.chmod(data_dir, 0o777) + version_file.chmod(0o777) + assert version_file.is_file() + assert version_file.read_text() == "0.0.0" + @pytest.mark.parametrize("create_package", [test_util.get_simple_package_path()], indirect=True) def test_version_change(create_package):