-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from arcondello/testing
Remove test mixins and replace with custom asserts
- Loading branch information
Showing
12 changed files
with
86 additions
and
307 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from dimod.testing.asserts import * |
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,65 @@ | ||
"""todo""" | ||
from collections import Mapping | ||
|
||
import dimod | ||
|
||
|
||
# def assert_response_correct_energy(response, bqm): | ||
# """todo""" | ||
# for sample in response: | ||
# assert isinstance(sample, Mapping), "'for sample in response', each sample should be a Mapping" | ||
|
||
# for v, value in sample.items(): | ||
# assert v in bqm.linear, 'sample contains a variable not in the given bqm' | ||
# assert value in bqm.vartype.value, 'sample contains a value not of the correct type' | ||
|
||
# for v in bqm.linear: | ||
# assert v in sample, "bqm contains a variable not in sample" | ||
|
||
|
||
def assert_sampler_api(sampler): | ||
"""Assert that an instantiated sampler has the correct properties and methods exposed. | ||
""" | ||
|
||
# abstract base class | ||
|
||
assert isinstance(sampler, dimod.Sampler), "must be a dimod Sampler." | ||
|
||
# sample methods | ||
|
||
assert hasattr(sampler, 'sample'), "instantiated sampler must have a 'sample' method" | ||
assert callable(sampler.sample), "instantiated sampler must have a 'sample' method" | ||
|
||
assert hasattr(sampler, 'sample_ising'), "instantiated sampler must have a 'sample_ising' method" | ||
assert callable(sampler.sample_ising), "instantiated sampler must have a 'sample_ising' method" | ||
|
||
assert hasattr(sampler, 'sample_qubo'), "instantiated sampler must have a 'sample_qubo' method" | ||
assert callable(sampler.sample_qubo), "instantiated sampler must have a 'sample_qubo' method" | ||
|
||
# properties | ||
|
||
msg = "instantiated sampler must have a 'parameters' property, set to a Mapping" | ||
assert hasattr(sampler, 'parameters'), msg | ||
assert not callable(sampler.parameters), msg | ||
assert isinstance(sampler.parameters, Mapping), msg | ||
|
||
msg = "instantiated sampler must have a 'properties' property, set to a Mapping" | ||
assert hasattr(sampler, 'properties'), msg | ||
assert not callable(sampler.properties), msg | ||
assert isinstance(sampler.properties, Mapping), msg | ||
|
||
|
||
def assert_composite_api(composed_sampler): | ||
"""todo""" | ||
|
||
assert isinstance(composed_sampler, dimod.Composite) | ||
|
||
# todo: check properties (including correctness of mixins) | ||
|
||
|
||
def assert_structured_api(sampler): | ||
"""todo""" | ||
|
||
assert isinstance(sampler, dimod.Structured), "must be a Structured sampler" | ||
|
||
# todo: check properties (including correctness of mixins) |
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
Oops, something went wrong.