Skip to content

Commit

Permalink
Merge #486
Browse files Browse the repository at this point in the history
486: Python 2 drop and tests improvement r=MatthieuDartiailh a=MatthieuDartiailh

With the new year it is time to drop Python 2. 

Also thanks to the generous support of Keysight, PyVISA developers can have access to a virtual instrument software allowing to test more thoroughly PyVISA. As a consequence the testsuite has been vastly increased and now cover much more code even without Keysight software installed. Hopefully this will help speed up the development of PyVISA. 

As a follow-up to this PR, I will try to introduce the use of Black to format the codebase and add type hints.

Co-authored-by: MatthieuDartiailh <marul@laposte.net>
Co-authored-by: mdartiailh <m.dartiailh@gmail.com>
  • Loading branch information
3 people committed Feb 2, 2020
2 parents 09078c2 + 0df812b commit 7cbbf9c
Show file tree
Hide file tree
Showing 61 changed files with 3,710 additions and 1,039 deletions.
17 changes: 17 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[run]
branch = True
include =
*/pyvisa/*
omit =
*/pyvisa/testsuite/*
*/pyvisa/thirdparty/*

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain if tests don't hit defensive assertion code:
raise NotImplementedError
pass
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ build/
dist/
MANIFEST
.tox
.coveragerc
.coverage
# WebDAV file system cache files
.DAV/
_test/
.vscode
htmlcov/
24 changes: 14 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ branches:
- master

python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"

install:
- if [ $TRAVIS_PYTHON_VERSION == '2.7' ] || [ $TRAVIS_PYTHON_VERSION == '3.6' ]; then pip install numpy; fi
- pip install coverage coveralls
- if [ $TRAVIS_PYTHON_VERSION == '3.6' ]; then pip install numpy; fi
- pip install pytest pytest-cov

# Install codecov report tools
- pip install codecov

before_install:
- cd $TRAVIS_BUILD_DIR
- python setup.py develop

script:
- coverage run -p --source=pyvisa --omit="*test*","*compat*" setup.py test
- coverage combine
- coverage report -m
- pytest pyvisa -v --cov pyvisa

after_script:
- coveralls --verbose
after_success:
- cd $TRAVIS_BUILD_DIR
- codecov
14 changes: 14 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ PyVISA Changelog
1.11 (unreleased)
-----------------

- Drop Python 2 support PR #486
- Limit support to Python 3.6+ PR #486
- Improve the test suite and introduce tests relying on Keysight Virtual
instrument software PR #486
- Add badges to the README PR #486
- Improve ResourceManager.list_opened_resource to list only open resources.
Previously all resources created and not yet garbage collected were listed. PR #486
- Always normalize resource names PR #486
- Treat floating points number as double when parsing ASCII data blocks PR #486
- Allow bound methods as handler function (the use of is in tests prevented it) PR #486
- Deprecate some unused functions found in the util.py module PR #486
- Warn or raise if the beginning of a binary block is not found among the first characters.
The default value is 25. PR #486
-
- Make the library less biased towards National Instrument by referring to IVI
where relevant. In particular rename the @ni backend to @ivi PR #456
- Deprecate the `visa` module that is causing issue with the VISA payment
Expand Down
18 changes: 17 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
PyVISA
======


.. image:: https://travis-ci.org/pyvisa/pyvisa.svg?branch=master
:target: https://travis-ci.org/pyvisa/pyvisa
:alt: Build Status
.. image:: https://codecov.io/gh/pyvisa/pyvisa/branch/master/graph/badge.svg
:target: https://codecov.io/gh/pyvisa/pyvisa
:alt: Code Coverage
.. image:: https://readthedocs.org/projects/pyvisa/badge/?version=latest
:target: https://pyvisa.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://img.shields.io/pypi/l/PyVISA
:target: https://pypi.python.org/pypi/pyvisa
:alt: PyPI - License
.. image:: https://img.shields.io/pypi/v/PyVISA
:target: https://pypi.python.org/pypi/pyvisa
:alt: PyPI

A Python package for support of the "Virtual Instrument Software
Architecture" (VISA), in order to control measurement devices and
test equipment via GPIB, RS232, Ethernet or USB.


Description
-----------

Expand Down
4 changes: 2 additions & 2 deletions docs/source/introduction/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ The following sections explore the most common attributes of ``Resource`` and
often. For more information, refer to the :ref:`api`.


Attributes Resource
-------------------
Attributes of Resource
----------------------

session
~~~~~~~
Expand Down
6 changes: 1 addition & 5 deletions pyvisa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@
:copyright: 2014-2019 by PyVISA Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""

from __future__ import division, unicode_literals, print_function, absolute_import

import logging
import pkg_resources

from . import compat
logger = logging.getLogger('pyvisa')
logger.addHandler(compat.NullHandler())
logger.addHandler(logging.NullHandler())


def log_to_screen(level=logging.DEBUG):
Expand Down
42 changes: 18 additions & 24 deletions pyvisa/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
:copyright: 2014 by PyVISA Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""

from __future__ import division, unicode_literals, print_function, absolute_import

from collections import defaultdict

from .compat import with_metaclass
from . import constants

#: Not available value.
Expand Down Expand Up @@ -53,8 +49,9 @@ def __init__(cls, name, bases, dct):
AttributesByID[cls.attribute_id] = cls


class Attribute(with_metaclass(AttributeType)):
class Attribute(object, metaclass=AttributeType):
"""Base class for Attributes to be used as Properties.
"""

#: List of resource types with this attribute.
Expand Down Expand Up @@ -143,11 +140,18 @@ def post_get(self, value):
return self.enum_type(value)

def pre_set(self, value):
if value not in self.enum_type:
# Python 3.8 raise if a non-Enum is used for value
try:
if value not in self.enum_type:
raise ValueError('%r is an invalid value for attribute %s, '
'should be a %r' % (value,
self.visa_name,
self.enum_type))
except TypeError:
raise ValueError('%r is an invalid value for attribute %s, '
'should be a %r' % (value,
self.visa_name,
self.enum_type))
'should be a %r' % (value,
self.visa_name,
self.enum_type))
return value


Expand Down Expand Up @@ -608,7 +612,7 @@ class AttrVI_ATTR_ASRL_PARITY(EnumAttribute):


# noinspection PyPep8Naming
class AttrVI_ATTR_ASRL_REPLACE_CHAR(RangeAttribute):
class AttrVI_ATTR_ASRL_REPLACE_CHAR(CharAttribute):
"""VI_ATTR_ASRL_REPLACE_CHAR specifies the character to be used to
replace incoming characters that arrive with errors (such as
parity error).
Expand All @@ -625,8 +629,6 @@ class AttrVI_ATTR_ASRL_REPLACE_CHAR(RangeAttribute):

read, write, local = True, True, True

min_value, max_value, values = 0, 0xFF, []


# noinspection PyPep8Naming
class AttrVI_ATTR_ASRL_RI_STATE(EnumAttribute):
Expand Down Expand Up @@ -714,7 +716,7 @@ class AttrVI_ATTR_ASRL_WIRE_MODE(RangeAttribute):


# noinspection PyPep8Naming
class AttrVI_ATTR_ASRL_XOFF_CHAR(RangeAttribute):
class AttrVI_ATTR_ASRL_XOFF_CHAR(CharAttribute):
"""VI_ATTR_ASRL_XOFF_CHAR specifies the value of the XOFF character used
for XON/XOFF flow control (both directions). If XON/XOFF flow
control (software handshaking) is not being used, the value of
Expand All @@ -732,11 +734,9 @@ class AttrVI_ATTR_ASRL_XOFF_CHAR(RangeAttribute):

read, write, local = True, True, True

min_value, max_value, values = 0, 0xFF, []


# noinspection PyPep8Naming
class AttrVI_ATTR_ASRL_XON_CHAR(RangeAttribute):
class AttrVI_ATTR_ASRL_XON_CHAR(CharAttribute):
"""VI_ATTR_ASRL_XON_CHAR specifies the value of the XON character used
for XON/XOFF flow control (both directions). If XON/XOFF flow
control (software handshaking) is not being used, the value of
Expand All @@ -754,8 +754,6 @@ class AttrVI_ATTR_ASRL_XON_CHAR(RangeAttribute):

read, write, local = True, True, True

min_value, max_value, values = 0, 0xFF, []


# Could not generate class for VI_ATTR_BUFFER.html
# Exception:
Expand Down Expand Up @@ -860,7 +858,7 @@ class AttrVI_ATTR_DEST_INCREMENT(RangeAttribute):


# noinspection PyPep8Naming
class AttrVI_ATTR_DEV_STATUS_BYTE(RangeAttribute):
class AttrVI_ATTR_DEV_STATUS_BYTE(CharAttribute):
"""This attribute specifies the 488-style status byte of the local
controller or device associated with this session.
"""
Expand All @@ -877,8 +875,6 @@ class AttrVI_ATTR_DEV_STATUS_BYTE(RangeAttribute):

read, write, local = True, True, False

min_value, max_value, values = 0, 0xFF, []


# noinspection PyPep8Naming
class AttrVI_ATTR_DMA_ALLOW_EN(BooleanAttribute):
Expand Down Expand Up @@ -2480,7 +2476,7 @@ class AttrVI_ATTR_TCPIP_PORT(RangeAttribute):


# noinspection PyPep8Naming
class AttrVI_ATTR_TERMCHAR(RangeAttribute):
class AttrVI_ATTR_TERMCHAR(CharAttribute):
"""VI_ATTR_TERMCHAR is the termination character. When the termination
character is read and VI_ATTR_TERMCHAR_EN is enabled during a read
operation, the read operation terminates.
Expand All @@ -2505,8 +2501,6 @@ class AttrVI_ATTR_TERMCHAR(RangeAttribute):

read, write, local = True, True, True

min_value, max_value, values = 0, 0xFF, []


# noinspection PyPep8Naming
class AttrVI_ATTR_TERMCHAR_EN(BooleanAttribute):
Expand Down

0 comments on commit 7cbbf9c

Please sign in to comment.