Skip to content

Commit

Permalink
Fix HypothesisDeprecationWarning (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
scasagrande committed Mar 31, 2022
1 parent 3e12bda commit e93b739
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
5 changes: 3 additions & 2 deletions tests/test_comm/test_usb_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

# IMPORTS ####################################################################

from hypothesis import given, strategies as st
import math

import pytest

import usb.core
Expand Down Expand Up @@ -109,7 +110,7 @@ def test_terminator_wrong_type(inst):
)


@given(val=st.integers(min_value=1))
@pytest.mark.parametrize("val", [1, 1000, math.inf])
def test_timeout_get(val, inst):
"""Get a timeout from device (ms) and turn into s."""
# mock timeout value of device
Expand Down
4 changes: 2 additions & 2 deletions tests/test_keithley/test_keithley195.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
# PYTEST FIXTURES FOR INITIALIZATION #


@pytest.fixture
@pytest.fixture(scope="session")
def init():
"""Returns the initialization command that is sent to instrument."""
return "YX\nG1DX"


@pytest.fixture
@pytest.fixture(scope="session")
def statusword():
"""Return a standard statusword for the status of the instrument."""
trigger = b"1" # talk_one_shot
Expand Down
6 changes: 3 additions & 3 deletions tests/test_keithley/test_keithley580.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
# PYTEST FIXTURES FOR INITIALIZATION #


@pytest.fixture
@pytest.fixture(scope="session")
def init():
"""Returns the initialization command that is sent to instrument."""
return "Y:X:"


@pytest.fixture
@pytest.fixture(scope="session")
def create_statusword():
"""Create a function that can create a status word.
Expand Down Expand Up @@ -83,7 +83,7 @@ def make_statusword(
return make_statusword


@pytest.fixture
@pytest.fixture(scope="session")
def create_measurement():
"""Create a function that can create a measurement.
Expand Down
45 changes: 23 additions & 22 deletions tests/test_newport/test_newportesp301.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# IMPORTS #####################################################################

import time
from unittest import mock

from hypothesis import given, strategies as st
import pytest
Expand Down Expand Up @@ -175,22 +176,22 @@ def test_reset(mocker):


@given(prg_id=st.integers(min_value=1, max_value=100))
def test_define_program(mocker, prg_id):
def test_define_program(prg_id):
"""Define an empty program.
Mock out the `_newport_cmd` routine. Already tested and not
required.
"""
with expected_protocol(ik.newport.NewportESP301, [], [], sep="\r") as inst:
mock_cmd = mocker.patch.object(inst, "_newport_cmd")
with inst.define_program(prg_id):
pass
calls = (
mocker.call("XX", target=prg_id),
mocker.call("EP", target=prg_id),
mocker.call("QP"),
)
mock_cmd.has_calls(calls)
with mock.patch.object(inst, "_newport_cmd") as mock_cmd:
with inst.define_program(prg_id):
pass
calls = (
mock.call("XX", target=prg_id),
mock.call("EP", target=prg_id),
mock.call("QP"),
)
mock_cmd.has_calls(calls)


@given(prg_id=st.integers().filter(lambda x: x < 1 or x > 100))
Expand Down Expand Up @@ -244,16 +245,16 @@ def test_execute_bulk_command(mocker, errcheck):


@given(prg_id=st.integers(min_value=1, max_value=100))
def test_run_program(mocker, prg_id):
def test_run_program(prg_id):
"""Run a program.
Mock out the `_newport_cmd` routine. Already tested and not
required.
"""
with expected_protocol(ik.newport.NewportESP301, [], [], sep="\r") as inst:
mock_cmd = mocker.patch.object(inst, "_newport_cmd")
inst.run_program(prg_id)
mock_cmd.assert_called_with("EX", target=prg_id)
with mock.patch.object(inst, "_newport_cmd") as mock_cmd:
inst.run_program(prg_id)
mock_cmd.assert_called_with("EX", target=prg_id)


@given(prg_id=st.integers().filter(lambda x: x < 1 or x > 100))
Expand Down Expand Up @@ -1690,7 +1691,7 @@ def test_axis_setup_axis_torque(mocker):


@given(rmt_time=st.integers().filter(lambda x: x < 0 or x > 60000))
def test_axis_setup_axis_torque_time_out_of_range(mocker, rmt_time):
def test_axis_setup_axis_torque_time_out_of_range(rmt_time):
"""Raise ValueError when time is out of range.
Mock out `_newport_cmd` since tested elsewhere.
Expand Down Expand Up @@ -1731,9 +1732,9 @@ def test_axis_setup_axis_torque_time_out_of_range(mocker, rmt_time):
ik.newport.NewportESP301, [ax_init[0]], [ax_init[1]], sep="\r"
) as inst:
axis = inst.axis[0]
mocker.patch.object(axis, "_newport_cmd")
mocker.patch.object(axis, "read_setup", return_value=True)
with pytest.raises(ValueError) as err_info:
with mock.patch.object(axis, "_newport_cmd"), mock.patch.object(
axis, "read_setup", return_value=True
), pytest.raises(ValueError) as err_info:
axis.setup_axis(
motor_type=motor_type,
current=current,
Expand Down Expand Up @@ -1772,7 +1773,7 @@ def test_axis_setup_axis_torque_time_out_of_range(mocker, rmt_time):


@given(rmt_perc=st.integers().filter(lambda x: x < 0 or x > 100))
def test_axis_setup_axis_torque_percentage_out_of_range(mocker, rmt_perc):
def test_axis_setup_axis_torque_percentage_out_of_range(rmt_perc):
"""Raise ValueError when time is out of range.
Mock out `_newport_cmd` since tested elsewhere.
Expand Down Expand Up @@ -1813,9 +1814,9 @@ def test_axis_setup_axis_torque_percentage_out_of_range(mocker, rmt_perc):
ik.newport.NewportESP301, [ax_init[0]], [ax_init[1]], sep="\r"
) as inst:
axis = inst.axis[0]
mocker.patch.object(axis, "_newport_cmd")
mocker.patch.object(axis, "read_setup", return_value=True)
with pytest.raises(ValueError) as err_info:
with mock.patch.object(axis, "_newport_cmd"), mock.patch.object(
axis, "read_setup", return_value=True
), pytest.raises(ValueError) as err_info:
axis.setup_axis(
motor_type=motor_type,
current=current,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tektronix/test_tktds5xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from datetime import datetime
import struct
import time
from unittest import mock

from hypothesis import (
given,
Expand Down Expand Up @@ -680,6 +681,7 @@ def test_display_clock_value_error():


@given(data=st.binary(min_size=1, max_size=2147483647))
@mock.patch.object(time, "sleep", return_value=None)
def test_get_hardcopy(mocker, data):
"""Transfer data in binary from the instrument.
Expand All @@ -694,8 +696,6 @@ def test_get_hardcopy(mocker, data):
in header are filled with zeros.
Mocking out sleep to do nothing.
"""
# mock out time
mocker.patch.object(time, "sleep", return_value=None)

# make data
length_data = (len(data) - 8) * 8 # subtract header and color table
Expand Down
2 changes: 1 addition & 1 deletion tests/test_thorlabs/test_thorlabs_apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def init_ksg101():
return stdin, stdout


@pytest.fixture
@pytest.fixture(scope="session")
def init_kpz001():
"""Return the send, receive value to initialize a KPZ001 unit."""
stdin = ThorLabsPacket(
Expand Down

0 comments on commit e93b739

Please sign in to comment.