-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a few tests for pipeline cloud (#72)
* add a few tests for pipeline cloud and have to cleanup too many flake8 errs * Refactor schemes for future metrics changes (#74) * Refactor schemes for future metrics changes * Update version * Add schemas for hardware related metrics (#75) * Add schemas for hardware metrics * Add project_id to metrics * Refactor schemes for future metrics changes (#74) * Refactor schemes for future metrics changes * Update version * Add schemas for hardware related metrics (#75) * Add schemas for hardware metrics * Add project_id to metrics * add a few tests for pipeline cloud and have to cleanup too many flake8 errs Co-authored-by: andrei-trandafir <47391556+andrei-trandafir@users.noreply.github.com>
- Loading branch information
1 parent
d982bdc
commit b7de643
Showing
15 changed files
with
166 additions
and
31 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import json | ||
|
||
|
||
from pipeline import Pipeline, PipelineCloud, Variable, pipeline_function | ||
|
||
api = PipelineCloud() | ||
|
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,4 +1,4 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
extend-ignore = "E203" | ||
per-file-ignores = tests/schemas/test_imports.py:F401 | ||
per-file-ignores = tests/schemas/test_imports.py:F401 tests/test_serialization.py:E501 examples/huggingface/gpt-j-6b.py:E203 |
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,88 @@ | ||
from datetime import datetime | ||
|
||
import pytest | ||
import responses | ||
from responses import matchers | ||
|
||
from pipeline.schemas.data import DataGet | ||
from pipeline.schemas.file import FileGet | ||
|
||
python_content = """ | ||
from pipeline.objects import Pipeline, Variable, pipeline_function | ||
# Check if the decorator correctly uses __init__ and __enter__ | ||
def test_with_decorator(): | ||
with Pipeline("test"): | ||
assert Pipeline._current_pipeline is not None | ||
""" | ||
|
||
|
||
@pytest.fixture | ||
def api_response(url, token, bad_token, file_get_json): | ||
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | ||
rsps.add( | ||
responses.GET, | ||
url + "/v2/users/me", | ||
json={"auth": True}, | ||
status=200, | ||
match=[matchers.header_matcher({"Authorization": "Bearer " + token})], | ||
) | ||
rsps.add( | ||
responses.GET, | ||
url + "/v2/users/me", | ||
json={"auth": True}, | ||
status=401, | ||
match=[matchers.header_matcher({"Authorization": "Bearer " + bad_token})], | ||
) | ||
rsps.add( | ||
responses.POST, | ||
url + "/v2/files/", | ||
json=file_get_json, | ||
status=201, | ||
match=[matchers.header_matcher({"Authorization": "Bearer " + token})], | ||
) | ||
yield rsps | ||
|
||
|
||
@pytest.fixture() | ||
def url(): | ||
return "http://127.0.0.1:8080" | ||
|
||
|
||
@pytest.fixture() | ||
def token(): | ||
return "token" | ||
|
||
|
||
@pytest.fixture() | ||
def bad_token(): | ||
return "bad_token" | ||
|
||
|
||
@pytest.fixture() | ||
def tmp_file(): | ||
return "tests/test_model.py" | ||
|
||
|
||
@pytest.fixture() | ||
def file_get_json(): | ||
return { | ||
"name": "test", | ||
"id": "file_test", | ||
"path": "test/path/to/file", | ||
"data": "data", | ||
"file_size": 8, | ||
} | ||
|
||
|
||
@pytest.fixture() | ||
def file_get(): | ||
return FileGet( | ||
name="test", id="file_test", path="test/path/to/file", data="data", file_size=8 | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def data_get(file_get): | ||
return DataGet(id="data_test", hex_file=file_get, created_at=datetime.now()) |
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,25 @@ | ||
import http | ||
|
||
import pytest | ||
|
||
from pipeline import PipelineCloud | ||
|
||
|
||
@pytest.mark.usefixtures("api_response") | ||
def test_cloud_init(url, token): | ||
api = PipelineCloud(url, token) | ||
assert api.token == token | ||
|
||
|
||
@pytest.mark.usefixtures("api_response") | ||
def test_cloud_init_failure(url, bad_token): | ||
with pytest.raises(Exception) as e: | ||
PipelineCloud(url, bad_token) | ||
assert e.status == http.HTTPStatus.UNAUTHORIZED | ||
|
||
|
||
@pytest.mark.usefixtures("api_response") | ||
def test_cloud_upload_file(url, token, file_get, tmp_file): | ||
api = PipelineCloud(url, token) | ||
f = api.upload_file(tmp_file, "remote_path") | ||
assert f == file_get |
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