Skip to content

Commit

Permalink
MNT #81 apply black -l 75
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Dec 26, 2020
1 parent 35fa7ba commit b87a461
Showing 1 changed file with 77 additions and 68 deletions.
145 changes: 77 additions & 68 deletions hkl/tests/test_fourc.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

from bluesky import plans as bp
from bluesky.simulators import check_limits
from ophyd import (PseudoSingle, SoftPositioner)
from ophyd import PseudoSingle, SoftPositioner
from ophyd import Component as Cpt
from ophyd.positioner import LimitError
import numpy as np
import numpy.testing
import pytest

import gi
gi.require_version('Hkl', '5.0')

gi.require_version("Hkl", "5.0")
# NOTE: MUST call gi.require_version() BEFORE import hkl
from hkl.diffract import E4CV


class Fourc(E4CV):
h = Cpt(PseudoSingle, '')
k = Cpt(PseudoSingle, '')
l = Cpt(PseudoSingle, '')
h = Cpt(PseudoSingle, "")
k = Cpt(PseudoSingle, "")
l = Cpt(PseudoSingle, "")

omega = Cpt(SoftPositioner, limits=(-180, 180))
chi = Cpt(SoftPositioner, limits=(-180, 180))
Expand All @@ -31,9 +31,9 @@ def __init__(self, *args, **kwargs):
p._set_position(0) # give each a starting position


@pytest.fixture(scope='function')
@pytest.fixture(scope="function")
def fourc():
fourc = Fourc('', name="fourc")
fourc = Fourc("", name="fourc")
return fourc


Expand All @@ -59,11 +59,15 @@ def test_check_value(fourc):

with pytest.raises(TypeError) as exinfo:
assert fourc.check_value(1, 0, 0) is None
assert "check_value() takes 2 positional arguments" in str(exinfo.value)
assert "check_value() takes 2 positional arguments" in str(
exinfo.value
)

with pytest.raises(ValueError) as exinfo:
assert fourc.check_value(1) is None
assert "Not all required values for a PseudoPosition" in str(exinfo.value)
assert "Not all required values for a PseudoPosition" in str(
exinfo.value
)

assert fourc.check_value(dict(h=1, tth=0)) is None

Expand All @@ -78,98 +82,103 @@ def test_check_value(fourc):

def test_move(fourc):
ppos = (1.2, 1.2, 0.001)
rpos = (58.051956519652485, 44.99999005281953,
89.95225352812487, 116.10391303930497)
rpos = (
58.051956519652485,
44.99999005281953,
89.95225352812487,
116.10391303930497,
)
fourc.move(ppos)
numpy.testing.assert_almost_equal(fourc.position, ppos)
numpy.testing.assert_almost_equal(tuple(fourc.real_position), rpos)


def test_hl_scan(fourc):
fourc.move((1.2, 1.2, 0.001))
assert check_limits(
bp.scan(
[fourc],
fourc.h, 0.9, 1.1,
fourc.l, 0, 0,
11)
) is None
assert (
check_limits(
bp.scan([fourc], fourc.h, 0.9, 1.1, fourc.l, 0, 0, 11)
)
is None
)


def test_h00_scan(fourc):
fourc.move(1, 0, 0)
assert check_limits(
bp.scan(
[fourc],
fourc.h, 0.9, 1.1,
fourc.l, 0, 0,
11)
) is None
assert (
check_limits(
bp.scan([fourc], fourc.h, 0.9, 1.1, fourc.l, 0, 0, 11)
)
is None
)


def test_hkl_scan(fourc):
fourc.move(1, 1, 1)
assert check_limits(
bp.scan(
[fourc],
fourc.h, 0.9, 1.1,
fourc.k, 0.9, 1.1,
fourc.l, 0.9, 1.1,
33)
) is None
assert (
check_limits(
bp.scan(
[fourc],
fourc.h,
0.9,
1.1,
fourc.k,
0.9,
1.1,
fourc.l,
0.9,
1.1,
33,
)
)
is None
)


def test_hkl_range_error(fourc):
with pytest.raises(ValueError) as exinfo:
assert check_limits(
bp.scan(
[fourc],
fourc.h, 0.9, 1.1,
fourc.k, 0.9, 1.1,
fourc.l, 0.09, 123.1,
33)
) is None
assert (
check_limits(
bp.scan(
[fourc],
fourc.h,
0.9,
1.1,
fourc.k,
0.9,
1.1,
fourc.l,
0.09,
123.1,
33,
)
)
is None
)
assert "Unable to solve." in str(exinfo.value)


def test_real_axis(fourc):
assert check_limits(
bp.scan(
[fourc],
fourc.tth, 10, 20,
3)
) is None
assert check_limits(bp.scan([fourc], fourc.tth, 10, 20, 3)) is None


def test_axis_contention(fourc):
# contention if move pseudo and real positioners together
with pytest.raises(ValueError) as exinfo:
check_limits(
bp.scan(
[fourc],
fourc.tth, 10, 20,
fourc.k, 0, 0,
3)
)
check_limits(bp.scan([fourc], fourc.tth, 10, 20, fourc.k, 0, 0, 3))
assert "mix of real and pseudo" in str(exinfo.value)


def test_real_axis_range_multi(fourc):
assert check_limits(
bp.scan(
[fourc],
fourc.tth, 10, 20,
fourc.chi, 5, 7,
3)
) is None
assert (
check_limits(
bp.scan([fourc], fourc.tth, 10, 20, fourc.chi, 5, 7, 3)
)
is None
)


def test_real_axis_range_error(fourc):
with pytest.raises(LimitError) as exinfo:
check_limits(
bp.scan(
[fourc],
fourc.tth, 10, 20000,
3)
)
check_limits(bp.scan([fourc], fourc.tth, 10, 20000, 3))
assert "not within limits" in str(exinfo.value)

0 comments on commit b87a461

Please sign in to comment.