Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ install:
- pipenv install --dev

script:
- pipenv run python -m pytest --cov=pytac --pep8 --flakes
- pipenv run python -m pytest --cov=pytac
- pipenv run flake8

after_success:
- coveralls
8 changes: 1 addition & 7 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[dev-packages]

pytest = "*"
pytest-cov = "*"
python-coveralls = "*"
mock = "*"
pytest-flakes = "*"
"pytest-pep8" = "*"
"flake8" = "*"
bpython = "*"
sphinx = "*"
sphinx-rtd-theme = "*"


[packages]

numpy = "*"
scipy = "*"
432 changes: 0 additions & 432 deletions Pipfile.lock

This file was deleted.

2 changes: 1 addition & 1 deletion pytac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
SIM = 'simulation'
LIVE = 'live'

from . import device, element, lattice, load_csv, utils
from . import device, element, lattice, load_csv, utils # noqa: E402,F401
15 changes: 9 additions & 6 deletions pytac/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def set_value(self, value):
DeviceException: if no setpoint PV exists.
"""
if self.sp_pv is None:
raise DeviceException("""Device {0} has no setpoint PV."""
.format(self.name))
raise DeviceException(
"Device {0} has no setpoint PV.".format(self.name)
)
self._cs.put(self.sp_pv, value)

def get_value(self, handle):
Expand All @@ -96,8 +97,9 @@ def get_value(self, handle):
elif handle == pytac.SP and self.sp_pv:
return self._cs.get(self.sp_pv)

raise DeviceException("""Device {0} has no {1} PV."""
.format(self.name, handle))
raise DeviceException(
"Device {0} has no {1} PV.".format(self.name, handle)
)

def get_pv_name(self, handle):
"""Get a PV name on a specified handle.
Expand All @@ -116,8 +118,9 @@ def get_pv_name(self, handle):
elif handle == pytac.SP and self.sp_pv:
return self.sp_pv

raise DeviceException("""Device {0} has no {1} PV."""
.format(self.name, handle))
raise DeviceException(
"Device {0} has no {1} PV.".format(self.name, handle)
)

def get_cs(self):
"""The control system object used to get and set the value of a PV.
Expand Down
6 changes: 4 additions & 2 deletions pytac/load_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ def load(mode, control_system=None, directory=None):
from pytac import epics
control_system = epics.EpicsControlSystem()
except ImportError:
print(('To load a lattice using the default control system, please'
' install cothread.'), file=sys.stderr)
print(
('To load a lattice using the default control system, please'
' install cothread.'), file=sys.stderr
)
return None
if directory is None:
directory = os.path.join(os.path.dirname(os.path.abspath(__file__)),
Expand Down
10 changes: 0 additions & 10 deletions requirements.txt

This file was deleted.

11 changes: 11 additions & 0 deletions rtd-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is still required as readthedocs doesn't yet support Pipfile.
# See https://github.com/rtfd/readthedocs.org/issues/3181
numpy
scipy
cothread
pytest
pytest-cov
flake8
mock
python-coveralls
sphinx_rtd_theme
15 changes: 5 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ description-file = README.rst
[bdist_wheel]
universal=1

[tool:pytest]
pep8ignore =
E121 E126 E127 E128 E501
pytac/__init__.py E402
docs/conf.py ALL

flakes-ignore =
pytac/__init__.py UnusedImport
docs/conf.py ALL

[flake8]
exclude = docs,build
ignore =
# E501 line too long
E501
5 changes: 3 additions & 2 deletions test/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
def create_device(prefix=PREFIX, rb_pv=RB_PV, sp_pv=SP_PV, enabled=True):
mock_cs = mock.MagicMock()
mock_cs.get.return_value = '1.0'
device = pytac.device.Device(prefix, mock.MagicMock(), enabled=enabled,
rb_pv=rb_pv, sp_pv=sp_pv)
device = pytac.device.Device(
prefix, mock.MagicMock(), enabled=enabled, rb_pv=rb_pv, sp_pv=sp_pv
)
return device


Expand Down
21 changes: 11 additions & 10 deletions test/test_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def simple_element(identity=1):

@pytest.fixture
def simple_element_and_lattice(simple_element, mock_cs):
l = pytac.lattice.Lattice(LATTICE, mock_cs, 1)
l.add_element(simple_element)
return simple_element, l
lat = pytac.lattice.Lattice(LATTICE, mock_cs, 1)
lat.add_element(simple_element)
return simple_element, lat


def test_create_lattice():
l = pytac.lattice.Lattice(LATTICE, mock.MagicMock(), 1)
assert(len(l)) == 0
assert l.name == LATTICE
lat = pytac.lattice.Lattice(LATTICE, mock.MagicMock(), 1)
assert(len(lat)) == 0
assert lat.name == LATTICE


def test_get_devices(simple_element_and_lattice):
Expand Down Expand Up @@ -107,12 +107,13 @@ def test_get_values(simple_element_and_lattice):
lattice._cs.get.assert_called_with([RB_PV])


@pytest.mark.parametrize('dtype,expected', (
@pytest.mark.parametrize(
'dtype,expected', (
(numpy.float64, numpy.array(DUMMY_ARRAY, dtype=numpy.float64)),
(numpy.int32, numpy.array(DUMMY_ARRAY, dtype=numpy.int32)),
(numpy.bool_, numpy.array((False, True, True), dtype=numpy.bool_)),
(None, DUMMY_ARRAY)
))
))
def test_get_values_returns_numpy_array_if_requested(simple_element_and_lattice, dtype, expected):
element, lattice = simple_element_and_lattice
values = lattice.get_values('family', 'x', pytac.RB, dtype=dtype)
Expand Down Expand Up @@ -146,10 +147,10 @@ def test_s_position(simple_element_and_lattice):


def test_get_s_throws_exception_if_element_not_in_lattice():
l = pytac.lattice.Lattice(LATTICE, mock.MagicMock(), 1)
lat = pytac.lattice.Lattice(LATTICE, mock.MagicMock(), 1)
element = pytac.element.Element(1, 1.0, 'Quad')
with pytest.raises(pytac.lattice.LatticeException):
l.get_s(element)
lat.get_s(element)


def test_get_family_s(simple_element_and_lattice):
Expand Down
43 changes: 26 additions & 17 deletions test/test_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def test_load_lattice_using_default_dir():
assert len(lat) == 2143


@pytest.mark.parametrize('ring_mode,n_elements,length', [
@pytest.mark.parametrize(
'ring_mode,n_elements,length', [
('VMX', 2143, 561.571),
('DIAD', 2145, 561.571)
])
Expand All @@ -34,7 +35,8 @@ def test_load_lattice(ring_mode, n_elements, length):
assert (lattice.get_length() - length) < EPS


@pytest.mark.parametrize('ring_mode,n_bpms', [
@pytest.mark.parametrize(
'ring_mode,n_bpms', [
('VMX', 173),
('DIAD', 173)
])
Expand All @@ -50,18 +52,20 @@ def test_get_pv_names(ring_mode, n_bpms):
assert re.match('SR.*HBPM.*SLOW:DISABLED', pv)


@pytest.mark.parametrize('ring_mode,n_bpms', [
@pytest.mark.parametrize(
'ring_mode,n_bpms', [
('VMX', 173),
('DIAD', 173)
])
def test_load_bpms(ring_mode, n_bpms):
lattice = get_lattice(ring_mode)
bpms = lattice.get_elements('BPM')
bpm_fields = {
'x', 'y', 'enabled', 'x_fofb_disabled', 'x_sofb_disabled',
'y_fofb_disabled', 'y_sofb_disabled'
}
for bpm in bpms:
assert set(bpm.get_fields()) == set(
('x', 'y', 'enabled', 'x_fofb_disabled', 'x_sofb_disabled',
'y_fofb_disabled', 'y_sofb_disabled')
)
assert set(bpm.get_fields()) == bpm_fields
assert re.match('SR.*BPM.*X', bpm.get_pv_name('x', pytac.RB))
with pytest.raises(pytac.device.DeviceException):
bpm.get_pv_name('x', pytac.SP)
Expand All @@ -70,7 +74,8 @@ def test_load_bpms(ring_mode, n_bpms):
assert bpms[-1].cell == 24


@pytest.mark.parametrize('ring_mode,n_drifts', [
@pytest.mark.parametrize(
'ring_mode,n_drifts', [
('VMX', 1308),
('DIAD', 1311)
])
Expand All @@ -80,7 +85,8 @@ def test_load_drift_elements(ring_mode, n_drifts):
assert len(drifts) == n_drifts


@pytest.mark.parametrize('ring_mode,n_quads', [
@pytest.mark.parametrize(
'ring_mode,n_quads', [
('VMX', 248),
('DIAD', 248)
])
Expand All @@ -95,7 +101,8 @@ def test_load_quadrupoles(ring_mode, n_quads):
assert re.match('SR.*Q.*:SETI', device.sp_pv)


@pytest.mark.parametrize('ring_mode,n_q1b,n_q1d', [
@pytest.mark.parametrize(
'ring_mode,n_q1b,n_q1d', [
('VMX', 34, 12),
('DIAD', 34, 12)
])
Expand All @@ -107,7 +114,8 @@ def test_load_quad_family(ring_mode, n_q1b, n_q1d):
assert len(q1d) == n_q1d


@pytest.mark.parametrize('ring_mode,n_correctors', [
@pytest.mark.parametrize(
'ring_mode,n_correctors', [
('VMX', 173),
('DIAD', 172)
])
Expand All @@ -119,15 +127,14 @@ def test_load_correctors(ring_mode, n_correctors):
assert len(vcm) == n_correctors
for element in hcm:
# each one has b0, h_fofb_disabled and h_sofb_disabled fields.
assert set(('b0', 'h_sofb_disabled', 'h_fofb_disabled')
).issubset(element.get_fields())
assert {'b0', 'h_sofb_disabled', 'h_fofb_disabled'}.issubset(element.get_fields())
for element in vcm:
# each one has a0, v_fofb_disabled and v_sofb_disabled fields.
assert set(('a0', 'v_sofb_disabled', 'v_fofb_disabled')
).issubset(element.get_fields())
assert {'a0', 'v_sofb_disabled', 'v_fofb_disabled'}.issubset(element.get_fields())


@pytest.mark.parametrize('ring_mode,n_squads', [
@pytest.mark.parametrize(
'ring_mode,n_squads', [
('VMX', 98),
('DIAD', 98)
])
Expand All @@ -142,7 +149,9 @@ def test_load_squads(ring_mode, n_squads):
assert re.match('SR.*SQ.*:SETI', device.sp_pv)


@pytest.mark.parametrize('ring_mode', ('VMX', 'DIAD'))
@pytest.mark.parametrize(
'ring_mode', ('VMX', 'DIAD')
)
def test_cell(ring_mode):
lattice = get_lattice(ring_mode)
# there are squads in every cell
Expand Down
5 changes: 3 additions & 2 deletions test/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ def test_UnitConv_not_implemented():
uc.eng_to_phys(-11)


@pytest.mark.parametrize('origin,target', [
@pytest.mark.parametrize(
'origin,target', [
(pytac.LIVE, pytac.ENG),
(pytac.PHYS, pytac.SP),
('a', 'b')
])
])
def test_UnitConv_requires_correct_arguments(origin, target):
uc = UnitConv()
with pytest.raises(UnitsException):
Expand Down