Skip to content

Commit

Permalink
Issue #91: adding Fixture for ykush switchable USB hub. (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
thirtytwobits committed Nov 19, 2019
1 parent dee8ca8 commit b47a462
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 2 deletions.
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ steps:
- ".tox/flake8/tmp/*"
- ".tox/dist/*.zip"
- ".tox/py*-test/tmp/xunit-result.xml"
- ".tox/py*-test/log/*.log"
plugins:
- docker#v3.3.0:
workdir: /repo
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
"xlabel",
"xunit",
"yepkit",
"ykush",
"ykushcmd",
"ylabel"
]
}
8 changes: 8 additions & 0 deletions docs/lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ Nanaimo (library)
:members:
:show-inheritance:

**************************************
:mod:`nanaimo.instruments.ykush`
**************************************

.. automodule:: nanaimo.instruments.ykush
:members:
:show-inheritance:

*************************************
:mod:`nanaimo.parsers`
*************************************
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# This is needed for read-the-docs. Please use tox -e local to install developer dependencies.

pyserial
pytest
pytest-asyncio
sphinx
sphinx-argparse
sphinx_rtd_theme
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ pytest11 =
pytest_nanaimo_serial_watch = nanaimo.builtin.nanaimo_serial_watch
pytest_nanaimo_instr_bkprecision = nanaimo.instruments.bkprecision
pytest_nanaimo_instr_saleae = nanaimo.instruments.saleae
pytest_nanaimo_instr_ykush = nanaimo.instruments.ykush
pytest_nanaimo_display = nanaimo.display
pytest_gtest_over_jlink = nanaimo.builtin.gtest_over_jlink
nanaimo =
nanaimo_builtin_bar = nanaimo.builtin.nanaimo_bar
nanaimo_builtin_saleae = nanaimo.instruments.saleae
nanaimo_builtin_ykush = nanaimo.instruments.ykush
nanaimo_builtin_gather = nanaimo.builtin.nanaimo_gather
nanaimo_builtin_cmd = nanaimo.builtin.nanaimo_cmd
nanaimo_builtin_scp = nanaimo.builtin.nanaimo_scp
Expand Down
1 change: 1 addition & 0 deletions src/nanaimo/instruments/saleae/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async def on_gather(self, args: nanaimo.Namespace) -> nanaimo.Artifacts:

writer.close()
await writer.wait_closed()
return nanaimo.Artifacts()


@nanaimo.fixtures.PluggyFixtureManager.type_factory
Expand Down
84 changes: 84 additions & 0 deletions src/nanaimo/instruments/ykush/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# This software is distributed under the terms of the MIT License.
#
# (@@@@%%%%%%%%%&@@&.
# /%&&%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&@@(
# *@&%%%%%%%%%&&%%%%%%%%%%%%%%%%%%&&&%%%%%%%
# @ @@@(@@@@%%%%%%%%%%%%%%%%&@@&* @@@ .
# , . . .@@@& /
# . . *
# @@ . @
# @&&&&&&@. . . *@%&@
# &&&&&&&&&&&&&&&&@@ *@@############@
# *&/ @@ #&&&&&&&&&&&&&&&&&&&&@ ###################*
# @&&&&&&&&&&&&&&&&&&##################@
# %@&&&&&&&&&&&&&&################@
# @&&&&&&&&&&%#######&@%
# nanaimo (@&&&&####@@*
#
"""
TODO: See https://www.learn.yepkit.com/reference/ykushcmd-reference-ykush/1/2 for the command
strings.
"""

import typing

import pytest

import nanaimo
import nanaimo.fixtures
import nanaimo.pytest.plugin


class Fixture(nanaimo.fixtures.SubprocessFixture):
"""
Fixture for controlling Yepkit USB hubs with switchable power. For example
the `YKUSH3 <https://www.yepkit.com/product/300110/YKUSH3>`_ is a 3-port
USB-3 hub that allows individual control of the power rails for each port.
"""

fixture_name = 'nanaimo_ykush'
argument_prefix = 'yku'

ykush_cmd = 'ykushcmd'

@classmethod
def on_visit_test_arguments(cls, arguments: nanaimo.Arguments) -> None:
arguments.add_argument('--model',
default='ykush3',
help='The ykush board type.')
arguments.add_argument('--serial',
help='A serial number of the board to send the command to.')
arguments.add_argument('--command',
help='Simple pass through of arguments to ')

def on_construct_command(self, arguments: nanaimo.Namespace, inout_artifacts: nanaimo.Artifacts) -> str:
serial_arg = self.get_arg_covariant(arguments, 'serial')
serial = ('' if serial_arg is None else ' -s ' + serial_arg)
return '{ykush_cmd} {board}{serial} {command}'.format(
ykush_cmd=self.ykush_cmd,
board=self.get_arg_covariant(arguments, 'model', ''),
serial=serial,
command=self.get_arg_covariant(arguments, 'command')
)


@nanaimo.fixtures.PluggyFixtureManager.type_factory
def get_fixture_type() -> typing.Type['Fixture']:
return Fixture


@pytest.fixture
def nanaimo_instr_ykush(request: typing.Any) -> nanaimo.fixtures.Fixture:
"""
Provides a :class:`nanaimo.instruments.ykush.Fixture` fixture to a pytest.
This fixture controls a `YKUSH <https://www.yepkit.com/products/ykush>`_
family board attached to the system via USB.
:param pytest_request: The request object passed into the pytest fixture factory.
:type pytest_request: _pytest.fixtures.FixtureRequest
:return: A fixture providing control of a YKUSH usb hub.
:rtype: nanaimo.instruments.ykush.Fixture
"""
return nanaimo.pytest.plugin.create_pytest_fixture(request, Fixture.get_canonical_name())
2 changes: 1 addition & 1 deletion src/nanaimo/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
# nanaimo (@&&&&####@@*
#

__version__ = '0.0.51'
__version__ = '0.0.52'

__license__ = 'MIT'
14 changes: 14 additions & 0 deletions test/test_ykush.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# This software is distributed under the terms of the MIT License.
#

import nanaimo
import nanaimo.fixtures


def test_ykush_exists(nanaimo_instr_ykush: nanaimo.fixtures.Fixture) -> None:
"""
Just making sure the fixture exists.
"""
assert nanaimo_instr_ykush.get_canonical_name() is not None
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ commands =
mypy -m nanaimo \
--cache-dir {envtmpdir} \
--txt-report {envtmpdir}/mypy-report-lib \
--config-file {toxinidir}/setup.cfg
--config-file {toxinidir}/tox.ini


[testenv:lint]
Expand Down Expand Up @@ -196,3 +196,6 @@ deps =
{[testenv:lint]deps}
{[testenv:docs]deps}
{[testenv:mypy]deps}

commands =
python --version

0 comments on commit b47a462

Please sign in to comment.