-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from VatsalJagani/more-test-cases
More-test-cases
- Loading branch information
Showing
5 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os, sys | ||
|
||
# path to be added -> /<this-repo>/tests/src | ||
sys.path.insert(0, os.path.join( | ||
os.path.dirname(os.path.dirname(__file__)), | ||
'src' | ||
) | ||
) | ||
|
||
import pytest | ||
from helpers.git_manager import get_file_hash, get_folder_hash, get_multi_files_hash | ||
|
||
|
||
# Use a fixture to create temporary files with known content for testing | ||
@pytest.fixture | ||
def sample_file(tmp_path): | ||
file_path = tmp_path / "test_file.txt" | ||
file_path.write_text("This is a test file") | ||
return file_path | ||
|
||
|
||
def test_get_file_hash_nonexistent_file(): | ||
file_path = "path/to/nonexistent_file" | ||
with pytest.raises(FileNotFoundError): | ||
get_file_hash(file_path) | ||
|
||
def test_get_file_hash_with_tmp_file(sample_file): | ||
expected_hash = "0b26e313ed4a7ca6904b0e9369e5b957" # MD5 hash of "This is a test file" | ||
assert get_file_hash(sample_file) == expected_hash | ||
|
||
def test_get_folder_hash_empty_folder(): | ||
folder_path = "empty_folder" | ||
os.makedirs(folder_path) | ||
expected_hash = "d41d8cd98f00b204e9800998ecf8427e" # MD5 hash of an empty string | ||
assert get_folder_hash(folder_path) == expected_hash | ||
os.rmdir(folder_path) | ||
|
||
def test_get_folder_hash_with_files(sample_file): | ||
folder_path = sample_file.parent | ||
expected_hash = "894c0cee919eb49f7a36060c7a607fb7" # Hash of the single file in the folder | ||
assert get_folder_hash(folder_path) == expected_hash | ||
|
||
def test_get_folder_hash_nonexistent_folder(): | ||
folder_path = "path/to/nonexistent_folder" | ||
with pytest.raises(Exception, match="Incorrect folder_path provided."): | ||
abc = get_folder_hash(folder_path) | ||
print(f"abc={abc}") | ||
|
||
def test_get_multi_files_hash_empty_list(): | ||
file_paths = [] | ||
expected_hash = "d41d8cd98f00b204e9800998ecf8427e" # MD5 hash of an empty string | ||
assert get_multi_files_hash(file_paths) == expected_hash | ||
|
||
def test_get_multi_files_hash_multiple_files(sample_file): | ||
file_paths = [sample_file, sample_file] # Use the same file twice for simplicity | ||
expected_hash = "91405dbee0a9c47e7bc657bda7cb29a9" # Hypothetical hash of the combined hashes | ||
assert get_multi_files_hash(file_paths) == expected_hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os, sys | ||
|
||
# path to be added -> /<this-repo>/tests/src | ||
sys.path.insert(0, os.path.join( | ||
os.path.dirname(os.path.dirname(__file__)), | ||
'src' | ||
) | ||
) | ||
|
||
from helpers.github_action_utils import str_to_boolean_default_false, str_to_boolean_default_true | ||
|
||
|
||
def test_str_to_boolean_default_true_positive_cases(): | ||
assert str_to_boolean_default_true("true") is True | ||
assert str_to_boolean_default_true("T") is True | ||
assert str_to_boolean_default_true("1") is True | ||
assert str_to_boolean_default_true("YES") is True | ||
|
||
def test_str_to_boolean_default_true_negative_cases(): | ||
assert str_to_boolean_default_true("false") is False | ||
assert str_to_boolean_default_true("f") is False | ||
assert str_to_boolean_default_true("0") is False | ||
assert str_to_boolean_default_true("no") is False | ||
assert str_to_boolean_default_true("") is True # Empty string defaults to True | ||
|
||
def test_str_to_boolean_default_false_positive_cases(): | ||
assert str_to_boolean_default_false("true") is True | ||
assert str_to_boolean_default_false("t") is True | ||
assert str_to_boolean_default_false("1") is True | ||
assert str_to_boolean_default_false("yes") is True | ||
|
||
def test_str_to_boolean_default_false_negative_cases(): | ||
assert str_to_boolean_default_false("false") is False | ||
assert str_to_boolean_default_false("f") is False | ||
assert str_to_boolean_default_false("0") is False | ||
assert str_to_boolean_default_false("no") is False | ||
assert str_to_boolean_default_false("") is False # Empty string defaults to False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
import os, sys | ||
|
||
# path to be added -> /<this-repo>/tests/src | ||
sys.path.insert(0, os.path.join( | ||
os.path.dirname(os.path.dirname(__file__)), | ||
'src' | ||
) | ||
) | ||
|
||
from helpers.global_variables import GlobalVariables | ||
|
||
def test_initiate_valid_args(): | ||
# Set up | ||
app_dir_name = "my_app" | ||
repodir_name = "custom_repo" | ||
root_dir_path = "/path/to/project" | ||
|
||
# Call the method | ||
GlobalVariables.initiate(app_dir_name, repodir_name, root_dir_path) | ||
|
||
# Assertions | ||
assert GlobalVariables.ROOT_DIR_PATH == root_dir_path | ||
assert GlobalVariables.ORIGINAL_REPO_DIR_NAME == repodir_name | ||
assert GlobalVariables.ORIGINAL_REPO_DIR_PATH == os.path.join(root_dir_path, repodir_name) | ||
assert GlobalVariables.APP_DIR_NAME == app_dir_name | ||
assert GlobalVariables.ORIGINAL_APP_DIR_PATH == os.path.join(GlobalVariables.ORIGINAL_REPO_DIR_PATH, app_dir_name) | ||
|
||
# Cleanup (optional, reset variables) | ||
GlobalVariables.ROOT_DIR_PATH = None | ||
GlobalVariables.ORIGINAL_REPO_DIR_NAME = None | ||
GlobalVariables.ORIGINAL_REPO_DIR_PATH = None | ||
GlobalVariables.APP_DIR_NAME = None | ||
GlobalVariables.ORIGINAL_APP_DIR_PATH = None | ||
|
||
def test_initiate_missing_args(): | ||
# Set up | ||
app_dir_name = "my_app" | ||
|
||
# Call the method | ||
GlobalVariables.initiate(app_dir_name) | ||
|
||
# Assertions (using os.getcwd() for current working directory) | ||
assert GlobalVariables.ROOT_DIR_PATH == os.getcwd() | ||
assert GlobalVariables.ORIGINAL_REPO_DIR_NAME == "repodir" | ||
assert GlobalVariables.ORIGINAL_REPO_DIR_PATH == os.path.join(GlobalVariables.ROOT_DIR_PATH, "repodir") | ||
assert GlobalVariables.APP_DIR_NAME == app_dir_name | ||
assert GlobalVariables.ORIGINAL_APP_DIR_PATH == os.path.join(GlobalVariables.ORIGINAL_REPO_DIR_PATH, app_dir_name) | ||
|
||
# Cleanup (optional, reset variables) | ||
GlobalVariables.ROOT_DIR_PATH = None | ||
GlobalVariables.ORIGINAL_REPO_DIR_NAME = None | ||
GlobalVariables.ORIGINAL_REPO_DIR_PATH = None | ||
GlobalVariables.APP_DIR_NAME = None | ||
GlobalVariables.ORIGINAL_APP_DIR_PATH = None | ||
|
||
def test_set_app_package_id(): | ||
package_id = "my_app_id" | ||
GlobalVariables.set_app_package_id(package_id) | ||
assert GlobalVariables.APP_PACKAGE_ID == package_id | ||
|
||
def test_set_app_version(): | ||
version = "1.2.3" | ||
GlobalVariables.set_app_version(version) | ||
assert GlobalVariables.APP_VERSION == version | ||
assert GlobalVariables.APP_VERSION_ENCODED == "1_2_3" # Encoded version | ||
|
||
# Cleanup (optional, reset variables) | ||
GlobalVariables.APP_VERSION = None | ||
GlobalVariables.APP_VERSION_ENCODED = None | ||
|
||
def test_set_app_build_number(): | ||
build_number = "456" | ||
GlobalVariables.set_app_build_number(build_number) | ||
assert GlobalVariables.APP_BUILD_NUMBER == build_number | ||
assert GlobalVariables.APP_BUILD_NUMBER_ENCODED == "456" # Encoded build number | ||
|
||
# Cleanup (optional, reset variables) | ||
GlobalVariables.APP_BUILD_NUMBER = None | ||
GlobalVariables.APP_BUILD_NUMBER_ENCODED = None |