Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 70061c2)
  • Loading branch information
MasloMaslane committed Sep 27, 2023
1 parent 3ce09d0 commit 940ee78
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}})
Expand All @@ -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):
Expand Down

0 comments on commit 940ee78

Please sign in to comment.