Skip to content

Commit

Permalink
Merge #545
Browse files Browse the repository at this point in the history
545: Fix list backends r=MatthieuDartiailh a=MatthieuDartiailh

- [x] Executed ``black . && isort -c . && flake8`` with no errors
- [x] The change is fully covered by automated unit tests (in pyvisa/pyvisa-py#269)
- [x] Added an entry to the CHANGES file


Co-authored-by: MatthieuDartiailh <marul@laposte.net>
  • Loading branch information
bors[bot] and MatthieuDartiailh committed Sep 23, 2020
2 parents 8b4e224 + 606c421 commit b59e099
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Test with pytest
run: |
pip install pytest-cov
pytest --pyargs pyvisa --cov pyvisa --cov-report xml
pytest --pyargs pyvisa --cov pyvisa --cov-report xml -v
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
PyVISA Changelog
================

1.11.1 (unreleased)
-------------------

- fix the listing of available backends (Also not that we now return the backend
name as can be used to create a ResourceManger) PR #545

1.11 (16-09-2020)
-----------------

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PyVISA
:target: https://github.com/pyvisa/pyvisa/actions
:alt: Documentation building
.. image:: https://dev.azure.com/pyvisa/pyvisa/_apis/build/status/pyvisa.keysight-assisted?branchName=master
:target: https://github.com/pyvisa/pyvisa/actions
:target: https://dev.azure.com/pyvisa/pyvisa/_build
:alt: Keysight assisted testing
.. image:: https://codecov.io/gh/pyvisa/pyvisa/branch/master/graph/badge.svg
:target: https://codecov.io/gh/pyvisa/pyvisa
Expand Down
7 changes: 4 additions & 3 deletions pyvisa/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2775,14 +2775,15 @@ def write_from_file(
def list_backends() -> List[str]:
"""Return installed backends.
Backends are installed python packages named pyvisa-<something> where <something>
Backends are installed python packages named pyvisa_<something> where <something>
is the name of the backend.
"""
return ["ivi"] + [
name
name[7:]
for (loader, name, ispkg) in pkgutil.iter_modules()
if name.startswith("pyvisa-") and not name.endswith("-script")
if (name.startswith("pyvisa_") or name.startswith("pyvisa-"))
and not name.endswith("-script")
]


Expand Down
14 changes: 11 additions & 3 deletions pyvisa/testsuite/test_cmd_line_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def test_visa_main(self):
print(result.stdout.strip())
print()
print(details.strip())
assert result.stdout.strip() == details.strip()
# Path difference can lead to subtle differences in the backends
# compare only the first lines.
assert (
result.stdout.strip().split("\n")[:16] == details.strip().split("\n")[:16]
)

with Popen(["python", "-m", "visa", "shell"], stdin=PIPE, stdout=PIPE) as p:
stdout, _ = p.communicate(b"exit")
Expand All @@ -51,9 +55,13 @@ def test_visa_info(self):
"""Test the visa info command line tool."""
result = run("pyvisa-info", stdout=PIPE, universal_newlines=True)
details = util.system_details_to_str(util.get_system_details())
assert result.stdout.strip() == details.strip()
# Path difference can lead to subtle differences in the backends
# compare only the first lines.
assert (
result.stdout.strip().split("\n")[:16] == details.strip().split("\n")[:16]
)

# TODO test backend selection: this not easy at all to assert
# TODO test backend selection: this is not easy at all to assert
@require_visa_lib
def test_visa_shell(self):
"""Test the visa shell function."""
Expand Down
14 changes: 14 additions & 0 deletions pyvisa/testsuite/test_highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ def _init(self):
assert "oserror" in msg[1]
assert "error" in msg[2]

def test_list_backends(self):
"""Test listing backends."""
highlevel._WRAPPERS.clear()

path = os.path.join(os.path.dirname(__file__), "fake-extensions")
sys.path.append(path)
try:
backends = highlevel.list_backends()
finally:
sys.path.remove(path)

assert "ivi" in backends
assert "test" in backends

def test_get_wrapper_class(self):
"""Test retrieving a wrapper class."""
highlevel._WRAPPERS.clear()
Expand Down

0 comments on commit b59e099

Please sign in to comment.