Skip to content

Commit

Permalink
Add second part of test update
Browse files Browse the repository at this point in the history
  • Loading branch information
Hind-M committed Sep 6, 2023
1 parent 7c3a9bd commit 24c1dd5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 40 deletions.
45 changes: 18 additions & 27 deletions mamba/tests/helpers_mamba.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,34 +220,25 @@ def create(
#raise (e)


#def update(*args, default_channel=True, no_rc=True, no_dry_run=False, **kwargs):
#umamba = get_umamba()
#cmd = [umamba, "update", "-y"] + [arg for arg in args if arg]
#if use_offline:
#cmd += ["--offline"]
#if no_rc:
#cmd += ["--no-rc"]
#if default_channel:
#cmd += channel
#if (dry_run_tests == DryRun.DRY) and "--dry-run" not in args and not no_dry_run:
#cmd += ["--dry-run"]

#try:
#res = subprocess_run(*cmd, **kwargs)
#if "--json" in args:
#try:
#j = json.loads(res)
#return j
#except json.decoder.JSONDecodeError as e:
#print(f"Error when loading JSON output from {res}")
#raise (e)
#print(f"Error when executing '{' '.join(cmd)}'")
#raise
def update(*args, **kwargs):
umamba = get_umamba()
cmd = [umamba, "update", "-y"] + [arg for arg in args if arg]
try:
res = subprocess_run(*cmd, **kwargs)
if "--json" in args:
try:
j = json.loads(res)
return j
except json.decoder.JSONDecodeError as e:
print(f"Error when loading JSON output from {res}")
raise (e)
print(f"Error when executing '{' '.join(cmd)}'")
raise

#return res.decode()
#except subprocess.CalledProcessError as e:
#print(f"Error when executing '{' '.join(cmd)}'")
#raise (e)
return res.decode()
except subprocess.CalledProcessError as e:
print(f"Error when executing '{' '.join(cmd)}'")
raise (e)


#def run_env(*args, f=None, **kwargs):
Expand Down
25 changes: 12 additions & 13 deletions mamba/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
get_umamba,
install,
umamba_run,
update,
)

from utils import (
Expand Down Expand Up @@ -79,27 +80,25 @@ def temp_env_prefix():
os.environ["CONDA_PREFIX"] = previous_prefix


#@pytest.mark.parametrize("shell_type", platform_shells())
#def test_update(shell_type):
def test_update(temp_env_prefix)
# check updating a package when a newer version
# first install an older version
def test_update(temp_env_prefix):
# Check updating a package when a newer version
# First install an older version (in fixture)
version = "1.25.11"

res = umamba_run(
"-p", temp_env_prefix, "python", "-c", "import urllib3; print(urllib3.__version__)"
)

# check that the installed version is the old one
# Check that the installed version is the old one
assert res[-1] == version

# then update package
#env.mamba("update -q -y urllib3") # TODO to change
#res = umamba_run(
#"-p", temp_env_prefix, "python", "-c", "import urllib3; print(urllib3.__version__)"
#)
## check that the installed version is newer
#assert StrictVersion(res[-1]) > StrictVersion(version)
# Update package
update("-p", temp_env_prefix, "-q", "urllib3")
res = umamba_run(
"-p", temp_env_prefix, "python", "-c", "import urllib3; print(urllib3.__version__)"
)
# Check that the installed version is newer
assert StrictVersion(res[-1]) > StrictVersion(version)


#@pytest.mark.parametrize("shell_type", platform_shells())
Expand Down

0 comments on commit 24c1dd5

Please sign in to comment.