Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidparks21 committed Dec 9, 2023
1 parent e63e93d commit 7e2ae51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/braingeneers/utils/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import multiprocessing
import posixpath
import itertools
import pathlib


_s3_client = None # S3 client for boto3, lazy initialization performed in _lazy_init_s3_client()
Expand Down
16 changes: 8 additions & 8 deletions src/braingeneers/utils/common_utils_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import unittest
from unittest.mock import patch, MagicMock
import file_utils
import common_utils # Updated import statement
import os
import tempfile
from pathlib import Path


class TestFileListFunction(unittest.TestCase):

@patch('file_utils._lazy_init_s3_client')
@patch('common_utils._lazy_init_s3_client') # Updated to common_utils
def test_s3_files_exist(self, mock_s3_client):
# Mock S3 client response
mock_response = {
Expand All @@ -19,15 +19,15 @@ def test_s3_files_exist(self, mock_s3_client):
}
mock_s3_client.return_value.list_objects.return_value = mock_response

result = file_utils.file_list('s3://test-bucket/')
expected = [('file1.txt', '2023-01-01', 123), ('file2.txt', '2023-01-02', 456)]
result = common_utils.file_list('s3://test-bucket/') # Updated to common_utils
expected = [('file2.txt', '2023-01-02', 456), ('file1.txt', '2023-01-01', 123)]
self.assertEqual(result, expected)

@patch('file_utils._lazy_init_s3_client')
@patch('common_utils._lazy_init_s3_client') # Updated to common_utils
def test_s3_no_files(self, mock_s3_client):
# Mock S3 client response for no files
mock_s3_client.return_value.list_objects.return_value = {}
result = file_utils.file_list('s3://test-bucket/')
result = common_utils.file_list('s3://test-bucket/') # Updated to common_utils
self.assertEqual(result, [])

def test_local_files_exist(self):
Expand All @@ -36,13 +36,13 @@ def test_local_files_exist(self):
Path(temp_dir, 'tempfile1.txt').touch()
Path(temp_dir, 'tempfile2.txt').touch()

result = file_utils.file_list(temp_dir)
result = common_utils.file_list(temp_dir) # Updated to common_utils
# The result should contain two files with their details
self.assertEqual(len(result), 2)

def test_local_no_files(self):
with tempfile.TemporaryDirectory() as temp_dir:
result = file_utils.file_list(temp_dir)
result = common_utils.file_list(temp_dir) # Updated to common_utils
self.assertEqual(result, [])


Expand Down

0 comments on commit 7e2ae51

Please sign in to comment.