-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have
Device.write
accept a full byte sequence, not just a single by…
…te (#79) * Add test_common.py * Add test_serial.py * Add test for logging * Have devices.Device.write accept a full byte sequence, not just a single byte * Different way of skipping bad test. * Update changelog
- Loading branch information
1 parent
2aab58b
commit dccb9ba
Showing
7 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import List, Optional | ||
|
||
import pytest | ||
|
||
from pyvisa_sim import common | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data, mask, send_end, want", | ||
[ | ||
(b"1234", None, False, b"1234"), | ||
(b"41234", 3, False, b"40004"), | ||
# Can't figure this one out. Getting ValueError: bytes must in in range(0, 256) | ||
# If I knew more about the purpose of `iter_bytes` then maybe I could | ||
# reconcile it, but I don't have time to investigate right now. | ||
pytest.param( | ||
b"1234", | ||
3, | ||
True, | ||
b"1234", | ||
marks=pytest.mark.xfail( | ||
reason=( | ||
"ValueError bytes must be in range(0, 256). TODO: figure" | ||
" out correct 'want' value." | ||
) | ||
), | ||
), | ||
], | ||
) | ||
def test_iter_bytes( | ||
data: bytes, mask: Optional[int], send_end: bool, want: List[bytes] | ||
) -> None: | ||
got = b"".join(common.iter_bytes(data, mask=mask, send_end=send_end)) | ||
assert got == want | ||
|
||
|
||
def test_iter_bytes_with_send_end_requires_mask() -> None: | ||
with pytest.raises(ValueError): | ||
# Need to wrap in list otherwise the iterator is never called. | ||
list(common.iter_bytes(b"", mask=None, send_end=True)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
import pyvisa | ||
|
||
from pyvisa_sim.sessions import serial | ||
|
||
serial.SerialInstrumentSession | ||
|
||
|
||
def test_serial_write_with_termination_last_bit(resource_manager): | ||
instr = resource_manager.open_resource( | ||
"ASRL4::INSTR", | ||
read_termination="\n", | ||
write_termination="\r\n", | ||
) | ||
|
||
# Ensure that we test the `asrl_end` block of serial.SerialInstrumentSession.write | ||
instr.set_visa_attribute( | ||
pyvisa.constants.ResourceAttribute.asrl_end_out, | ||
pyvisa.constants.SerialTermination.last_bit, | ||
) | ||
|
||
# There's a bug (maybe?) in common.iter_bytes that we want to avoid for now. | ||
instr.set_visa_attribute( | ||
pyvisa.constants.ResourceAttribute.send_end_enabled, | ||
pyvisa.constants.VI_FALSE, | ||
) | ||
|
||
instr.write("*IDN?") | ||
assert instr.read() == "SCPI,MOCK,VERSION_1.0" |