-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests and fix some function loading issues
- Loading branch information
Showing
7 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,10 @@ | |
.ipynb_checkpoints/ | ||
|
||
/py3env | ||
__pycache__/ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
/dist/ | ||
/build/ | ||
/sysrev.egg-info/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .funcs import Client | ||
from .client import Client |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from sysrev.client import Client | ||
|
||
class TestClient(unittest.TestCase): | ||
def setUp(self): | ||
# Create a Client instance with a fake API key for testing | ||
self.client = Client(api_key='fake_api_key') | ||
|
||
@patch('sysrev.client.requests.get') | ||
def test_get_project_info(self, mock_get): | ||
# Configure the mock to return a JSON response | ||
mock_get.return_value.status_code = 200 | ||
mock_get.return_value.json.return_value = {'project': {'id': 123, 'name': 'Test Project'}} | ||
|
||
# Call the function | ||
response = self.client.get_project_info(project_id=123) | ||
|
||
# Check that the requests.get was called correctly | ||
mock_get.assert_called_once_with( | ||
'https://www.sysrev.com/api-json/project-info', | ||
headers={'Authorization': 'Bearer fake_api_key'}, | ||
params={'project-id': 123} | ||
) | ||
|
||
# Verify the response | ||
self.assertEqual(response, {'project': {'id': 123, 'name': 'Test Project'}}) | ||
|
||
@patch('sysrev.client.requests.post') | ||
def test_set_labels(self, mock_post): | ||
# Configure the mock to return a JSON response | ||
mock_post.return_value.status_code = 200 | ||
mock_post.return_value.json.return_value = {'success': True} | ||
|
||
# Dummy data for the test | ||
label_ids = [1, 2] | ||
label_values = ['yes', 'no'] | ||
label_types = ['boolean', 'boolean'] | ||
|
||
# Call the function | ||
response = self.client.set_labels( | ||
project_id=456, article_id=789, label_ids=label_ids, | ||
label_values=label_values, label_types=label_types, | ||
confirm=True, change=False, resolve=False | ||
) | ||
|
||
# Check that the requests.post was called correctly | ||
mock_post.assert_called_once() | ||
|
||
# Verify the response | ||
self.assertEqual(response, {'success': True}) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import unittest | ||
from sysrev.client import LabelTransformer | ||
|
||
class TestLabelTransformer(unittest.TestCase): | ||
def test_handle_boolean_true(self): | ||
lt = LabelTransformer() | ||
self.assertTrue(lt.handle_boolean('yes')) | ||
|
||
def test_handle_boolean_false(self): | ||
lt = LabelTransformer() | ||
self.assertFalse(lt.handle_boolean('no')) | ||
|
||
def test_handle_boolean_raises(self): | ||
lt = LabelTransformer() | ||
with self.assertRaises(ValueError): | ||
lt.handle_boolean('maybe') | ||
|
||
def test_handle_categorical_or_string_single(self): | ||
lt = LabelTransformer() | ||
self.assertEqual(lt.handle_categorical_or_string('test'), ['test']) | ||
|
||
def test_handle_categorical_or_string_list(self): | ||
lt = LabelTransformer() | ||
self.assertEqual(lt.handle_categorical_or_string(['test', 'test2']), ['test', 'test2']) | ||
|
||
def test_handle_categorical_or_string_raises(self): | ||
lt = LabelTransformer() | ||
with self.assertRaises(ValueError): | ||
lt.handle_categorical_or_string(['test', 123]) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |