Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Miscellaneous refactors to reduce technical debt in variable declarations and comparison operations #236

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions docs/_static/js/copybutton.js
nfelt14 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const clearSelection = () => {
// Changes tooltip text for a moment, then changes it back
// We want the timeout of our `success` class to be a bit shorter than the
// tooltip and icon change, so that we can hide the icon before changing back.
var timeoutIcon = 2000;
var timeoutSuccessClass = 1500;
const timeoutIcon = 2000;
const timeoutSuccessClass = 1500;

const temporarilyChangeTooltip = (el, oldText, newText) => {
el.setAttribute('data-tooltip', newText)
Expand Down Expand Up @@ -159,12 +159,12 @@ function filterText(target, exclude) {
// Callback when a copy button is clicked. Will be passed the node that was clicked
// should then grab the text and replace pieces of text that shouldn't be used in output
function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = "", hereDocDelim = "") {
var regexp;
var match;
let regexp;
let match;

// Do we check for line continuation characters and "HERE-documents"?
var useLineCont = !!lineContinuationChar
var useHereDoc = !!hereDocDelim
let useLineCont = !!lineContinuationChar
let useHereDoc = !!hereDocDelim

// create regexp to capture prompt and remaining line
if (isRegexp) {
Expand All @@ -174,9 +174,9 @@ function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onl
}

const outputLines = [];
var promptFound = false;
var gotLineCont = false;
var gotHereDoc = false;
let promptFound = false;
let gotLineCont = false;
let gotHereDoc = false;
const lineGotPrompt = [];
for (const line of textContent.split('\n')) {
match = line.match(regexp)
Expand Down Expand Up @@ -211,8 +211,8 @@ function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onl
}


var copyTargetText = (trigger) => {
var target = document.querySelector(trigger.attributes['data-clipboard-target'].value);
const copyTargetText = (trigger) => {
let target = document.querySelector(trigger.attributes['data-clipboard-target'].value);

// get filtered text
let exclude = '.linenos'; // Can use ".linenos, .gp, .go" to exclude prompt characters and output in code blocks
Expand Down
4 changes: 2 additions & 2 deletions docs/_static/js/insert-hr.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
document.addEventListener('DOMContentLoaded', function () {
// Selects all h2 elements within divs that have both the "doc" and "doc-children" classes
var headings = document.querySelectorAll('.doc.doc-children h2');
let headings = document.querySelectorAll('.doc.doc-children h2');

headings.forEach(function(heading) {
var hr = document.createElement('hr'); // Creates a new <hr> element
let hr = document.createElement('hr'); // Creates a new <hr> element
// Inserts the <hr> element before the current h2 element
heading.parentNode.insertBefore(hr, heading);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

# Measure Settings
smu2450.commands.smu.measure.func = smu2450.commands.smu.FUNC_DC_VOLTAGE
smu2450.commands.smu.measure.autorange = smu2450.commands.smu.measure.autorange
smu2450.commands.smu.measure.nplc = NPLC
smu2450.commands.smu.measure.sense = smu2450.commands.smu.SENSE_4WIRE

Expand Down
5 changes: 2 additions & 3 deletions examples/source_measure_units/2600/smu_2600_bjt_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def bjt_slow(inst: SMU2602B) -> None:

vceo_status = vceo(inst, index)
vce_sat_status, vbe_sat_status = vbe_vce_sat(inst, index)
hfe_status = hfe1(inst, index)
hfe_status = hfe1(inst)

if not vceo_status:
bins[1] += 1
Expand Down Expand Up @@ -213,12 +213,11 @@ def vbe_vce_sat(inst: SMU2602B, index: int) -> Tuple[bool, bool]:
return vce_sat_status, vbe_sat_status


def hfe1(inst: SMU2602B, index: int) -> bool:
def hfe1(inst: SMU2602B) -> bool:
"""This function will run the HFE1 test on the transistor.

Args:
inst (SMU2602B): The python driver instance for the instrument used in testing.
index (int): The number of the transistor under test.

Returns:
bool: Returns the status of the HFE1 test. Pass = True, Fail = False
Expand Down
2 changes: 1 addition & 1 deletion scripts/contributor_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def main() -> None:
args = parse_arguments()
if running_in_virtualenv():
raise IndexError
if not sys.version_info >= (3, 8):
if sys.version_info < (3, 8): # noqa: UP036
msg = (
"Unable to set up the environment. "
"Please use a Python version greater than or equal to 3.8."
Expand Down
4 changes: 2 additions & 2 deletions src/tm_devices/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def cleanup_all_devices(self) -> None:
self.__protect_access()
for device_name, device_object in self.__devices.items():
try:
device_object.cleanup(verbose=False or bool(self.__config.options.verbose_mode))
device_object.cleanup(verbose=bool(self.__config.options.verbose_mode))
except (visa.errors.Error, socket.error, RPCError, AttributeError): # noqa: PERF203
print(f"Device cleanup of {device_name} failed. Retrying...")
device_object.cleanup()
Expand Down Expand Up @@ -1256,7 +1256,7 @@ def __create_device(

# Clean up devices if the option is enabled.
if self.__setup_cleanup_enabled:
new_device.cleanup(verbose=False or bool(self.__config.options.verbose_mode))
new_device.cleanup(verbose=bool(self.__config.options.verbose_mode))

return new_device

Expand Down
5 changes: 2 additions & 3 deletions src/tm_devices/drivers/pi/pi_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,9 @@ def query_less_than(
if (
allow_equal
and (
(not abs(actual_value) <= (abs(value) + tolerance))
and (str(value) != str(actual_value))
(abs(actual_value) < (abs(value) + tolerance)) and (str(value) != str(actual_value))
)
) or (not allow_equal and not abs(actual_value) < (abs(value) + tolerance)):
) or (not allow_equal and abs(actual_value) >= (abs(value) + tolerance)):
max_value = value + tolerance
self.raise_failure(
f"query_less_than failed for query: {query}\n "
Expand Down
2 changes: 1 addition & 1 deletion src/tm_devices/helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def get_model_series(model: str) -> str:
# contribute to determining the correct series.
valid_model_endings = {"A", "B", "C", "D", "LP"}
model_end = ""
if re.search("[0-9]", simplified_model): # if the model contains numbers
if re.search(r"\d", simplified_model): # if the model contains numbers
model_end = re.split(r"\d+", simplified_model)[-1] # split on the occurrence of each number
if len(model_end) == 1 and model_end not in valid_model_endings:
simplified_model = simplified_model.rstrip(model_end)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_afgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_afg3kc(device_manager: DeviceManager) -> None:
"pyvisa.resources.messagebased.MessageBasedResource.query",
mock.MagicMock(side_effect=visa.errors.Error("custom error")),
), pytest.raises(visa.errors.Error):
assert afg3kc.query_expect_timeout("INVALID?", timeout_ms=1) == ""
afg3kc.query_expect_timeout("INVALID?", timeout_ms=1)
assert afg3kc.expect_esr(32, '1, Command error\n0,"No error"')[0]
with pytest.raises(AssertionError):
afg3kc.expect_esr(32, '1, Command error\n0,"No error"')
Expand Down
6 changes: 3 additions & 3 deletions tests/test_devices_legacy_tsp_ieee_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_dmm6500(device_manager: DeviceManager) -> None:
"pyvisa.resources.messagebased.MessageBasedResource.query",
mock.MagicMock(side_effect=visa.errors.Error("custom error")),
), pytest.raises(visa.errors.Error):
assert dmm.query_expect_timeout("INVALID?", timeout_ms=1) == ""
dmm.query_expect_timeout("INVALID?", timeout_ms=1)
assert dmm.expect_esr(32, "Command error,No Error")[0]
assert dmm.all_channel_names_list == ()

Expand All @@ -43,7 +43,7 @@ def test_dmm75xx(device_manager: DeviceManager) -> None:
"pyvisa.resources.messagebased.MessageBasedResource.query",
mock.MagicMock(side_effect=visa.errors.Error("custom error")),
), pytest.raises(visa.errors.Error):
assert dmm.query_expect_timeout("INVALID?", timeout_ms=1) == ""
dmm.query_expect_timeout("INVALID?", timeout_ms=1)
assert dmm.expect_esr(32, "Command error,No Error")[0]
assert dmm.all_channel_names_list == ()

Expand All @@ -64,6 +64,6 @@ def test_daq6510(device_manager: DeviceManager) -> None:
"pyvisa.resources.messagebased.MessageBasedResource.query",
mock.MagicMock(side_effect=visa.errors.Error("custom error")),
), pytest.raises(visa.errors.Error):
assert daq.query_expect_timeout("INVALID?", timeout_ms=1) == ""
daq.query_expect_timeout("INVALID?", timeout_ms=1)
assert daq.expect_esr(32, "Command error,No Error")[0]
assert daq.all_channel_names_list == ("1",)
4 changes: 2 additions & 2 deletions tests/test_smu.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_smu( # noqa: PLR0915
"pyvisa.resources.messagebased.MessageBasedResource.query",
mock.MagicMock(side_effect=visa.errors.Error("custom error")),
), pytest.raises(visa.errors.Error):
assert smu.query_expect_timeout("INVALID?", timeout_ms=1) == ""
smu.query_expect_timeout("INVALID?", timeout_ms=1)
assert smu.expect_esr(32, "Command error,No Error")[0]

with pytest.raises(AssertionError):
Expand Down Expand Up @@ -263,7 +263,7 @@ def test_smu2450(device_manager: DeviceManager, capsys: pytest.CaptureFixture[st
"pyvisa.resources.messagebased.MessageBasedResource.query",
mock.MagicMock(side_effect=visa.errors.Error("custom error")),
), pytest.raises(visa.errors.Error):
assert smu.query_expect_timeout("INVALID?", timeout_ms=1) == ""
smu.query_expect_timeout("INVALID?", timeout_ms=1)
assert smu.expect_esr(32, "Command error,No Error")[0]
assert smu.all_channel_names_list == ("OUTPUT1",)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_ss(device_manager: DeviceManager) -> None:
"pyvisa.resources.messagebased.MessageBasedResource.query",
mock.MagicMock(side_effect=visa.errors.Error("custom error")),
), pytest.raises(visa.errors.Error):
assert switch.query_expect_timeout("INVALID?", timeout_ms=1) == ""
switch.query_expect_timeout("INVALID?", timeout_ms=1)
assert switch.expect_esr(32, "Command error,No Error")[0]

expected_ch_names = tuple(str(x) for x in range(1, switch.total_channels + 1))
Expand Down
Loading