yonikremer
commited on
Commit
·
b7eab4d
1
Parent(s):
bdded84
testing the is_downloaded function
Browse files- test_is_downloaded.py +48 -0
test_is_downloaded.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# test_hanlde_form_submit.py - Generated by CodiumAI
|
2 |
+
import os
|
3 |
+
|
4 |
+
import pytest
|
5 |
+
|
6 |
+
from hanlde_form_submit import is_downloaded
|
7 |
+
|
8 |
+
"""
|
9 |
+
Code Analysis:
|
10 |
+
- The main goal of the function is to check if a specific model is downloaded or not.
|
11 |
+
- The function takes a string parameter 'model_name' which is the name of the model to be checked.
|
12 |
+
- It then sets the 'models_dir' variable to the directory where the downloaded models are stored.
|
13 |
+
- The function then creates a new variable 'model_dir' by joining the 'models_dir' and the 'model_name' parameter with a specific format.
|
14 |
+
- The function then checks if the 'model_dir' exists as a directory using the 'os.path.isdir' method.
|
15 |
+
- If the directory exists, the function returns True, indicating that the model is downloaded.
|
16 |
+
- If the directory does not exist, the function returns False, indicating that the model is not downloaded.
|
17 |
+
"""
|
18 |
+
|
19 |
+
"""
|
20 |
+
Test Plan:
|
21 |
+
- test_is_downloaded_exists(): tests that the function correctly identifies that a downloaded model exists and returns True. Tags: [happy path]
|
22 |
+
- test_is_downloaded_not_exists(): tests that the function correctly identifies that a downloaded model does not exist and returns False. Tags: [happy path]
|
23 |
+
- test_is_downloaded_empty_model_name(): tests that the function handles an empty string for the 'model_name' parameter. Tags: [edge case]
|
24 |
+
- 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]
|
25 |
+
- test_is_downloaded_only_directories(): tests that the function only checks for directories, not files. Tags: [general behavior]
|
26 |
+
- test_is_downloaded_dir_not_exist(): tests that the function handles the case where the 'models_dir' directory does not exist. Tags: [edge case]
|
27 |
+
- test_is_downloaded_dir_not_writable(): tests that the function handles the case where the 'models_dir' directory is not writable. Tags: [general behavior]
|
28 |
+
- test_is_downloaded_dir_not_readable(): tests that the function handles the case where the 'model_dir' directory is not readable. Tags: [general behavior]
|
29 |
+
- test_is_downloaded_specific_dir_structure(): tests that the function assumes a specific directory structure for downloaded models. Tags: [general behavior]
|
30 |
+
- test_is_downloaded_specific_model_name_format(): tests that the function assumes a specific format for the 'model_name' parameter. Tags: [general behavior]
|
31 |
+
"""
|
32 |
+
|
33 |
+
|
34 |
+
class TestIsDownloaded:
|
35 |
+
def test_is_downloaded_exists(self):
|
36 |
+
assert is_downloaded("gpt2")
|
37 |
+
|
38 |
+
def test_is_downloaded_not_exists(self):
|
39 |
+
assert not is_downloaded("non-existent-model")
|
40 |
+
|
41 |
+
def test_is_downloaded_empty_model_name(self):
|
42 |
+
assert not is_downloaded("")
|
43 |
+
|
44 |
+
def test_is_downloaded_invalid_model_name(self):
|
45 |
+
assert not is_downloaded("model/with/invalid/characters")
|
46 |
+
|
47 |
+
def test_is_downloaded_only_directories(self):
|
48 |
+
assert not is_downloaded("gpt2/vocab.txt")
|