Update tests to include drive_one and getgumtreexmlvalues
This commit is contained in:
@@ -252,6 +252,9 @@ class Baker(Able):
|
|||||||
self.assertTrue('control' in id_list)
|
self.assertTrue('control' in id_list)
|
||||||
|
|
||||||
def test_004_002_gumtreexml(self):
|
def test_004_002_gumtreexml(self):
|
||||||
|
global config, hipadaba
|
||||||
|
if not ('pfeiffer_hg' in config.sections() and config.get("pfeiffer_hg", "enabled") == "True"):
|
||||||
|
raise unittest.SkipTest("Pfeiffer PS9 is not configured")
|
||||||
child = gumtreexml
|
child = gumtreexml
|
||||||
for node in "/sample/ps9/".strip('/').split('/'):
|
for node in "/sample/ps9/".strip('/').split('/'):
|
||||||
children = [ch for ch in child.findall('component') if ch.attrib['id'].lower() == node.lower()]
|
children = [ch for ch in child.findall('component') if ch.attrib['id'].lower() == node.lower()]
|
||||||
@@ -261,7 +264,38 @@ class Baker(Able):
|
|||||||
self.assertTrue(len([ch.attrib['id'] for ch in child.findall('component')]) > 0)
|
self.assertTrue(len([ch.attrib['id'] for ch in child.findall('component')]) > 0)
|
||||||
self.assertTrue(len([(ch.attrib['id'], [v.text for v in ch.findall('value')]) for ch in child.findall('property')]) > 0)
|
self.assertTrue(len([(ch.attrib['id'], [v.text for v in ch.findall('value')]) for ch in child.findall('property')]) > 0)
|
||||||
|
|
||||||
def Test_005_000_drive(self):
|
def test_004_003_gumtreexmlvalues(self):
|
||||||
|
#raise unittest.SkipTest("Not doing this test now")
|
||||||
|
d = self.send_command("getgumtreexmlvalues /")
|
||||||
|
def cb3(result, *args, **kw):
|
||||||
|
global gumtreexml
|
||||||
|
#print "XML:", len(result)
|
||||||
|
if "</hipadaba:SICS>" != result[-1]:
|
||||||
|
raise Exception("XML is not complete, ends:" + repr(result[-1]))
|
||||||
|
txt = []
|
||||||
|
for line in result:
|
||||||
|
txt.append(''.join(c for c in line if ord(c) >= 32))
|
||||||
|
gumtreexml = HipadabaTree('\n'.join(txt)).root
|
||||||
|
d.addCallback(cb3)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def test_004_004_gumtreexmlvalues(self):
|
||||||
|
self.assertTrue(gumtreexml.attrib == {})
|
||||||
|
id_list = []
|
||||||
|
for child in gumtreexml.findall('component'):
|
||||||
|
id_list.append(child.attrib['id'])
|
||||||
|
#print child, child.tag, child.attrib
|
||||||
|
#for grandchild in child.findall('component'):
|
||||||
|
# print " ", grandchild.attrib
|
||||||
|
self.assertTrue('commands' in id_list)
|
||||||
|
self.assertTrue('instrument' in id_list)
|
||||||
|
self.assertTrue('sample' in id_list)
|
||||||
|
self.assertTrue('monitor' in id_list)
|
||||||
|
self.assertTrue('user' in id_list)
|
||||||
|
self.assertTrue('experiment' in id_list)
|
||||||
|
self.assertTrue('control' in id_list)
|
||||||
|
|
||||||
|
def Test_005_000_drive_skip(self):
|
||||||
"""Skipping example
|
"""Skipping example
|
||||||
|
|
||||||
Skips on the basis that the equipment to be tested is not configured
|
Skips on the basis that the equipment to be tested is not configured
|
||||||
@@ -277,7 +311,7 @@ class Baker(Able):
|
|||||||
d.addCallback(cb3)
|
d.addCallback(cb3)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def test_006_000_drive(self):
|
def test_006_000_drive_zero(self):
|
||||||
"""Drive to where the motors already are
|
"""Drive to where the motors already are
|
||||||
|
|
||||||
Should finish quickly
|
Should finish quickly
|
||||||
@@ -310,7 +344,52 @@ class Baker(Able):
|
|||||||
d = self.send_command("m1")
|
d = self.send_command("m1")
|
||||||
d.addCallback(cb1)
|
d.addCallback(cb1)
|
||||||
return self.deferred
|
return self.deferred
|
||||||
test_006_000_drive.timeout = 10
|
test_006_000_drive_zero.timeout = 5
|
||||||
|
|
||||||
|
def test_006_001_drive_one(self):
|
||||||
|
"""Drive to where the motors already are
|
||||||
|
|
||||||
|
Should finish quickly
|
||||||
|
"""
|
||||||
|
self.deferred = defer.Deferred()
|
||||||
|
def cb3(result, *args, **kw):
|
||||||
|
#print "Drive:", result
|
||||||
|
if "Driving finished successfully" != result[-1]:
|
||||||
|
raise Exception("Drive is not complete, ends:" + repr(result[-1]))
|
||||||
|
for item in result:
|
||||||
|
if item.startswith("New m1 position:"):
|
||||||
|
self.assertTrue(round(float(item.split(":")[1]) - self.m1, 2) == 0,
|
||||||
|
"Motor m1 position %f not equal target %f" % (float(item.split(":")[1]), self.m1))
|
||||||
|
if item.startswith("New m2 position:"):
|
||||||
|
self.assertTrue(round(float(item.split(":")[1]) - self.m2, 2) == 0,
|
||||||
|
"Motor m2 position %f not equal target %f" % (float(item.split(":")[1]), self.m2))
|
||||||
|
self.deferred.callback(True)
|
||||||
|
def cb2(result, *args, **kw):
|
||||||
|
#print "m2:", result
|
||||||
|
if not result[0].startswith("m2 = "):
|
||||||
|
raise Exception("Unexpected m2 response: " + repr(result))
|
||||||
|
self.m2 = float(result[0].split("=")[1])
|
||||||
|
if self.m1 > 20:
|
||||||
|
self.m1 = round(self.m1 - 1, 0)
|
||||||
|
else:
|
||||||
|
self.m1 = round(self.m1 + 1, 0)
|
||||||
|
if self.m2 > 20:
|
||||||
|
self.m2 = round(self.m2 - 1, 0)
|
||||||
|
else:
|
||||||
|
self.m2 = round(self.m2 + 1, 0)
|
||||||
|
d = self.send_command("drive m1 %.3f m2 %.3f" % (self.m1, self.m2))
|
||||||
|
d.addCallback(cb3)
|
||||||
|
def cb1(result, *args, **kw):
|
||||||
|
#print "m1:", result
|
||||||
|
if not result[0].startswith("m1 = "):
|
||||||
|
raise Exception("Unexpected m1 response: " + repr(result))
|
||||||
|
self.m1 = float(result[0].split("=")[1])
|
||||||
|
d = self.send_command("m2")
|
||||||
|
d.addCallback(cb2)
|
||||||
|
d = self.send_command("m1")
|
||||||
|
d.addCallback(cb1)
|
||||||
|
return self.deferred
|
||||||
|
test_006_001_drive_one.timeout = 20
|
||||||
|
|
||||||
def Test_007_000_mercury(self):
|
def Test_007_000_mercury(self):
|
||||||
raise unittest.SkipTest("Not doing this test now (borken)")
|
raise unittest.SkipTest("Not doing this test now (borken)")
|
||||||
@@ -320,13 +399,12 @@ class Baker(Able):
|
|||||||
if debug:
|
if debug:
|
||||||
print "\nMercury:", result.short_tree()
|
print "\nMercury:", result.short_tree()
|
||||||
self.deferred.callback(result)
|
self.deferred.callback(result)
|
||||||
if "mercury_scpi" in config.sections() and config.get("mercury_scpi", "enabled"):
|
if not ("mercury_scpi" in config.sections() and config.get("mercury_scpi", "enabled") == "True"):
|
||||||
self.deferred = defer.Deferred()
|
|
||||||
d = self.load_hipadaba("/sample/%s" % config.get("mercury_scpi", "name"))
|
|
||||||
d.addCallback(cb0)
|
|
||||||
return self.deferred
|
|
||||||
else:
|
|
||||||
raise unittest.SkipTest("mercury_scpi is not configured")
|
raise unittest.SkipTest("mercury_scpi is not configured")
|
||||||
|
self.deferred = defer.Deferred()
|
||||||
|
d = self.load_hipadaba("/sample/%s" % config.get("mercury_scpi", "name"))
|
||||||
|
d.addCallback(cb0)
|
||||||
|
return self.deferred
|
||||||
Test_007_000_mercury.timeout = 2
|
Test_007_000_mercury.timeout = 2
|
||||||
|
|
||||||
def test_008_000_mercury_hipadaba(self):
|
def test_008_000_mercury_hipadaba(self):
|
||||||
@@ -336,50 +414,52 @@ class Baker(Able):
|
|||||||
debug = False
|
debug = False
|
||||||
if not 'hipadaba' in globals() or hipadaba is None:
|
if not 'hipadaba' in globals() or hipadaba is None:
|
||||||
raise unittest.SkipTest("hipadaba is missing")
|
raise unittest.SkipTest("hipadaba is missing")
|
||||||
else:
|
if not ('mercury_scpi' in config.sections() and config.get("mercury_scpi", "enabled") == "True"):
|
||||||
if False:
|
raise unittest.SkipTest("Mercury TC9 is not configured")
|
||||||
hipadaba.print_tree()
|
|
||||||
root_children = hipadaba.getChildren('/')
|
if False:
|
||||||
if debug:
|
hipadaba.print_tree()
|
||||||
print "Children:", root_children
|
root_children = hipadaba.getChildren('/')
|
||||||
root_children = [i.lower() for i in root_children]
|
if debug:
|
||||||
self.assertTrue('sample' in root_children)
|
print "Children:", root_children
|
||||||
sample_children = hipadaba.getChildren('/sample')
|
root_children = [i.lower() for i in root_children]
|
||||||
if debug:
|
self.assertTrue('sample' in root_children)
|
||||||
print "Children:", sample_children
|
sample_children = hipadaba.getChildren('/sample')
|
||||||
sample_children = [i.lower() for i in sample_children]
|
if debug:
|
||||||
self.assertTrue('tc9' in sample_children)
|
print "Children:", sample_children
|
||||||
level_children = hipadaba.getChildren('/sample/tc9/level/')
|
sample_children = [i.lower() for i in sample_children]
|
||||||
if debug:
|
self.assertTrue('tc9' in sample_children)
|
||||||
print "Children:", level_children
|
level_children = hipadaba.getChildren('/sample/tc9/level/')
|
||||||
level_children = [i.lower() for i in level_children]
|
if debug:
|
||||||
self.assertTrue('helium' in level_children)
|
print "Children:", level_children
|
||||||
self.assertTrue('nitrogen' in level_children)
|
level_children = [i.lower() for i in level_children]
|
||||||
he_props = hipadaba.getProperties('/sample/tc9/level/helium')
|
self.assertTrue('helium' in level_children)
|
||||||
if debug:
|
self.assertTrue('nitrogen' in level_children)
|
||||||
print "Properties:", he_props
|
he_props = hipadaba.getProperties('/sample/tc9/level/helium')
|
||||||
he_props = [i.lower() for i in he_props]
|
if debug:
|
||||||
self.assertTrue('data' in he_props)
|
print "Properties:", he_props
|
||||||
self.assertTrue('control' in he_props)
|
he_props = [i.lower() for i in he_props]
|
||||||
self.assertTrue('nxsave' in he_props)
|
self.assertTrue('data' in he_props)
|
||||||
self.assertTrue('nxalias' in he_props)
|
self.assertTrue('control' in he_props)
|
||||||
nxalias = hipadaba.getProperty('/sample/tc9/level/helium', 'NXalias')
|
self.assertTrue('nxsave' in he_props)
|
||||||
if debug:
|
self.assertTrue('nxalias' in he_props)
|
||||||
print "Prop:", nxalias
|
nxalias = hipadaba.getProperty('/sample/tc9/level/helium', 'NXalias')
|
||||||
self.assertTrue(nxalias.lower() == 'tc9_level_helium'.lower())
|
if debug:
|
||||||
y = hipadaba.getValue('/sample/tc9/Level/helium')
|
print "Prop:", nxalias
|
||||||
if debug:
|
self.assertTrue(nxalias.lower() == 'tc9_level_helium'.lower())
|
||||||
print "Value:", y
|
y = hipadaba.getValue('/sample/tc9/Level/helium')
|
||||||
y = hipadaba.getNode('/sample/tc9/level/helium')
|
if debug:
|
||||||
if debug:
|
print "Value:", y
|
||||||
print "Found:", hipadaba.short_tree(y)
|
y = hipadaba.getNode('/sample/tc9/level/helium')
|
||||||
if debug:
|
if debug:
|
||||||
hipadaba.print_tree(y)
|
print "Found:", hipadaba.short_tree(y)
|
||||||
text = hipadaba.list_tree(y, props=True, indent=6)
|
if debug:
|
||||||
if debug:
|
hipadaba.print_tree(y)
|
||||||
print "Tree (/sample/tc9/level/helium):"
|
text = hipadaba.list_tree(y, props=True, indent=6)
|
||||||
for line in text:
|
if debug:
|
||||||
print line
|
print "Tree (/sample/tc9/level/helium):"
|
||||||
|
for line in text:
|
||||||
|
print line
|
||||||
|
|
||||||
class Zulu(Able):
|
class Zulu(Able):
|
||||||
def test_performance(self):
|
def test_performance(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user