Skip to content

Commit 96a0aff

Browse files
authored
Merge branch 'master' into refactor_doNds
2 parents ce2be03 + 02684a9 commit 96a0aff

File tree

8 files changed

+246
-2
lines changed

8 files changed

+246
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ benchmarking/results/
9494

9595
# qcodes
9696
experiments.db
97+
98+
# test outputs
99+
qdev_wrappers/tests/dataset/output
100+
qdev_wrappers/tests/dataset/*.db

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ python:
2929

3030
install:
3131
- pip install -r test_requirements.txt --upgrade --upgrade-strategy only-if-needed
32+
- pip install git+https://github.com/QCoDeS/Qcodes.git
3233
- pip install -e .
3334

3435
script:
36+
- cd qdev_wrappers
37+
- pytest tests/dataset/
3538
- cd ..
3639
# check that line endings are correct avoiding mixed windows/unix style line endings
3740
- pylint --reports=n --disable=all --enable=mixed-line-endings,unexpected-line-ending-format --expected-line-ending-format=LF qdev-wrappers

qdev_wrappers/file_setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from IPython import get_ipython
21
import atexit
32
import os
43
from os.path import sep

qdev_wrappers/tests/__init__.py

Whitespace-only changes.

qdev_wrappers/tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import matplotlib
2+
matplotlib.use('agg')

qdev_wrappers/tests/dataset/__init__.py

Whitespace-only changes.
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
"""
2+
These are the basic black box tests for the doNd functions.
3+
"""
4+
5+
from qdev_wrappers.dataset.doNd import do0d, do1d, do2d
6+
from typing import Tuple, List, Optional
7+
from qcodes.instrument.parameter import Parameter
8+
from qcodes import config, new_experiment, load_by_id
9+
from qcodes.utils import validators
10+
11+
import pytest
12+
13+
config.user.mainfolder = "output" # set ouput folder for doNd's
14+
new_experiment("doNd-tests", sample_name="no sample")
15+
16+
17+
@pytest.fixture()
18+
def _param():
19+
20+
p = Parameter('simple_parameter',
21+
set_cmd=None,
22+
get_cmd=lambda: 1)
23+
return p
24+
25+
26+
@pytest.fixture()
27+
def _paramComplex():
28+
p = Parameter('simple_complex_parameter',
29+
set_cmd=None,
30+
get_cmd=lambda: 1 + 1j,
31+
vals=validators.ComplexNumbers())
32+
return p
33+
34+
35+
@pytest.fixture()
36+
def _param_set():
37+
p = Parameter('simple_setter_parameter',
38+
set_cmd=None,
39+
get_cmd=None)
40+
return p
41+
42+
43+
def _param_func(_p):
44+
"""
45+
A private utility function.
46+
"""
47+
_new_param = Parameter('modified_parameter',
48+
set_cmd= None,
49+
get_cmd= lambda: _p.get()*2)
50+
return _new_param
51+
52+
53+
@pytest.fixture()
54+
def _param_callable(_param):
55+
return _param_func(_param)
56+
57+
58+
def test_param_callable(_param_callable):
59+
_param_modified = _param_callable
60+
assert _param_modified.get() == 2
61+
62+
63+
@pytest.mark.parametrize('period, plot', [(None, True), (None, False),
64+
(1, True), (1, False)])
65+
def test_do0d_with_real_parameter(_param, period, plot):
66+
do0d(_param, write_period=period, do_plot=plot)
67+
68+
69+
@pytest.mark.parametrize('period, plot', [(None, True), (None, False),
70+
(1, True), (1, False)])
71+
def test_do0d_with_complex_parameter(_paramComplex, period, plot):
72+
do0d(_paramComplex, write_period=period, do_plot=plot)
73+
74+
75+
@pytest.mark.parametrize('period, plot', [(None, True), (None, False),
76+
(1, True), (1, False)])
77+
def test_do0d_with_a_callable(_param_callable, period, plot):
78+
do0d(_param_callable, write_period=period, do_plot=plot)
79+
80+
81+
@pytest.mark.parametrize('period, plot', [(None, True), (None, False),
82+
(1, True), (1, False)])
83+
def test_do0d_with_multiparameters(_param, _paramComplex, period, plot):
84+
do0d(_param, _paramComplex, write_period=period, do_plot=plot)
85+
86+
87+
@pytest.mark.parametrize('period, plot', [(None, True), (None, False),
88+
(1, True), (1, False)])
89+
def test_do0d_with_parameter_and_a_callable(_paramComplex, _param_callable,
90+
period, plot):
91+
do0d(_param_callable, _paramComplex, write_period=period, do_plot=plot)
92+
93+
94+
def test_do0d_output_type_real_parameter(_param):
95+
data = do0d(_param)
96+
assert type(data[0]) == int
97+
98+
99+
def test_do0d_output_type_complex_parameter(_paramComplex):
100+
dataComplex = do0d(_paramComplex)
101+
assert type(dataComplex[0]) == int
102+
103+
104+
def test_do0d_output_type_callable(_param_callable):
105+
dataFunc = do0d(_param_callable)
106+
assert type(dataFunc[0]) == int
107+
108+
109+
def test_do0d_output_data(_param):
110+
exp = do0d(_param)
111+
data = load_by_id(exp[0])
112+
assert data.parameters == _param.name
113+
assert data.get_values(_param.name)[0][0] == _param.get()
114+
115+
116+
@pytest.mark.parametrize('delay', [0, 0.1, 1])
117+
def test_do1d_with_real_parameter(_param_set, _param, delay):
118+
119+
start = 0
120+
stop = 1
121+
num_points = 1
122+
123+
do1d(_param_set, start, stop, num_points, delay, _param)
124+
125+
126+
@pytest.mark.parametrize('delay', [0, 0.1, 1])
127+
def test_do1d_with_complex_parameter(_param_set, _paramComplex, delay):
128+
129+
start = 0
130+
stop = 1
131+
num_points = 1
132+
133+
do1d(_param_set, start, stop, num_points, delay, _paramComplex)
134+
135+
136+
@pytest.mark.parametrize('delay', [0, 0.1, 1])
137+
def test_do1d_with_multiparameter(_param_set, _param, _paramComplex, delay):
138+
139+
start = 0
140+
stop = 1
141+
num_points = 1
142+
143+
do1d(_param_set, start, stop, num_points, delay, _param, _paramComplex)
144+
145+
146+
@pytest.mark.parametrize('delay', [0, 0.1, 1])
147+
def test_do1d_output_type_real_parameter(_param_set, _param, delay):
148+
149+
start = 0
150+
stop = 1
151+
num_points = 1
152+
153+
data = do1d(_param_set, start, stop, num_points, delay, _param)
154+
assert type(data[0]) == int
155+
156+
157+
def test_do1d_output_data(_param, _param_set):
158+
159+
start = 0
160+
stop = 1
161+
num_points = 5
162+
delay = 0
163+
164+
exp = do1d(_param_set, start, stop, num_points, delay, _param)
165+
data = load_by_id(exp[0])
166+
167+
assert data.parameters == f'{_param_set.name},{_param.name}'
168+
assert data.get_values(_param.name) == [[1]] * 5
169+
assert data.get_values(_param_set.name) == [[0], [0.25], [0.5], [0.75], [1]]
170+
171+
172+
@pytest.mark.parametrize('sweep, columns', [(False, False), (False, True),
173+
(True, False), (True, True)])
174+
def test_do2d(_param, _paramComplex, _param_set, sweep, columns):
175+
176+
start_p1 = 0
177+
stop_p1 = 1
178+
num_points_p1 = 1
179+
delay_p1 = 0
180+
181+
start_p2 = 0.1
182+
stop_p2 = 1.1
183+
num_points_p2 = 2
184+
delay_p2 = 0.01
185+
186+
do2d(_param_set, start_p1, stop_p1, num_points_p1, delay_p1,
187+
_param_set, start_p2, stop_p2, num_points_p2, delay_p2,
188+
_param, _paramComplex, set_before_sweep=sweep, flush_columns=columns)
189+
190+
191+
def test_do2d_output_type(_param, _paramComplex, _param_set):
192+
193+
start_p1 = 0
194+
stop_p1 = 0.5
195+
num_points_p1 = 1
196+
delay_p1 = 0
197+
198+
start_p2 = 0.1
199+
stop_p2 = 0.75
200+
num_points_p2 = 2
201+
delay_p2 = 0.025
202+
203+
data = do2d(_param_set, start_p1, stop_p1, num_points_p1, delay_p1,
204+
_param_set, start_p2, stop_p2, num_points_p2, delay_p2,
205+
_param, _paramComplex)
206+
207+
assert type(data[0]) == int
208+
209+
210+
def test_do2d_output_data(_param, _paramComplex, _param_set):
211+
212+
start_p1 = 0
213+
stop_p1 = 0.5
214+
num_points_p1 = 5
215+
delay_p1 = 0
216+
217+
start_p2 = 0.5
218+
stop_p2 = 1
219+
num_points_p2 = 5
220+
delay_p2 = 0.0
221+
222+
exp = do2d(_param_set, start_p1, stop_p1, num_points_p1, delay_p1,
223+
_param_set, start_p2, stop_p2, num_points_p2, delay_p2,
224+
_param, _paramComplex)
225+
226+
data = load_by_id(exp[0])
227+
228+
assert data.parameters == f'{_param_set.name},{_param.name},{_paramComplex.name}'
229+
assert data.get_values(_param.name) == [[1]] * 25
230+
assert data.get_values(_paramComplex.name) == [[(1+1j)]] * 25
231+
assert data.get_values(_param_set.name) == [[0.5], [0.5], [0.625], [0.625],
232+
[0.75], [0.75], [0.875], [0.875],
233+
[1], [1]] * 5

test_requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ lxml
88
codecov
99
asv
1010
gitpython
11-
pylint
11+
pylint
12+
attrs>=19.2.0 # needed for hypothesis >=4.38.1 but not correctly honored by pip 19.2.3
13+
PyQt5
14+
scipy

0 commit comments

Comments
 (0)