-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement interface check * Implement signature check * Add tests for parameter checks --------- Co-authored-by: Nicholas Junge <[email protected]>
- Loading branch information
1 parent
e2d4e6b
commit f17beab
Showing
5 changed files
with
104 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from nnbench import runner | ||
|
||
|
||
def test_argcheck(typecheckfolder: str) -> None: | ||
benchmarks = os.path.join(typecheckfolder, "benchmarks.py") | ||
r = runner.AbstractBenchmarkRunner() | ||
with pytest.raises(TypeError, match="expected type <class 'int'>.*"): | ||
r.run(benchmarks, params={"x": 1, "y": "1"}) | ||
with pytest.raises(ValueError, match="missing value for required parameter.*"): | ||
r.run(benchmarks, params={"x": 1}) | ||
|
||
r.run(benchmarks, params={"x": 1, "y": 1}) | ||
|
||
|
||
def test_error_on_duplicate_params(typecheckfolder: str) -> None: | ||
benchmarks = os.path.join(typecheckfolder, "duplicate_benchmarks.py") | ||
|
||
with pytest.raises(TypeError, match="got non-unique types.*"): | ||
r = runner.AbstractBenchmarkRunner() | ||
r.run(benchmarks, params={"x": 1, "y": 1}) |
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,16 @@ | ||
import nnbench | ||
|
||
|
||
@nnbench.benchmark | ||
def double(x: int) -> int: | ||
return x * 2 | ||
|
||
|
||
@nnbench.benchmark | ||
def triple(y: int) -> int: | ||
return y * 3 | ||
|
||
|
||
@nnbench.benchmark | ||
def prod(x: int, y: int) -> int: | ||
return x * y |
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,11 @@ | ||
import nnbench | ||
|
||
|
||
@nnbench.benchmark | ||
def double(x: int) -> int: | ||
return x * 2 | ||
|
||
|
||
@nnbench.benchmark | ||
def triple_str(x: str) -> str: | ||
return x * 3 |