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 Test/test_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@author: Kay Kasemir
"""
from __future__ import print_function
import unittest
from scan.commands import Set, CommandSequence
from scan.alignment import AlignmentScan
Expand All @@ -13,7 +14,7 @@ def testBasics(self):
pre=Set("motor_y", 3),
find_command="FindPeak")
cmds = align.createScan()
print CommandSequence(cmds)
print(CommandSequence(cmds))

self.assertEqual(str(cmds), "[Set('Demo:CS:Scan:Fit:Height', 0), Set('motor_y', 3), Loop('motor_x', 0, 10, 0.5, [ Delay(0.5), Log('signal', 'motor_x'), Script('WriteDataToPV', 'motor_x', 'Demo:CS:Scan:Fit:Data:X'), Script('WriteDataToPV', 'signal', 'Demo:CS:Scan:Fit:Data:Y', '-', '1') ]), Script('FindPeak', 'motor_x', 'signal', '-', '1', 'Demo:CS:Scan:Fit:Pos', 'Demo:CS:Scan:Fit:Height', 'Demo:CS:Scan:Fit:Width')]")

Expand Down
182 changes: 91 additions & 91 deletions Test/test_commands.py

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions Test/test_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from scan.client.logdata import iterateSamples, getDatetime, parseXMLData, createTable

# client = ScanClient()
Expand Down Expand Up @@ -101,19 +102,19 @@

# client.getData(id) calls this to turn the XML data into a data dict:
data = parseXMLData(xml_text)
print data
print(data)

# Direct access to data dict
print "Times: ", [ str(getDatetime(time)) for time in data['motor_x']['time'] ]
print "Values: ", data['motor_x']['value']
print("Times: ", [ str(getDatetime(time)) for time in data['motor_x']['time'] ])
print("Values: ", data['motor_x']['value'])

# Demo of sample iterator
for s in iterateSamples(data, 'motor_x'):
print "%s (%2d): %s" % (str(getDatetime(s[1])), s[0], str(s[2]))
print("%s (%2d): %s" % (str(getDatetime(s[1])), s[0], str(s[2])))

# Create table, i.e. align samples for different devices by sample ID:
table = createTable(data, 'motor_x', 'motor_y')
print table[0]
print table[1]
print(table[0])
print(table[1])

# With numpy/scipy: plot(table[0], table[1]) etc.
13 changes: 7 additions & 6 deletions Test/test_ndim.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
>>> from __future__ import print_function
>>> from scan import *

>>> class MyScanSettings(ScanSettings):
Expand All @@ -7,7 +8,7 @@
...
>>> setScanSettings(MyScanSettings())

>>> print CommandSequence(createNDimScan(('xpos', 1, 10)))
>>> print(CommandSequence(createNDimScan(('xpos', 1, 10))))
[
Loop('xpos', 1, 10, 1,
[
Expand All @@ -17,16 +18,16 @@
>>>


>>> print CommandSequence(createNDimScan(('xpos', 1, 10), 'readback'))
>>> print(CommandSequence(createNDimScan(('xpos', 1, 10), 'readback')))
[
Loop('xpos', 1, 10, 1,
[
Log('xpos', 'readback')
], completion=True)
]

>>> print CommandSequence(createNDimScan(('xpos', 1, 10),
... ('ypos', 1, 5, 0.2), 'readback'))
>>> print(CommandSequence(createNDimScan(('xpos', 1, 10),
... ('ypos', 1, 5, 0.2), 'readback')))
[
Loop('xpos', 1, 10, 1,
[
Expand All @@ -37,10 +38,10 @@
], completion=True)
]

>>> print CommandSequence(createNDimScan(
>>> print(CommandSequence(createNDimScan(
... ('xpos', 1, 10),
... ('ypos', 1, 5, 0.2),
... Set('xyz', 1), Set('xyz', 0)))
... Set('xyz', 1), Set('xyz', 0))))
[
Loop('xpos', 1, 10, 1,
[
Expand Down
25 changes: 13 additions & 12 deletions Test/test_range_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: Kay Kasemir
"""
from __future__ import print_function
from scan.table.range_helper import getRangeOrLoop, range_matcher, loop_matcher, getIterable, expandRanges
import unittest

Expand Down Expand Up @@ -68,26 +69,26 @@ def test_expand(self):
# One range stepping down
[ "Line 4", "range(2)", "Seconds", "range(2,0,-1)" ],
]
print "Original:"
print("Original:")
for row in rows:
print row
print "Expanded:"
print(row)
print("Expanded:")
result = expandRanges(rows)
for row in result:
print row
print(row)
self.assertEqual(len(result), 14)

# List, tuple
rows = [
[ "( 2, 4)", "[ 0, 90, 180]", "Seconds" ],
]
print "Original:"
print("Original:")
for row in rows:
print row
print "Expanded:"
print(row)
print("Expanded:")
result = expandRanges(rows)
for row in result:
print row
print(row)
self.assertEqual(len(result), 6)


Expand All @@ -98,13 +99,13 @@ def test_expand(self):
[ "Jane", "[2]", "Seconds" ],
[ "Nop2", "range(2, 0, 2)", "Seconds" ],
]
print "Original:"
print("Original:")
for row in rows:
print row
print "Expanded:"
print(row)
print("Expanded:")
result = expandRanges(rows)
for row in result:
print row
print(row)
self.assertEqual(len(result), 4)


Expand Down
29 changes: 15 additions & 14 deletions Test/test_scan_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@author: Kay Kasemir
"""
from __future__ import print_function
import unittest
from scan.commands.delay import Delay
from scan.util.scan_settings import DeviceSettings, ScanSettings, setScanSettings, SettingsBasedSet, SettingsBasedLoop, SettingsBasedWait
Expand Down Expand Up @@ -32,17 +33,17 @@ def getReadbackName(self, device_name):
class DeviceSettingsTest(unittest.TestCase):
def testDefaultSettings(self):
s = DeviceSettings("device", readback=False)
print s
print(s)
self.assertEquals(s.getName(), "device")
self.assertEquals(s.getReadback(), None)

s = DeviceSettings("device", readback=True)
print s
print(s)
self.assertEquals(s.getName(), "device")
self.assertEquals(s.getReadback(), "device")

s = DeviceSettings("device", readback="other")
print s
print(s)
self.assertEquals(s.getName(), "device")
self.assertEquals(s.getReadback(), "other")

Expand All @@ -51,7 +52,7 @@ def testCustomSettings(self):

# Device that has no specific settings, using the default
s = settings.getDefaultSettings("SomeRandomDevice")
print s
print(s)
self.assertEquals(s.getName(), "SomeRandomDevice")
self.assertEquals(s.getCompletion(), False)
self.assertEquals(s.getReadback(), "SomeRandomDevice")
Expand All @@ -60,7 +61,7 @@ def testCustomSettings(self):

# Check device that should have special settings
s = settings.getDefaultSettings("My:Lakeshore1")
print s
print(s)
self.assertEquals(s.getName(), "My:Lakeshore1")
self.assertEquals(s.getCompletion(), True)
self.assertEquals(s.getReadback(), None)
Expand All @@ -69,14 +70,14 @@ def testCustomSettings(self):

# Check device that should NOT have them
s = settings.getDefaultSettings("Your:Lakeshore1")
print s
print(s)
self.assertEquals(s.getName(), "Your:Lakeshore1")
self.assertEquals(s.getCompletion(), False)
self.assertEquals(s.getReadback(), "Your:Lakeshore1")

# 'Motor' that uses *.RBV for a readback
s = settings.getDefaultSettings("My:Motor:47")
print s
print(s)
self.assertEquals(s.getName(), "My:Motor:47")
self.assertEquals(s.getCompletion(), True)
self.assertEquals(s.getReadback(), "My:Motor:47.RBV")
Expand All @@ -85,11 +86,11 @@ def testCustomSettings(self):

# Different comparisons
s = settings.getDefaultSettings("SomeCounter")
print s
print(s)
self.assertEquals(s.getComparison(), '>=')

s = settings.getDefaultSettings("PerpetualCounter")
print s
print(s)
self.assertEquals(s.getComparison(), 'increase by')


Expand All @@ -98,7 +99,7 @@ def testDeviceModifiers(self):

spec = "My:Lakeshore1"
s = settings.parseDeviceSettings(spec)
print "%s -> %s" % (spec, s)
print("%s -> %s" % (spec, s))
self.assertEquals(s.getName(), "My:Lakeshore1")
self.assertEquals(s.getCompletion(), True)
self.assertEquals(s.getReadback(), None)
Expand All @@ -111,29 +112,29 @@ def testDeviceModifiers(self):

spec = "-c My:Lakeshore1"
s = settings.parseDeviceSettings(spec)
print "%s -> %s" % (spec, s)
print("%s -> %s" % (spec, s))
self.assertEquals(s.getName(), "My:Lakeshore1")
self.assertEquals(s.getCompletion(), False)
self.assertEquals(s.getReadback(), None)

spec = "+p-c+r My:Lakeshore1"
s = settings.parseDeviceSettings(spec)
print "%s -> %s" % (spec, s)
print("%s -> %s" % (spec, s))
self.assertEquals(s.getName(), "My:Lakeshore1")
self.assertEquals(s.getCompletion(), False)
self.assertEquals(s.getReadback(), "My:Lakeshore1")
self.assertEquals(s.getParallel(), True)

spec = "+pr My:Lakeshore1"
s = settings.parseDeviceSettings(spec)
print "%s -> %s" % (spec, s)
print("%s -> %s" % (spec, s))
self.assertEquals(s.getName(), "My:Lakeshore1")
self.assertEquals(s.getReadback(), "My:Lakeshore1")
self.assertEquals(s.getParallel(), True)

spec = "+p-cr My:Motor:47"
s = settings.parseDeviceSettings(spec)
print "%s -> %s" % (spec, s)
print("%s -> %s" % (spec, s))
self.assertEquals(s.getName(), "My:Motor:47")
self.assertEquals(s.getCompletion(), False)
self.assertEquals(s.getReadback(), None)
Expand Down
5 changes: 3 additions & 2 deletions Test/test_spreadsheet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import unittest
import os
from scan.util.spreadsheet import readSpreadsheet, writeSpreadsheet
Expand All @@ -11,7 +12,7 @@ def testSpreadsheet(self):
writeSpreadsheet(filename, table)

table2 = readSpreadsheet(filename)
print table2
print(table2)
self.assertEqual(table, table2)

os.remove(filename)
Expand All @@ -23,7 +24,7 @@ def testTableScan(self):
table.save(filename)

table2 = loadTableScan(filename)
print table
print(table)
self.assertEqual(table.headers, table2.headers)
self.assertEqual(table.rows, table2.rows)

Expand Down
27 changes: 21 additions & 6 deletions Test/test_standalone.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
# Execute all tests that can run without any dependencies
DIRNAME=`dirname "$0"`

PYTHON="${PYTHON:-python}"

export PYTHONPATH=".."

FAILED=0
python test_range_helper.py
$PYTHON "$DIRNAME/test_range_helper.py"
if [ $? -ne 0 ]
then
FAILED=`expr $FAILED + 1`
fi

$PYTHON "$DIRNAME/test_scan_settings.py"
if [ $? -ne 0 ]
then
FAILED=`expr $FAILED + 1`
fi

$PYTHON "$DIRNAME/test_commands.py"
if [ $? -ne 0 ]
then
FAILED=`expr $FAILED + 1`
fi

python test_scan_settings.py
$PYTHON "$DIRNAME/test_table_scan.py"
if [ $? -ne 0 ]
then
FAILED=`expr $FAILED + 1`
fi

python test_commands.py
$PYTHON "$DIRNAME/test_data.py"
if [ $? -ne 0 ]
then
FAILED=`expr $FAILED + 1`
fi

python test_table_scan.py
$PYTHON -m doctest "$DIRNAME/test_ndim.txt"
if [ $? -ne 0 ]
then
FAILED=`expr $FAILED + 1`
fi

python test_data.py
$PYTHON -m doctest "$DIRNAME/test_alignment.py"
if [ $? -ne 0 ]
then
FAILED=`expr $FAILED + 1`
fi

python -m doctest test_ndim.txt
$PYTHON -m doctest "$DIRNAME/test_spreadsheet.py"
if [ $? -ne 0 ]
then
FAILED=`expr $FAILED + 1`
Expand Down
Loading