Updated SICS unit test infrastructure and test tests
This commit is contained in:
@@ -42,7 +42,7 @@ class Able(unittest.TestCase):
|
||||
|
||||
def load_hipadaba(self):
|
||||
def cb0(result, *args, **kw):
|
||||
with open("junksh.xml", "w") as outfile:
|
||||
with open("hipadaba.xml", "w") as outfile:
|
||||
for line in result:
|
||||
outfile.write(line + '\n')
|
||||
if result[0][0] != '<':
|
||||
@@ -52,7 +52,7 @@ class Able(unittest.TestCase):
|
||||
self.hipadaba = HipadabaTree('\n'.join(result))
|
||||
self.tree_deferred.callback(self.hipadaba)
|
||||
self.tree_deferred = defer.Deferred()
|
||||
d = self.send_command("getgumtreexml /")
|
||||
d = self.send_command("tcl:test_suite::getsicsxml /")
|
||||
d.addCallback(cb0)
|
||||
return self.tree_deferred
|
||||
|
||||
@@ -76,7 +76,7 @@ class Baker(Able):
|
||||
print "Login:", result, args, kw
|
||||
if self.sics.login != 2:
|
||||
raise Exception("Bad login:" + repr(self.sics.login))
|
||||
d = self.send_command("fileeval TEST_SICS/test_suite.tcl")
|
||||
d = self.send_command("fileeval TEST_SICS/unit_tests/test_suite.tcl")
|
||||
d.addCallback(cb1)
|
||||
def cb1(result, *args, **kw):
|
||||
if debug:
|
||||
@@ -177,13 +177,13 @@ class Baker(Able):
|
||||
d.addCallback(cb3)
|
||||
return d
|
||||
|
||||
def test_004_000_xml(self):
|
||||
def test_004_000_gumtreexml(self):
|
||||
#raise unittest.SkipTest("Not doing this test now")
|
||||
d = self.send_command("getgumtreexml /")
|
||||
def cb3(result, *args, **kw):
|
||||
global root
|
||||
global gumtreexml
|
||||
#print "XML:", len(result)
|
||||
with open("junk.xml", "w") as outfile:
|
||||
with open("gumtree.xml", "w") as outfile:
|
||||
for line in result:
|
||||
outfile.write(line + '\n')
|
||||
if "</hipadaba:SICS>" != result[-1]:
|
||||
@@ -191,31 +191,41 @@ class Baker(Able):
|
||||
txt = []
|
||||
for line in result:
|
||||
txt.append(''.join(c for c in line if ord(c) >= 32))
|
||||
root = HipadabaTree('\n'.join(txt)).root
|
||||
gumtreexml = HipadabaTree('\n'.join(txt)).root
|
||||
d.addCallback(cb3)
|
||||
return d
|
||||
|
||||
def test_004_001_xml(self):
|
||||
print
|
||||
print "Root:", root, root.attrib
|
||||
for child in root.findall('component'):
|
||||
print child, child.tag, child.attrib
|
||||
def test_004_001_gumtreexml(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_004_002_xml(self):
|
||||
print
|
||||
child = root
|
||||
def test_004_002_gumtreexml(self):
|
||||
child = gumtreexml
|
||||
for node in "/sample/ps9/".strip('/').split('/'):
|
||||
children = [ch for ch in child.findall('component') if ch.attrib['id'].lower() == node.lower()]
|
||||
print children
|
||||
self.assertTrue(len(children) > 0)
|
||||
child = children[0]
|
||||
print child
|
||||
print child.attrib
|
||||
print [ch.attrib['id'] for ch in child.findall('component')]
|
||||
print [(ch.attrib['id'], [v.text for v in ch.findall('value')]) for ch in child.findall('property')]
|
||||
self.assertTrue(len(child.attrib) > 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)
|
||||
|
||||
def test_005_drive(self):
|
||||
"""Skipping example
|
||||
|
||||
Skips on the basis that the equipment to be tested is not configured
|
||||
"""
|
||||
global motors
|
||||
if not "ds9" in motors:
|
||||
raise unittest.SkipTest("Cannot drive motor ds9: does not exist")
|
||||
@@ -228,13 +238,39 @@ class Baker(Able):
|
||||
return d
|
||||
|
||||
def test_006_drive(self):
|
||||
d = self.send_command("drive m1 20 m2 20 ")
|
||||
"""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]))
|
||||
d.addCallback(cb3)
|
||||
return d
|
||||
for item in result:
|
||||
if item.startswith("New m1 position:"):
|
||||
self.assertTrue(round(float(item.split(":")[1]) - self.m1, 3) == 0)
|
||||
if item.startswith("New m2 position:"):
|
||||
self.assertTrue(round(float(item.split(":")[1]) - self.m2, 3) == 0)
|
||||
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])
|
||||
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_drive.timeout = 10
|
||||
|
||||
def test_007_mercury(self):
|
||||
raise unittest.SkipTest("Not doing this test now (borken)")
|
||||
@@ -254,7 +290,8 @@ class Baker(Able):
|
||||
test_007_mercury.timeout = 2
|
||||
|
||||
def test_008_mercury_hipadaba(self):
|
||||
raise unittest.SkipTest("Not doing this test now (borken)")
|
||||
"""Test the hipadaba tree and mechanism
|
||||
"""
|
||||
global hipadaba
|
||||
debug = False
|
||||
if hipadaba is None:
|
||||
@@ -299,9 +336,10 @@ class Baker(Able):
|
||||
if debug:
|
||||
hipadaba.print_tree(y)
|
||||
text = hipadaba.list_tree(y, props=True, indent=6)
|
||||
print
|
||||
for line in text:
|
||||
print line
|
||||
if debug:
|
||||
print "Tree (/sample/tc9/level/helium):"
|
||||
for line in text:
|
||||
print line
|
||||
|
||||
class Zulu(Able):
|
||||
def test_performance(self):
|
||||
|
||||
Reference in New Issue
Block a user