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 dbe8de31..45c8069b 100644 --- a/site_ansto/instrument/TEST_SICS/unit_tests/sics_test.py +++ b/site_ansto/instrument/TEST_SICS/unit_tests/sics_test.py @@ -26,7 +26,10 @@ class Able(unittest.TestCase): def cb_login(client, *args, **kw): if debug: print "cb_login:", client, args, kw - if 'test_suite' not in globals(): + if 'instrument_name' not in globals(): + d = self.get_instrument_name() + d.addCallback(cb_login, "Test_Suite") + elif 'test_suite' not in globals(): d = self.load_test_suite() d.addCallback(cb_login, "Test_Suite") elif 'sicsconfig' not in globals(): @@ -55,6 +58,20 @@ class Able(unittest.TestCase): #print "Command:", command, d return d + def get_instrument_name(self): + debug = False + def cb1(result, *args, **kw): + global instrument_name + if debug: + print "instrument:", result, args, kw + self.assertTrue(result[0].lower().startswith("instrument = ")) + instrument_name = result[0].split("=")[1].strip().lower() + if debug: + print "Instrument:", instrument_name + d = self.send_command("instrument") + d.addCallback(cb1) + return d + def load_test_suite(self): debug = False def cb1(result, *args, **kw): @@ -232,7 +249,7 @@ class Baker(Able): for m in ["m1", "m2", "s1", "s2", "a1", "a2"]: if m not in motors: missing.append(m) - if len(missing) > 0: + if instrument_name == "taipan" and len(missing) > 0: raise Exception("Missing motors:" + repr(missing)) d.addCallback(cb3) return d @@ -336,6 +353,9 @@ class Baker(Able): Should finish quickly """ + if instrument_name != "taipan": + raise unittest.SkipTest("Cannot drive motor m1, m2: not taipan") + self.deferred = defer.Deferred() def cb3(result, *args, **kw): #print "Drive:", result @@ -371,6 +391,9 @@ class Baker(Able): Should finish quickly """ + if instrument_name != "taipan": + raise unittest.SkipTest("Cannot drive motor m1, m2: not taipan") + self.deferred = defer.Deferred() def cb3(result, *args, **kw): #print "Drive:", result @@ -481,10 +504,13 @@ class Baker(Able): for line in text: print line -class Charlie(Able): +class Posit(Able): timeout = 5 def test_000_000_posit(self): debug = True + if instrument_name != "taipan": + raise unittest.SkipTest("Cannot posit motor m1, m2: not taipan") + def cb(result, *args, **kw): if debug: print "\nposit:", result, args, kw @@ -526,9 +552,12 @@ class Charlie(Able): d.addCallback(cb, 1) return self.deferred +class Python(Able): + timeout = 5 def test_001_000_python(self): - debug = True + debug = False def cb(result, *args, **kw): + global python_installed if debug: print "\npython:", result, args, kw phase = args[0] @@ -536,12 +565,27 @@ class Charlie(Able): target += 1 if phase == target: if result[0].startswith("python=obj, type=python,"): - d = self.send_command("python sics.puts(\"Hello Sailor\")") - d.addCallback(cb, phase + 1) + python_installed = True else: - raise unittest.SkipTest("Python is not configured") - return + python_installed = False + self.deferred.callback(True) + self.deferred = defer.Deferred(); + d = self.send_command("sicslist python") + d.addCallback(cb, 1) + return self.deferred + + def test_002_000_python(self): + debug = False + if debug: + print "Python_Installed:", python_installed + if not python_installed: + raise unittest.SkipTest("Python is not installed") + def cb(result, *args, **kw): + if debug: + print "\npython:", result, args, kw + phase = args[0] + target = 0 target += 1 if phase == target: if result[0].startswith("Hello Sailor"): @@ -555,7 +599,7 @@ class Charlie(Able): self.deferred.callback(True) self.deferred = defer.Deferred(); - d = self.send_command("sicslist python") + d = self.send_command("python sics.puts(\"Hello Sailor\")") d.addCallback(cb, 1) return self.deferred