Skip to content

Commit

Permalink
Update pre-commit hooks (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
scasagrande committed Mar 29, 2022
1 parent 6b5dc23 commit 6fb8ea7
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ repos:
- id: check-yaml
- id: debug-statements
- repo: https://github.com/psf/black
rev: 21.12b0
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v2.31.1
hooks:
- id: pyupgrade
args: [ --py36-plus ]
2 changes: 1 addition & 1 deletion doc/examples/ex_hp3456.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
print(dmm.measure(dmm.Mode.resistance_2wire))
dmm.nplc = 1
for i in range(-1, 4):
value = (10 ** i) * u.volt
value = (10**i) * u.volt
dmm.input_range = value
print(dmm.measure(dmm.Mode.dcv))

Expand Down
4 changes: 2 additions & 2 deletions instruments/newport/newport_pmc8742.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ def acceleration(self):
>>> ax = inst.axis[0]
>>> ax.acceleration = u.Quantity(500, 1/u.s**-2)
"""
return assume_units(int(self.query("AC?")), u.s ** -2)
return assume_units(int(self.query("AC?")), u.s**-2)

@acceleration.setter
def acceleration(self, value):
value = int(assume_units(value, u.s ** -2).to(u.s ** -2).magnitude)
value = int(assume_units(value, u.s**-2).to(u.s**-2).magnitude)
if not 1 <= value <= 200000:
raise ValueError(
f"Acceleration must be between 1 and "
Expand Down
34 changes: 17 additions & 17 deletions instruments/newport/newportesp301.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ def acceleration(self):

return assume_units(
float(self._newport_cmd("AC?", target=self.axis_id)),
self._units / (u.s ** 2),
self._units / (u.s**2),
)

@acceleration.setter
def acceleration(self, newval):
if newval is None:
return
newval = float(
assume_units(newval, self._units / (u.s ** 2))
.to(self._units / (u.s ** 2))
assume_units(newval, self._units / (u.s**2))
.to(self._units / (u.s**2))
.magnitude
)
self._newport_cmd("AC", target=self.axis_id, params=[newval])
Expand All @@ -177,16 +177,16 @@ def deceleration(self):
"""
return assume_units(
float(self._newport_cmd("AG?", target=self.axis_id)),
self._units / (u.s ** 2),
self._units / (u.s**2),
)

@deceleration.setter
def deceleration(self, newval):
if newval is None:
return
newval = float(
assume_units(newval, self._units / (u.s ** 2))
.to(self._units / (u.s ** 2))
assume_units(newval, self._units / (u.s**2))
.to(self._units / (u.s**2))
.magnitude
)
self._newport_cmd("AG", target=self.axis_id, params=[newval])
Expand All @@ -202,14 +202,14 @@ def estop_deceleration(self):
"""
return assume_units(
float(self._newport_cmd("AE?", target=self.axis_id)),
self._units / (u.s ** 2),
self._units / (u.s**2),
)

@estop_deceleration.setter
def estop_deceleration(self, decel):
decel = float(
assume_units(decel, self._units / (u.s ** 2))
.to(self._units / (u.s ** 2))
assume_units(decel, self._units / (u.s**2))
.to(self._units / (u.s**2))
.magnitude
)
self._newport_cmd("AE", target=self.axis_id, params=[decel])
Expand All @@ -226,14 +226,14 @@ def jerk(self):

return assume_units(
float(self._newport_cmd("JK?", target=self.axis_id)),
self._units / (u.s ** 3),
self._units / (u.s**3),
)

@jerk.setter
def jerk(self, jerk):
jerk = float(
assume_units(jerk, self._units / (u.s ** 3))
.to(self._units / (u.s ** 3))
assume_units(jerk, self._units / (u.s**3))
.to(self._units / (u.s**3))
.magnitude
)
self._newport_cmd("JK", target=self.axis_id, params=[jerk])
Expand Down Expand Up @@ -381,16 +381,16 @@ def max_acceleration(self):
"""
return assume_units(
float(self._newport_cmd("AU?", target=self.axis_id)),
self._units / (u.s ** 2),
self._units / (u.s**2),
)

@max_acceleration.setter
def max_acceleration(self, newval):
if newval is None:
return
newval = float(
assume_units(newval, self._units / (u.s ** 2))
.to(self._units / (u.s ** 2))
assume_units(newval, self._units / (u.s**2))
.to(self._units / (u.s**2))
.magnitude
)
self._newport_cmd("AU", target=self.axis_id, params=[newval])
Expand All @@ -410,8 +410,8 @@ def max_deceleration(self):
@max_deceleration.setter
def max_deceleration(self, decel):
decel = float(
assume_units(decel, self._units / (u.s ** 2))
.to(self._units / (u.s ** 2))
assume_units(decel, self._units / (u.s**2))
.to(self._units / (u.s**2))
.magnitude
)
self.max_acceleration = decel
Expand Down
2 changes: 1 addition & 1 deletion instruments/rigol/rigolds1000.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def acquire_averages(self):

@acquire_averages.setter
def acquire_averages(self, newval):
if newval not in [2 ** i for i in range(1, 9)]:
if newval not in [2**i for i in range(1, 9)]:
raise ValueError(
"Number of averages {} not supported by instrument; "
"must be a power of 2 from 2 to 256.".format(newval)
Expand Down
2 changes: 1 addition & 1 deletion instruments/srs/srs830.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# CONSTANTS ###################################################################

VALID_SAMPLE_RATES = [2.0 ** n for n in range(-4, 10)]
VALID_SAMPLE_RATES = [2.0**n for n in range(-4, 10)]
VALID_SAMPLE_RATES += ["trigger"]

# CLASSES #####################################################################
Expand Down
2 changes: 1 addition & 1 deletion instruments/tektronix/tekawg2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def upload_waveform(self, yzero, ymult, xincr, waveform):
self.sendcmd(f"WFMP:YMULT {ymult}")
self.sendcmd(f"WFMP:XINCR {xincr}")

waveform *= 2 ** 12 - 1
waveform *= 2**12 - 1
waveform = waveform.astype("<u2").tobytes()
wfm_header_2 = str(len(waveform))
wfm_header_1 = len(wfm_header_2)
Expand Down
8 changes: 4 additions & 4 deletions instruments/tektronix/tekdpo70000.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,14 @@ def _scale_raw_data(self, data):
# TODO: incorperate the unit_string somehow
if numpy:
return self.scale * (
(TekDPO70000.VERT_DIVS / 2) * data.astype(float) / (2 ** 15)
(TekDPO70000.VERT_DIVS / 2) * data.astype(float) / (2**15)
- self.position
)

scale = self.scale
position = self.position
rval = tuple(
scale * ((TekDPO70000.VERT_DIVS / 2) * d / (2 ** 15) - position)
scale * ((TekDPO70000.VERT_DIVS / 2) * d / (2**15) - position)
for d in map(float, data)
)
return rval
Expand Down Expand Up @@ -624,14 +624,14 @@ def _scale_raw_data(self, data):
return (
scale
* (
(TekDPO70000.VERT_DIVS / 2) * data.astype(float) / (2 ** 15)
(TekDPO70000.VERT_DIVS / 2) * data.astype(float) / (2**15)
- position
)
+ offset
)

return tuple(
scale * ((TekDPO70000.VERT_DIVS / 2) * d / (2 ** 15) - position)
scale * ((TekDPO70000.VERT_DIVS / 2) * d / (2**15) - position)
+ offset
for d in map(float, data)
)
Expand Down
2 changes: 1 addition & 1 deletion instruments/tests/test_hp/test_hp3456a.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_hp3456a_input_range():
with expected_protocol(
ik.hp.HP3456a, ["HO0T4SO1", "R2W", "R3W"], [""], sep="\r"
) as dmm:
dmm.input_range = 10 ** -1 * u.volt
dmm.input_range = 10**-1 * u.volt
dmm.input_range = 1e3 * u.ohm
with pytest.raises(NotImplementedError):
_ = dmm.input_range
Expand Down
4 changes: 2 additions & 2 deletions instruments/tests/test_newport/test_newport_pmc8742.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def test_axis_return_index_error(ax):
@given(val=st.integers(min_value=1, max_value=200000))
def test_axis_acceleration(val):
"""Set / get axis acceleration unitful and without units."""
val_unit = u.Quantity(val, u.s ** -2)
val_unit_other = val_unit.to(u.min ** -2)
val_unit = u.Quantity(val, u.s**-2)
val_unit_other = val_unit.to(u.min**-2)
with expected_protocol(
ik.newport.PicoMotorController8742,
[f"1AC{val}", f"1AC{val}", "1AC?"],
Expand Down
22 changes: 11 additions & 11 deletions instruments/tests/test_newport/test_newportesp301.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def test_axis_acceleration(mocker):
mock_cmd = mocker.patch.object(axis, "_newport_cmd", return_value=value)
axis.acceleration = value
mock_cmd.assert_called_with("AC", target=1, params=[float(value)])
assert axis.acceleration == u.Quantity(value, axis._units / u.s ** 2)
assert axis.acceleration == u.Quantity(value, axis._units / u.s**2)
mock_cmd.assert_called_with("AC?", target=1)


Expand All @@ -413,7 +413,7 @@ def test_axis_deceleration(mocker):
mock_cmd = mocker.patch.object(axis, "_newport_cmd", return_value=value)
axis.deceleration = value
mock_cmd.assert_called_with("AG", target=1, params=[float(value)])
assert axis.deceleration == u.Quantity(value, axis._units / u.s ** 2)
assert axis.deceleration == u.Quantity(value, axis._units / u.s**2)
mock_cmd.assert_called_with("AG?", target=1)


Expand All @@ -439,7 +439,7 @@ def test_axis_estop_deceleration(mocker):
mock_cmd = mocker.patch.object(axis, "_newport_cmd", return_value=value)
axis.estop_deceleration = value
mock_cmd.assert_called_with("AE", target=1, params=[float(value)])
assert axis.estop_deceleration == u.Quantity(value, axis._units / u.s ** 2)
assert axis.estop_deceleration == u.Quantity(value, axis._units / u.s**2)
mock_cmd.assert_called_with("AE?", target=1)


Expand All @@ -456,7 +456,7 @@ def test_axis_jerk(mocker):
mock_cmd = mocker.patch.object(axis, "_newport_cmd", return_value=value)
axis.jerk = value
mock_cmd.assert_called_with("JK", target=1, params=[float(value)])
assert axis.jerk == u.Quantity(value, axis._units / u.s ** 3)
assert axis.jerk == u.Quantity(value, axis._units / u.s**3)
mock_cmd.assert_called_with("JK?", target=1)


Expand Down Expand Up @@ -620,7 +620,7 @@ def test_axis_max_acceleration(mocker):
mock_cmd = mocker.patch.object(axis, "_newport_cmd", return_value=value)
axis.max_acceleration = value
mock_cmd.assert_called_with("AU", target=1, params=[float(value)])
assert axis.max_acceleration == u.Quantity(value, axis._units / u.s ** 2)
assert axis.max_acceleration == u.Quantity(value, axis._units / u.s**2)
mock_cmd.assert_called_with("AU?", target=1)


Expand All @@ -646,7 +646,7 @@ def test_axis_max_deceleration(mocker):
mock_cmd = mocker.patch.object(axis, "_newport_cmd", return_value=value)
axis.max_deceleration = value
mock_cmd.assert_called_with("AU", target=1, params=[float(value)])
assert axis.max_deceleration == u.Quantity(value, axis._units / u.s ** 2)
assert axis.max_deceleration == u.Quantity(value, axis._units / u.s**2)
mock_cmd.assert_called_with("AU?", target=1)


Expand Down Expand Up @@ -1867,15 +1867,15 @@ def test_axis_read_setup(mocker):
"current": u.Quantity(4.0, u.A),
"max_velocity": u.Quantity(5.0, u.mm / u.s),
"encoder_resolution": u.Quantity(6.0, u.mm),
"acceleration": u.Quantity(7.0, u.mm / u.s ** 2),
"deceleration": u.Quantity(8.0, u.mm / u.s ** 2),
"acceleration": u.Quantity(7.0, u.mm / u.s**2),
"deceleration": u.Quantity(8.0, u.mm / u.s**2),
"velocity": u.Quantity(9.0, u.mm / u.s),
"max_acceleration": u.Quantity(10.0, u.mm / u.s ** 2.0),
"max_acceleration": u.Quantity(10.0, u.mm / u.s**2.0),
"homing_velocity": u.Quantity(11.0, u.mm / u.s),
"jog_high_velocity": u.Quantity(12.0, u.mm / u.s),
"jog_low_velocity": u.Quantity(13.0, u.mm / u.s),
"estop_deceleration": u.Quantity(14.0, u.mm / u.s ** 2.0),
"jerk": u.Quantity(14.0, u.mm / u.s ** 3.0),
"estop_deceleration": u.Quantity(14.0, u.mm / u.s**2.0),
"jerk": u.Quantity(14.0, u.mm / u.s**3.0),
"proportional_gain": 15.0, # last 1 removed at return
"derivative_gain": 16.0,
"integral_gain": 17.0,
Expand Down
2 changes: 1 addition & 1 deletion instruments/tests/test_tektronix/test_tekawg2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_upload_waveform(yzero, ymult, xincr, waveform):
"""Upload a waveform from the PC to the instrument."""
# prep waveform
waveform = numpy.array(waveform)
waveform_send = waveform * (2 ** 12 - 1)
waveform_send = waveform * (2**12 - 1)
waveform_send = waveform_send.astype("<u2").tobytes()
wfm_header_2 = str(len(waveform_send))
wfm_header_1 = len(wfm_header_2)
Expand Down
18 changes: 9 additions & 9 deletions instruments/tests/test_tektronix/test_tekdpo70000.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_data_source_read_waveform(channel, values):
offset = 0.0
scaled_values = [
scale
* ((ik.tektronix.TekDPO70000.VERT_DIVS / 2) * float(v) / (2 ** 15) - position)
* ((ik.tektronix.TekDPO70000.VERT_DIVS / 2) * float(v) / (2**15) - position)
+ offset
for v in values
]
Expand All @@ -105,7 +105,7 @@ def test_data_source_read_waveform(channel, values):
* (
(ik.tektronix.TekDPO70000.VERT_DIVS / 2)
* values.astype(float)
/ (2 ** 15)
/ (2**15)
- position
)
+ offset
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_data_source_read_waveform_with_old_data_source():
offset = 0.0
scaled_values = [
scale
* ((ik.tektronix.TekDPO70000.VERT_DIVS / 2) * float(v) / (2 ** 15) - position)
* ((ik.tektronix.TekDPO70000.VERT_DIVS / 2) * float(v) / (2**15) - position)
+ offset
for v in values
]
Expand All @@ -177,7 +177,7 @@ def test_data_source_read_waveform_with_old_data_source():
* (
(ik.tektronix.TekDPO70000.VERT_DIVS / 2)
* values.astype(float)
/ (2 ** 15)
/ (2**15)
- position
)
+ offset
Expand Down Expand Up @@ -691,13 +691,13 @@ def test_math_scale_raw_data(values):
position = -2.3
expected_value = tuple(
scale
* ((ik.tektronix.TekDPO70000.VERT_DIVS / 2) * float(v) / (2 ** 15) - position)
* ((ik.tektronix.TekDPO70000.VERT_DIVS / 2) * float(v) / (2**15) - position)
for v in values
)
if numpy:
values = numpy.array(values)
expected_value = scale * (
(ik.tektronix.TekDPO70000.VERT_DIVS / 2) * values.astype(float) / (2 ** 15)
(ik.tektronix.TekDPO70000.VERT_DIVS / 2) * values.astype(float) / (2**15)
- position
)

Expand Down Expand Up @@ -951,7 +951,7 @@ def test_channel_scale_raw_data(values):
offset = u.Quantity(0.0, u.V)
expected_value = tuple(
scale
* ((ik.tektronix.TekDPO70000.VERT_DIVS / 2) * float(v) / (2 ** 15) - position)
* ((ik.tektronix.TekDPO70000.VERT_DIVS / 2) * float(v) / (2**15) - position)
for v in values
)
if numpy:
Expand All @@ -961,7 +961,7 @@ def test_channel_scale_raw_data(values):
* (
(ik.tektronix.TekDPO70000.VERT_DIVS / 2)
* values.astype(float)
/ (2 ** 15)
/ (2**15)
- position
)
+ offset
Expand Down Expand Up @@ -1045,7 +1045,7 @@ def test_acquire_mode_actual(value):
assert inst.acquire_mode_actual == value


@given(value=st.integers(min_value=0, max_value=2 ** 30 - 1))
@given(value=st.integers(min_value=0, max_value=2**30 - 1))
def test_acquire_num_acquisitions(value):
"""Get number of waveform acquisitions since start (query only)."""
with expected_protocol(
Expand Down

0 comments on commit 6fb8ea7

Please sign in to comment.