Skip to content

Commit 6d50d3c

Browse files
committed
feat: unit tests
1 parent f9e09a0 commit 6d50d3c

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

.github/workflows/CI_tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI | Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
- 'master'
8+
- '!master-ci'
9+
- '!release'
10+
11+
pull_request:
12+
branches:
13+
- master
14+
15+
workflow_dispatch:
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Set up Python 3.11
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: 3.11.0
28+
29+
- name: Install Dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
python setup.py install
33+
pip install pytest
34+
35+
- name: Run Tests
36+
run: |
37+
pytest

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
''' Allows the tests to be run from the top level directory.'''

tests/serverless_tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
''' Allows the import of serverless_tests as a module. '''
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
''' Tests for runpod | serverless| modules | download.py '''
2+
3+
import unittest
4+
from unittest import mock
5+
from unittest.mock import patch, MagicMock, mock_open
6+
7+
from runpod.serverless.modules.download import download_input_objects
8+
9+
10+
def mock_requests_get(*args, **kwargs):
11+
'''
12+
Mocks requests.get
13+
'''
14+
class MockResponse:
15+
''' Mocks requests.get response '''
16+
17+
def __init__(self, content, status_code):
18+
'''
19+
Mocks requests.get response
20+
'''
21+
self.content = content
22+
self.status_code = status_code
23+
24+
if args[0] == 'https://example.com/picture.jpg':
25+
return MockResponse(b'nothing', 200)
26+
27+
return MockResponse(None, 404)
28+
29+
30+
class TestDownloadInputObjects(unittest.TestCase):
31+
''' Tests for download_input_objects '''
32+
33+
@patch('requests.get', side_effect=mock_requests_get)
34+
@patch('builtins.open', new_callable=mock_open)
35+
def test_download_input_objects(self):
36+
'''
37+
Tests download_input_objects
38+
'''
39+
objects = download_input_objects(
40+
['https://example.com/picture.jpg', ]
41+
)

0 commit comments

Comments
 (0)