Skip to content

Commit

Permalink
update unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
cehune committed Dec 5, 2024
1 parent 52d51e6 commit 65d6276
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest source/tests/test_utils.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
pytest src/file_auto_expiry/tests/test_utils.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "file_auto_expiry"
version = "0.0.5"
version = "0.0.6"
description = "WATCloud project containing scripts to check if directories / files are expired"
readme = "README.md"
requires-python = ">=3.7, <4"
Expand Down
3 changes: 2 additions & 1 deletion src/file_auto_expiry/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def test_is_expired_filepath(self, patch_stat):

@patch('os.listdir')
@patch("os.stat")
@patch("os.open")
@patch("utils.expiry_checks.is_expired")
def test_is_expired_folder(self, patch_expired, patch_stat, patch_path):
def test_is_expired_folder(self, patch_expired, patch_open, patch_stat, patch_path):
"""
Tests the is_expired_folder function. This should return
True (is_expired) if all subdirectories and files are also expired.
Expand Down
10 changes: 5 additions & 5 deletions src/file_auto_expiry/utils/expiry_checks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import stat
from ..data.expiry_constants import *
from ..data.expiry_constants import DIRECTORIES_TO_IGNORE
from ..data.tuples import *
from .file_creator import *
from src.file_auto_expiry.data.expiry_constants import *
from src.file_auto_expiry.data.expiry_constants import DIRECTORIES_TO_IGNORE
from src.file_auto_expiry.data.tuples import *
from src.file_auto_expiry.utils.file_creator import *
import datetime

def is_expired(path, expiry_threshold):
Expand Down Expand Up @@ -133,7 +133,7 @@ def is_expired_folder(folder_path, folder_stat, expiry_threshold):
recent_atime = max(recent_atime, file_expiry_information.atime)
recent_ctime = max(recent_ctime, file_expiry_information.ctime)
recent_mtime = max(recent_mtime, file_expiry_information.mtime)

os.close(dirfd)
return expiry_tuple(is_expired_flag, file_creators, recent_atime,
recent_ctime, recent_mtime)

Expand Down
4 changes: 2 additions & 2 deletions src/file_auto_expiry/utils/file_creator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import pwd
from ..data.tuples import *
from src.file_auto_expiry.data.tuples import *

def get_file_creator(path):
"""
Returns a tuple including the file creator username,
Returns a tuple including the file creator username,
their UID, and GID in that order respectively.
string file_path: The absolute path of the file
Expand Down
7 changes: 4 additions & 3 deletions src/file_auto_expiry/utils/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import json
import datetime
import time
from ..data.expiry_constants import *
from ..data.tuples import *
from .expiry_checks import is_expired
from src.file_auto_expiry.data.expiry_constants import *
from src.file_auto_expiry.data.tuples import *
from src.file_auto_expiry.utils.expiry_checks import is_expired

def get_file_creator(path):
"""
Expand Down Expand Up @@ -48,6 +48,7 @@ def scan_folder_for_expired(folder_path, expiry_threshold):
# path, creator tuple (name, uid, gid), atime, ctime, mtime
yield entry_path, expiry_result.is_expired, expiry_result.creators, \
expiry_result.atime, expiry_result.ctime, expiry_result.mtime
os.close(dirfd)

def collect_expired_file_information(folder_path, save_file, scrape_time, expiry_threshold):
"""
Expand Down

0 comments on commit 65d6276

Please sign in to comment.