grouped-sampling-demo / test_is_downloaded.py
yonikremer's picture
add more test cases to TestIsDownloaded
2f94880
# test_hanlde_form_submit.py - Generated by CodiumAI
from hanlde_form_submit import is_downloaded
"""
Code Analysis:
- The main goal of the function is to check if a specific model is downloaded or not.
- The function takes a string parameter 'model_name' which is the name of the model to be checked.
- It then sets the 'models_dir' variable to the directory where the downloaded models are stored.
- The function then creates a new variable 'model_dir' by joining the 'models_dir' and the 'model_name' parameter with a specific format.
- The function then checks if the 'model_dir' exists as a directory using the 'os.path.isdir' method.
- If the directory exists, the function returns True, indicating that the model is downloaded.
- If the directory does not exist, the function returns False, indicating that the model is not downloaded.
"""
"""
Test Plan:
- test_is_downloaded_exists(): tests that the function correctly identifies that a downloaded model exists and returns True. Tags: [happy path]
- test_is_downloaded_not_exists(): tests that the function correctly identifies that a downloaded model does not exist and returns False. Tags: [happy path]
- test_is_downloaded_empty_model_name(): tests that the function handles an empty string for the 'model_name' parameter. Tags: [edge case]
- test_is_downloaded_invalid_model_name(): tests that the function handles invalid characters for a directory name in the 'model_name' parameter. Tags: [edge case]
- test_is_downloaded_only_directories(): tests that the function only checks for directories, not files. Tags: [general behavior]
- test_is_downloaded_dir_not_exist(): tests that the function handles the case where the 'models_dir' directory does not exist. Tags: [edge case]
- test_is_downloaded_dir_not_writable(): tests that the function handles the case where the 'models_dir' directory is not writable. Tags: [general behavior]
- test_is_downloaded_dir_not_readable(): tests that the function handles the case where the 'model_dir' directory is not readable. Tags: [general behavior]
- test_is_downloaded_specific_dir_structure(): tests that the function assumes a specific directory structure for downloaded models. Tags: [general behavior]
- test_is_downloaded_specific_model_name_format(): tests that the function assumes a specific format for the 'model_name' parameter. Tags: [general behavior]
"""
class TestIsDownloaded:
def test_is_downloaded_exists(self):
assert is_downloaded("gpt2")
assert is_downloaded("facebook/opt-iml-max-1.3b")
assert is_downloaded("facebook/opt-iml-max-30b")
def test_is_downloaded_not_exists(self):
assert not is_downloaded("non-existent-model")
def test_is_downloaded_empty_model_name(self):
assert not is_downloaded("")
def test_is_downloaded_invalid_model_name(self):
assert not is_downloaded("model/with/invalid/characters")
def test_is_downloaded_only_directories(self):
assert not is_downloaded("gpt2/vocab.txt")