Repository: Kota-Karthik/twinTrim (language: python)

Issue:
Test Regex for File Type Matching in `filter_files`

   - **Description**: Write tests to verify that the regex for file type matching in the `filter_files` method behaves as expected, including edge cases for file names with multiple extensions.
   - **Resources**: Refer to the [pytest getting started guide](https://docs.pytest.org/en/stable/getting-started.html) for writing tests.
   - **Path**: `twinTrim/dataStructures/fileFilter.py`
   - **Note**: Ensure to maintain the file structure as per the existing files and tests, and add these tests.


Discussion / hints:
@Kota-Karthik please assign this issue to me 
@smartfellow1234 
Yes,
make sure to create a separate branch before making the necessary changes and retain the folder structure.

Fix patch:
diff --git a/poetry.lock b/poetry.lock
index 5d40ce3..756b9ec 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -25,6 +25,90 @@ files = [
     {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
 ]
 
+[[package]]
+name = "exceptiongroup"
+version = "1.2.2"
+description = "Backport of PEP 654 (exception groups)"
+optional = false
+python-versions = ">=3.7"
+files = [
+    {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"},
+    {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"},
+]
+
+[package.extras]
+test = ["pytest (>=6)"]
+
+[[package]]
+name = "iniconfig"
+version = "2.0.0"
+description = "brain-dead simple config-ini parsing"
+optional = false
+python-versions = ">=3.7"
+files = [
+    {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"},
+    {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"},
+]
+
+[[package]]
+name = "packaging"
+version = "24.1"
+description = "Core utilities for Python packages"
+optional = false
+python-versions = ">=3.8"
+files = [
+    {file = "packaging-24.1-py3-none-any.whl", hash = "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"},
+    {file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"},
+]
+
+[[package]]
+name = "pluggy"
+version = "1.5.0"
+description = "plugin and hook calling mechanisms for python"
+optional = false
+python-versions = ">=3.8"
+files = [
+    {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"},
+    {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"},
+]
+
+[package.extras]
+dev = ["pre-commit", "tox"]
+testing = ["pytest", "pytest-benchmark"]
+
+[[package]]
+name = "pytest"
+version = "8.3.3"
+description = "pytest: simple powerful testing with Python"
+optional = false
+python-versions = ">=3.8"
+files = [
+    {file = "pytest-8.3.3-py3-none-any.whl", hash = "sha256:a6853c7375b2663155079443d2e45de913a911a11d669df02a50814944db57b2"},
+    {file = "pytest-8.3.3.tar.gz", hash = "sha256:70b98107bd648308a7952b06e6ca9a50bc660be218d53c257cc1fc94fda10181"},
+]
+
+[package.dependencies]
+colorama = {version = "*", markers = "sys_platform == \"win32\""}
+exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""}
+iniconfig = "*"
+packaging = "*"
+pluggy = ">=1.5,<2"
+tomli = {version = ">=1", markers = "python_version < \"3.11\""}
+
+[package.extras]
+dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
+
+[[package]]
+name = "tomli"
+version = "2.0.1"
+description = "A lil' TOML parser"
+optional = false
+python-versions = ">=3.7"
+files = [
+    {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
+    {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
+]
+
 [[package]]
 name = "tqdm"
 version = "4.66.5"
@@ -48,4 +132,4 @@ telegram = ["requests"]
 [metadata]
 lock-version = "2.0"
 python-versions = "^3.8"
-content-hash = "72c796aec58686a99594c38b20f4e5ea31740184948b1de562de7dcf50b30027"
+content-hash = "091544b18d7f441657d74777e07d3b55b41d18505b7aee4d99facd1ac3b90ade"
diff --git a/pyproject.toml b/pyproject.toml
index 4ce1f09..4550d28 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -10,6 +10,9 @@ python = "^3.8"
 click = "^8.0"  # For creating CLI commands
 tqdm = "^4.66.5"
 
+[tool.poetry.group.dev.dependencies]
+pytest = "^8.3.3"
+
 [build-system]
 requires = ["poetry-core>=1.0.0"]
 build-backend = "poetry.core.masonry.api"
diff --git a/twinTrim/utils.py b/twinTrim/utils.py
index 2aac566..76f9ac9 100644
--- a/twinTrim/utils.py
+++ b/twinTrim/utils.py
@@ -26,11 +26,16 @@ def get_file_hash(file_path):
 
 def parse_size(size_str):
     size_str = size_str.lower()
-    if size_str.endswith('kb'):
-        return int(float(size_str[:-2]) * 1024)
-    elif size_str.endswith('mb'):
-        return int(float(size_str[:-2]) * 1024 * 1024)
-    elif size_str.endswith('gb'):
-        return int(float(size_str[:-2]) * 1024 * 1024 * 1024)
-    else:
-        return int(size_str)
\ No newline at end of file
+    try:
+        if size_str.endswith('kb'):
+            return int(float(size_str[:-2]) * 1024)
+        elif size_str.endswith('mb'):
+            return int(float(size_str[:-2]) * 1024 * 1024)
+        elif size_str.endswith('gb'):
+            return int(float(size_str[:-2]) * 1024 * 1024 * 1024)
+        else:
+            # Attempt to convert size_str to an integer
+            return int(size_str)  # This can also be modified to handle sizes without suffix
+    except ValueError:
+        # If conversion fails, return 0 for invalid formats
+        return 0


Test patch:
diff --git a/tests/test_fileFilter.py b/tests/test_fileFilter.py
new file mode 100644
index 0000000..b480cff
--- /dev/null
+++ b/tests/test_fileFilter.py
@@ -0,0 +1,44 @@
+import pytest
+from twinTrim.dataStructures.fileFilter import FileFilter
+
+def test_set_max_file_size_valid():
+    """Test setting valid max file size values."""
+    file_filter = FileFilter()
+
+    # Test with a smaller size
+    file_filter.setMaxFileSize("500mb")
+    assert file_filter.maxFileSize == "500mb", "Failed to set max file size to 500mb"
+
+    # Test with a larger size
+    file_filter.setMaxFileSize("2gb")
+    assert file_filter.maxFileSize == "2gb", "Failed to set max file size to 2gb"
+
+    # Test with a minimum size (edge case)
+    file_filter.setMaxFileSize("1kb")
+    assert file_filter.maxFileSize == "1kb", "Failed to set max file size to 1kb"
+
+def test_set_max_file_size_same_value():
+    """Test setting the same max file size."""
+    file_filter = FileFilter()
+
+    # Test setting the max file size to the default value
+    file_filter.setMaxFileSize("1gb")
+    assert file_filter.maxFileSize == "1gb", "Failed to set max file size to 1gb"
+
+def test_set_max_file_size_boundary():
+    """Test boundary values for max file size."""
+    file_filter = FileFilter()
+
+    # Test setting a value just under the default
+    file_filter.setMaxFileSize("999mb")
+    assert file_filter.maxFileSize == "999mb", "Failed to set max file size to 999mb"
+
+def test_set_max_file_size_empty_value():
+    """Test setting an empty value to max file size."""
+    file_filter = FileFilter()
+
+    # Since there is no validation, an empty value would still set it to the empty string
+    file_filter.setMaxFileSize("")
+    assert file_filter.maxFileSize == "", "Failed to set max file size to empty value"
+
+
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644
index 0000000..7a87c29
--- /dev/null
+++ b/tests/test_utils.py
@@ -0,0 +1,63 @@
+import os
+import pytest
+import tempfile
+from twinTrim.utils import parse_size, get_file_hash  # Adjust based on actual import path
+
+# Tests for parse_size function
+def test_parse_size_valid():
+    # Test valid size strings
+    assert parse_size("10kb") == 10 * 1024  # 10 * 1024 bytes = 10240
+    assert parse_size("1mb") == 1 * 1024 * 1024  # 1 * 1024 * 1024 bytes = 1048576
+    assert parse_size("1.5gb") == int(1.5 * 1024 * 1024 * 1024)  # 1610612736 bytes
+    assert parse_size("0kb") == 0  # Edge case: 0kb should be 0
+    assert parse_size("0mb") == 0  # Edge case: 0mb should be 0
+    assert parse_size("0gb") == 0  # Edge case: 0gb should be 0
+
+def test_parse_size_invalid():
+    # Test invalid size strings
+    assert parse_size("abc") == 0  # Non-numeric input should return 0
+    assert parse_size("10x") == 0
+    assert parse_size("100.5xyz") == 0
+
+    # Uncomment to raise exceptions for invalid formats:
+    # with pytest.raises(ValueError):
+    #     parse_size("abc")
+    # with pytest.raises(ValueError):
+    #     parse_size("10x")
+    # with pytest.raises(ValueError):
+    #     parse_size("100.5xyz")
+
+# Fixture for creating a temporary file with 'hello' content
+@pytest.fixture
+def create_temp_file():
+    """Fixture to create a temporary file with known content."""
+    with tempfile.NamedTemporaryFile(delete=False, mode='w+') as tmp_file:
+        tmp_file.write("hello")  # Write 'hello' to the file for hashing
+        tmp_file.flush()  # Flush to ensure the content is written
+        yield tmp_file.name  # Provide the name for the test
+    os.remove(tmp_file.name)  # Cleanup after test
+
+@pytest.fixture
+def create_empty_file():
+    """Fixture to create an empty temporary file."""
+    with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
+        yield tmp_file.name  # Provide the name for the test
+    os.remove(tmp_file.name)  # Cleanup after test
+
+# Tests for get_file_hash function
+def test_get_file_hash_regular_file(create_temp_file):
+    """Test hashing for a regular file with known content."""
+    hash_value = get_file_hash(create_temp_file)
+    expected_hash = "5d41402abc4b2a76b9719d911017c592"  # MD5 hash for 'hello'
+    assert hash_value == expected_hash
+
+def test_get_file_hash_empty_file(create_empty_file):
+    """Test hashing for an empty file."""
+    hash_value = get_file_hash(create_empty_file)
+    expected_hash = "d41d8cd98f00b204e9800998ecf8427e"  # MD5 hash for an empty file
+    assert hash_value == expected_hash
+
+def test_get_file_hash_non_existent_file():
+    """Test handling of non-existent file."""
+    with pytest.raises(FileNotFoundError):
+        get_file_hash("non_existent_file.txt")