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

BFs for visa_communicator and tests #308

Merged

Conversation

trappitsch
Copy link
Contributor

Figured I'll take care of issue #307 and incorporate a few tests for the visa communicator. Using pyvisa-sim to simulate a non-connected device.

  • read_raw() now uses read_raw() of pyvisa and not read() - as discussed in Keithley 195A #307
  • Not implemented functions now raise NotImplementedError
  • Removed testing if pyvisa is present

More details given with code comments. Would be great if @thestumbler could test the BF with the actual instrument present!

- read_raw() now uses read_raw() of pyvisa and not read()
- Not implemented functions now raise NotImplementedError
- Removed testing if pyvisa is present
@@ -29,9 +29,6 @@ class VisaCommunicator(io.IOBase, AbstractCommunicator):
def __init__(self, conn):
super(VisaCommunicator, self).__init__(self)

if pyvisa is None:
raise ImportError("PyVISA required for accessing VISA instruments.")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this can ever be triggered, wouldn't it throw an error during the import pyvisa above if pyvisa is not installed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it would. Also, pyvisa is named as a dependency of IK, so I'm not sure in what scenario your users would end up with pyvisa not available?

In any case, I think the normal pattern for "optional" packages is doing something like this above:

try:
    import pyvisa
except ImportError:
    pyvisa = None

, then this would work as you expect (I think).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, just noticed that the same check is also in instrument.py before opening the visa communicator alltogether. the import there is the same, i.e., import pyvisa. Probably makes not much sense there either I'd assume...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its an old code block from way back when it was an optional dep, because installation required a separate non-Python package to be installed.

@@ -118,7 +115,7 @@ def read_raw(self, size=-1):

elif size == -1:
# Read the whole contents, appending the buffer we've already read.
msg = self._buf + self._conn.read()
msg = self._buf + self._conn.read_raw()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BF as discussed in #307

@@ -136,10 +133,10 @@ def write_raw(self, msg):
self._conn.write_raw(msg)

def seek(self, offset): # pylint: disable=unused-argument,no-self-use
return NotImplemented
raise NotImplementedError
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make consistent with the rest of IK, same for second replacement below.

@coveralls
Copy link

coveralls commented Jul 4, 2021

Coverage Status

Coverage increased (+0.2%) to 99.243% when pulling ff9d943 on trappitsch:BF_and_tests_visa_communicator into ed74135 on Galvant:master.

@trappitsch trappitsch mentioned this pull request Jul 4, 2021
Copy link
Contributor

@scasagrande scasagrande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@scasagrande scasagrande merged commit 7d9acce into instrumentkit:master Jul 5, 2021
@trappitsch trappitsch deleted the BF_and_tests_visa_communicator branch July 5, 2021 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants