Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ def test_s3_connection(self, mock_client):

class TestDownloadCoreFunctionality(unittest.TestCase):

@patch('llm_web_kit.model.resource_utils.download_assets.CACHE_TMP_DIR')
@patch('llm_web_kit.model.resource_utils.download_assets.S3Connection')
def test_successful_download(self, mock_conn):
def test_successful_download(self, mock_conn, mock_cache_tmp_dir):
mock_cache_tmp_dir.return_value = '/tmp'
# Mock connection
download_data = b'data'
mock_instance = MagicMock()
Expand All @@ -81,8 +83,10 @@ def test_successful_download(self, mock_conn):
assert result == target
assert os.path.exists(target)

@patch('llm_web_kit.model.resource_utils.download_assets.CACHE_TMP_DIR')
@patch('llm_web_kit.model.resource_utils.download_assets.HttpConnection')
def test_size_mismatch(self, mock_conn):
def test_size_mismatch(self, mock_conn, mock_cache_tmp_dir):
mock_cache_tmp_dir.return_value = '/tmp'
download_data = b'data'
mock_instance = MagicMock()
mock_instance.read_stream.return_value = [download_data]
Expand All @@ -92,6 +96,7 @@ def test_size_mismatch(self, mock_conn):

with tempfile.TemporaryDirectory() as tmpdir:
target = os.path.join(tmpdir, 'target.file')
print(target)
with self.assertRaises(ModelResourceException):
download_auto_file_core('http://example.com', target)

Expand Down
3 changes: 3 additions & 0 deletions tests/llm_web_kit/model/resource_utils/test_unzip_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def test_target_directory_conflict(self):
unzip_local_file_core(self.zip_path, self.target_dir)
self.assertIn('already exists', str(cm.exception))

@patch('llm_web_kit.model.resource_utils.unzip_ext.CACHE_TMP_DIR', '/tmp')
def test_successful_extraction(self):
with zipfile.ZipFile(self.zip_path, 'w') as zipf:
zipf.writestr('file.txt', 'content')
Expand All @@ -114,6 +115,7 @@ def test_successful_extraction(self):
self.assertEqual(result, self.target_dir)
self.assertTrue(os.path.exists(os.path.join(self.target_dir, 'file.txt')))

@patch('llm_web_kit.model.resource_utils.unzip_ext.CACHE_TMP_DIR', '/tmp')
def test_password_protected_extraction(self):
password = 'secret'
with zipfile.ZipFile(self.zip_path, 'w') as zipf:
Expand All @@ -136,6 +138,7 @@ def setUp(self):
def tearDown(self):
self.temp_dir.cleanup()

@patch('llm_web_kit.model.resource_utils.unzip_ext.CACHE_TMP_DIR', '/tmp')
@patch(
'llm_web_kit.model.resource_utils.unzip_ext.process_and_verify_file_with_lock'
)
Expand Down