-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dbanda/replayer-match-ops-labels
- Loading branch information
Showing
11 changed files
with
192 additions
and
17 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
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
|
||
from snuba.pipeline.query_pipeline import ( | ||
InvalidQueryPipelineResult, | ||
QueryPipelineResult, | ||
QueryPipelineStage, | ||
) | ||
|
||
|
||
class TestQueryPipelineStage(QueryPipelineStage[int, int]): | ||
def _execute(self, input: QueryPipelineResult[int]) -> QueryPipelineResult[int]: | ||
try: | ||
result = check_input_and_multiply(input.data) | ||
return QueryPipelineResult(result, None) | ||
except Exception as e: | ||
return QueryPipelineResult(None, e) | ||
|
||
|
||
def check_input_and_multiply(num: Optional[int]) -> int: | ||
if num == 0 or num is None: | ||
raise Exception("Input cannot be zero") | ||
return num * 2 | ||
|
||
|
||
def test_query_pipeline_stage() -> None: | ||
input = QueryPipelineResult(data=1, error=None) | ||
result = TestQueryPipelineStage().execute(input) | ||
assert result.data == 2 | ||
|
||
input = QueryPipelineResult(data=0, error=None) | ||
result = TestQueryPipelineStage().execute(input) | ||
assert str(result.error) == "Input cannot be zero" | ||
|
||
with pytest.raises(InvalidQueryPipelineResult): | ||
input = QueryPipelineResult(data=None, error=None) |