Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hind-M committed Jan 9, 2025
1 parent 61dafcf commit fe6d72d
Showing 1 changed file with 26 additions and 49 deletions.
75 changes: 26 additions & 49 deletions tests/test_fetch_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ def test_get_micromamba_existing_version(retry_config, version, use_default_vers

pytest.fail(f"Failed to fetch micromamba release info after multiple retries.")

#TODO add a test with use_default_version = False
@pytest.mark.parametrize("version", ("2.0.5.rc0", "2.0.4alpha1"))
def test_get_micromamba_existing_dev_or_prerelease(retry_config, version):
def test_get_micromamba_existing_dev_or_prerelease_use_default(retry_config, version):
"""
Test fetching existing micromamba dev or prerelease version.
"""
Expand All @@ -106,6 +105,29 @@ def test_get_micromamba_existing_dev_or_prerelease(retry_config, version):

pytest.fail(f"Failed to fetch micromamba release info after multiple retries.")

@pytest.mark.parametrize("version", ("2.0.5.rc0", "2.0.4alpha1"))
def test_get_micromamba_existing_dev_or_prerelease(retry_config, version):
"""
Test fetching existing micromamba dev or prerelease version.
"""
max_retries = retry_config['max_retries']
retry_delay = retry_config['retry_delay']

for _ in range(max_retries):
try:
get_micromamba(version, use_default_version = False)
assert get_output_value("MICROMAMBA_NEW_VERSION") == "false"
assert get_output_value("MICROMAMBA_NEW_PRERELEASE") == None
assert get_output_value("MICROMAMBA_LATEST") == None
assert get_output_value("MICROMAMBA_VERSION") == None
print(f"Fetched micromamba release {version} successfully.")
return
except requests.exceptions.RequestException as e:
print(f"Error fetching micromamba release, retrying... {e}")
time.sleep(retry_delay)

pytest.fail(f"Failed to fetch micromamba release info after multiple retries.")

@pytest.mark.parametrize("use_default_version", (False, True))
def test_get_micromamba_non_existing_version(use_default_version):
"""
Expand All @@ -115,51 +137,6 @@ def test_get_micromamba_non_existing_version(use_default_version):
with pytest.raises(requests.exceptions.HTTPError):
get_micromamba("9.10.5", use_default_version)

#TODO mock test for non existing versions => new


#def test_get_micromamba_default_version(retry_config):
#"""
#Test fetching the default (latest) version of micromamba from Anaconda API.
#This tests the `use_default_version=True` scenario.
#"""
#max_retries = retry_config['max_retries']
#retry_delay = retry_config['retry_delay']

#for _ in range(max_retries):
#try:
#get_micromamba("latest", use_default_version=True) # Make actual request
#print("Fetched the latest micromamba release successfully.")
#return # Success, break out of the loop
#except requests.exceptions.RequestException as e:
#print(f"Error fetching latest micromamba release, retrying... {e}")
#time.sleep(retry_delay)

#pytest.fail("Failed to fetch the latest micromamba release info after multiple retries.")


#def test_get_all_tags_github_with_invalid_url():
#"""
#Test the behavior when the GitHub API endpoint is invalid (to check error handling).
#"""
#invalid_url = "https://api.github.com/repos/mamba-org/micromamba-releases/invalid_tags"
#try:
## Temporarily override the URL to simulate failure
#response = requests.get(invalid_url)
#response.raise_for_status() # Will raise HTTPError for bad responses
#pytest.fail("Expected HTTPError due to invalid URL, but the request succeeded.")
#except requests.exceptions.RequestException as e:
#print(f"Handled expected error: {e}")
#assert str(e).startswith("404")


#def test_get_micromamba_with_invalid_version():
#"""
#Test fetching micromamba with an invalid version.
#This should raise an error or handle the scenario gracefully.
#"""
#invalid_version = "999.999.999" # Invalid version that doesn't exist
#try:
#get_micromamba(invalid_version, use_default_version=False)
#pytest.fail(f"Expected failure for invalid version {invalid_version}, but the request succeeded.")
#except requests.exceptions.RequestException as e:
#print(f"Handled expected error: {e}")
#assert str(e).startswith("404")

0 comments on commit fe6d72d

Please sign in to comment.