This repository was archived by the owner on Dec 19, 2023. It is now read-only.
WIP: Include MockDWaveSampler In Unit Tests#51
Open
m3ller wants to merge 17 commits into
Open
Conversation
added 17 commits
April 23, 2019 16:19
I want to test mock and the API token issue by just isolating one demo
Double check that the code works with DWaveSampler before I replace it again with a mock sampler
Previous commit did not utilize mock
macOS CI tests have python 2.7 pre-installed. When 'python -m virtualenv' gets used in the macOS tests, python 2.7 ends up being used in the virtualenv rather than python 3 (which is also installed). Will not change the call to 'python3 -m virtualenv' because we still have python 2.7 tests that also run this template
Using 'python -m virtualenv' again because it turns out that Python 3.7 comes pre-installed in Xcode and virtualenv gets shipped with Python 3.7. Default interpreter on this virtualenv is Python 3.7. Hence, I'm adding 'python -m' back into the code and then using 'pyenv' to prevent 'python -m' from defaulting to python 2.7
The Linux tests don't need pyenv, hence I don't want to install pyenv in those tests just so that macOS tests can use the template to call pyenv. Temporarily duplicating the code just to make sure that pyenv solves the problem for macOS tests; will clean up later
Want to clear cache so that we can install a different interpreter for virtualenv
This if-statement may not be portable as double square brackets may only work with Bash, but not POSIX
$PYTHON only exists for the macOS tests, hence we will just grab the python version via bash
e5274ed to
1a6a71d
Compare
randomir
reviewed
May 3, 2019
| # Python 2.7 case | ||
| # Note: using 2>&1 because python 2.7 sends version info to stderr | ||
| python_version="$(python --version 2>&1)" | ||
| if [[ "$python_version" =~ ^Python\ 2\.7\.[0-9]+$ ]]; then |
Member
There was a problem hiding this comment.
Bash pro tip: you can have regex in a variable to avoid escaping:
regex='^Python 2.7.[0-9]+$'
[[ $python_version =~ $regex ]] && pip install mock
(Also, don't need to quote vars inside [[ ]]. And here a simpler expression would be enough: [[ $pyver =~ "Python 2.7" ]].)
Member
There was a problem hiding this comment.
But, looking at a bigger picture, you would want to have this requirement (for Python 2.7) in the requirements file, to simplify the build script, e.g:
mock; python_version=="2.7"
Check an example.
| expected_solution = {'0,1w': 1, '1,1n': 1, '1,1w': 1, '2,0n': 1, '2,1w': 1, '2,2w': 1} | ||
| fill_with_zeros(expected_solution, n_rows, n_cols, [start, end]) | ||
| self.compare(response_sample, expected_solution) | ||
| with mock.patch('dwave.system.samplers.DWaveSampler', MockDWaveSampler): |
Member
There was a problem hiding this comment.
You could simplify mocking by patching the whole testcase, or at least the complete test. E.g.:
@patch(...)
def test(...):
...
or:
@patch(...)
class Test(TestCase):
...
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.