diff --git a/site_ansto/instrument/TEST_SICS/unit_tests/sics_test.py b/site_ansto/instrument/TEST_SICS/unit_tests/sics_test.py index 256d7bd9..78d5de5a 100644 --- a/site_ansto/instrument/TEST_SICS/unit_tests/sics_test.py +++ b/site_ansto/instrument/TEST_SICS/unit_tests/sics_test.py @@ -13,6 +13,7 @@ from twisted.trial import unittest from twisted.internet import reactor, protocol, defer import ConfigParser, StringIO +from datetime import datetime as dt class Able(unittest.TestCase): @@ -67,24 +68,35 @@ class Able(unittest.TestCase): class Baker(Able): timeout = 5 - def test_000_login(self): + def test_000_000_login(self): debug = False self.deferred = defer.Deferred() - d = self.sics.login_deferred def cb0(result, *args, **kw): if debug: 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/unit_tests/test_suite.tcl") - d.addCallback(cb1) + self.deferred.callback(None) + d = self.sics.login_deferred + d.addCallback(cb0) + return self.deferred + + def test_000_001_fileeval(self): + debug = False + self.deferred = defer.Deferred() def cb1(result, *args, **kw): if debug: print "fileeval:", result, args, kw if result[0] != "OK": raise Exception("fileeval returned " + repr(result)) - d = self.send_command("tcl:test_suite::show_config ::config_dict") - d.addCallback(cb2) + self.deferred.callback(None) + d = self.send_command("fileeval TEST_SICS/unit_tests/test_suite.tcl") + d.addCallback(cb1) + return self.deferred + + def test_001_000_config(self): + debug = False + self.deferred = defer.Deferred() def cb2(result, *args, **kw): global config if debug: @@ -108,16 +120,44 @@ class Baker(Able): for option in sorted(config.options(section)): print ("%s = %s\n" % (option, config.get(section, option))), print - d = self.load_hipadaba() - d.addCallback(cb3) + self.deferred.callback(None) + d = self.send_command("tcl:test_suite::show_config ::config_dict") + d.addCallback(cb2) + return self.deferred + + def test_001_001_clock(self): + debug = False + self.deferred = defer.Deferred() + def cb2(result, *args, **kw): + if debug: + print "Clock:", result + formatted = dt.fromtimestamp(1399866027).strftime("%Y-%b-%d %H:%M:%S") + self.assertEqual(result[0], formatted) + self.deferred.callback(None) + def cb3(result, *args, **kw): + if debug: + print "Clock:", result + if not result[0].isdigit(): + raise Exception("Bad response:" + repr(result)) + if not 1399865694 <= int(result[0]) < 1499865694: + raise Exception("Bad value:" + repr(result)) + d = self.send_command("tcl:clock format 1399866027 -format \"%Y-%h-%d %T\"") + d.addCallback(cb2) + d = self.send_command("tcl:clock seconds") + d.addCallback(cb3) + return self.deferred + + def test_001_002_hipadaba(self): + self.deferred = defer.Deferred() def cb3(result, *args, **kw): global hipadaba hipadaba = result self.deferred.callback(None) - d.addCallback(cb0) + d = self.load_hipadaba() + d.addCallback(cb3) return self.deferred - def test_001_status(self): + def test_001_003_status(self): d = self.send_command("status") def cb3(result, *args, **kw): #print "Status:", result @@ -126,7 +166,7 @@ class Baker(Able): d.addCallback(cb3) return d - def test_002_dir(self): + def Test_002_000_dir(self): raise unittest.SkipTest("Not doing this test now") self.deferred = defer.Deferred() d = self.send_command("dir types") @@ -160,7 +200,7 @@ class Baker(Able): d.addCallback(cb3) return self.deferred - def test_003_motor(self): + def test_003_000_motors(self): global motors motors = [] d = self.send_command("sicslist type motor") @@ -221,7 +261,7 @@ class Baker(Able): 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): + def Test_005_000_drive(self): """Skipping example Skips on the basis that the equipment to be tested is not configured @@ -237,7 +277,7 @@ class Baker(Able): d.addCallback(cb3) return d - def test_006_drive(self): + def test_006_000_drive(self): """Drive to where the motors already are Should finish quickly @@ -270,9 +310,9 @@ class Baker(Able): d = self.send_command("m1") d.addCallback(cb1) return self.deferred - test_006_drive.timeout = 10 + test_006_000_drive.timeout = 10 - def test_007_mercury(self): + def Test_007_000_mercury(self): raise unittest.SkipTest("Not doing this test now (borken)") global config, hipadaba debug = False @@ -287,9 +327,9 @@ class Baker(Able): return self.deferred else: raise unittest.SkipTest("mercury_scpi is not configured") - test_007_mercury.timeout = 2 + Test_007_000_mercury.timeout = 2 - def test_008_mercury_hipadaba(self): + def test_008_000_mercury_hipadaba(self): """Test the hipadaba tree and mechanism """ global hipadaba