def test_acquire(self): picture_name = "test.tiff" size = (1024, 1024) # change resolution try: # "Andor SimCam" contains a space, so cut the line ourselves cmdline = [ "cli", "--set-attr", "Camera", "resolution", "%d,%d" % size ] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) # acquire (simulated) image try: # "Andor SimCam" contains a space, so cut the line ourselves cmdline = [ "cli", "--acquire", "Camera", "--output=%s" % picture_name ] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) st = os.stat(picture_name) # this test also that the file is created self.assertGreater(st.st_size, 0) im = Image.open(picture_name) self.assertEqual(im.format, "TIFF") self.assertEqual(im.size, size)
def test_acquire(self): picture_name = "test.tiff" size = (1024, 1024) # change resolution try: # "Andor SimCam" contains a space, so cut the line ourselves cmdline = ["cli", "--set-attr", "Camera", "resolution", "%d,%d" % size] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) # acquire (simulated) image try: # "Andor SimCam" contains a space, so cut the line ourselves cmdline = ["cli", "--acquire", "Camera", "--output=%s" % picture_name] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) st = os.stat(picture_name) # this test also that the file is created self.assertGreater(st.st_size, 0) im = Image.open(picture_name) self.assertEqual(im.format, "TIFF") self.assertEqual(im.size, size)
def test_error_scan(self): try: cmdline = "cli --scan bar.foo" ret = main.main(cmdline.split()) except SystemExit as exc: # because it's handled by argparse ret = exc.code self.assertNotEqual(ret, 0, "Wrongly succeeded trying to run scan with unknown class: '%s'" % cmdline)
def test_check(self): try: cmdline = "cli --check" ret = main.main(cmdline.split()) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "Not detecting backend running")
def test_set_attr(self): # to read attribute power regex = re.compile("\spower\s.*value:\s*([.0-9]+)") # read before try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--list-prop", "Light Engine"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) output = out.getvalue() power = float(regex.search(output).group(1)) self.assertGreaterEqual(power, 0, "power should be bigger than 0") # set the new value try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--set-attr", "Light Engine", "power", "0"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) # read the new value try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--list-prop", "Light Engine"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) output = out.getvalue() power = float(regex.search(output).group(1)) self.assertEqual(power, 0, "power should be 0")
def test_error_command_line(self): """ It checks handling when wrong number of argument is given """ try: cmdline = "cli --set-attr light power" ret = main.main(cmdline.split()) except SystemExit, exc: # because it's handled by argparse ret = exc.code
def test_scan(self): try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --log-level=2 --scan" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code
def test_error_command_line(self): """ It checks handling when wrong number of argument is given """ try: cmdline = "cli --set-attr light power" ret = main.main(cmdline.split()) except SystemExit as exc: # because it's handled by argparse ret = exc.code self.assertNotEqual(ret, 0, "trying to run erroneous '%s'" % cmdline)
def test_list_prop(self): try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --list-prop Spectra" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code
def test_error_scan(self): try: cmdline = "cli --scan bar.foo" ret = main.main(cmdline.split()) except SystemExit as exc: # because it's handled by argparse ret = exc.code self.assertNotEqual( ret, 0, "Wrongly succeeded trying to run scan with unknown class: '%s'" % cmdline)
def test_set_attr_dict(self): # set a dict, which is a bit complicated structure try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --set-attr OLStage speed x:0.5,y:0.2" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code
def test_acquire(self): picture_name = "test.tiff" size = (1024, 1024) # change resolution try: # "Andor SimCam" contains a space, so use \t as delimiter cmdline = "cli\t--set-attr\tAndor SimCam\tresolution\t%d,%d" % size ret = main.main(cmdline.split("\t")) except SystemExit, exc: ret = exc.code
def test_stop(self): try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --stop" ret = main.main(cmdline.split()) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
def test_position(self): try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--position", "Sample Stage", "x", "50e-6"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
def test_move(self): # TODO compare position VA # test move and also multiple move requests try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --move OLStage x 5 --move OLStage y -0.2" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code
def test_set_attr_dict(self): # set a dict, which is a bit complicated structure try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--set-attr", "Sample Stage", "speed", "x: 0.5, y: 0.2"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
def test_set_attr_dict(self): # set a dict, which is a bit complicated structure try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--set-attr", "OLStage", "speed", "x: 0.5, y: 0.2"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
def test_reference(self): # On this simulated hardware, no component supports referencing, so # just check that referencing correctly reports this try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--reference", "Sample Stage", "x"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertNotEqual(ret, 0, "Referencing should have failed with '%s'" % cmdline)
def test_move(self): # TODO compare position VA # test move and also multiple move requests try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--move", "Sample Stage", "x", "5", "--move", "Sample Stage", "y", "-0.2"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
def test_help(self): """ It checks handling help option """ try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --help" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code
def test_reference(self): # On this simulated hardware, no component supports referencing, so # just check that referencing correctly reports this try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --reference OLStage x" ret = main.main(cmdline.split()) except SystemExit as exc: ret = exc.code self.assertNotEqual(ret, 0, "Referencing should have failed with '%s'" % cmdline)
def test_set_attr(self): # to read attribute power regex = re.compile("\spower\s.*value:\s*([.0-9]+)") # read before try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --list-prop Spectra" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code
def test_position_deg_fail(self): """converting position into degrees shouldn't be possible for axes in meters""" try: # change the stdout out = BytesIO() sys.stdout = out cmdline = [ "cli", "--position", "Sample Stage", "x", "50e-6", "--degrees" ] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertNotEqual(ret, 0, "trying to run '%s' should fail" % cmdline)
def test_reference(self): # On this simulated hardware, no component supports referencing, so # just check that referencing correctly reports this try: # change the stdout out = BytesIO() sys.stdout = out cmdline = ["cli", "--reference", "Sample Stage", "x"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertNotEqual( ret, 0, "Referencing should have failed with '%s'" % cmdline)
def test_list(self): try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --list" ret = main.main(cmdline.split()) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) output = out.getvalue() self.assertTrue("Light Engine" in output) self.assertTrue("Camera" in output)
def test_list_prop(self): try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = ["cli", "--list-prop", "Light Engine"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) output = out.getvalue() self.assertTrue("role" in output) self.assertTrue("swVersion" in output) self.assertTrue("power" in output)
def test_move(self): # TODO compare position VA # test move and also multiple move requests try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = [ "cli", "--move", "Sample Stage", "x", "5", "--move", "Sample Stage", "y", "-0.2" ] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
def test_help(self): """ It checks handling help option """ try: # change the stdout out = BytesIO() sys.stdout = out cmdline = "cli --help" ret = main.main(cmdline.split()) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s' returned %s" % (cmdline, ret)) output = out.getvalue() self.assertTrue(b"optional arguments" in output)
def test_scan(self): try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --log-level=2 --scan" ret = main.main(cmdline.split()) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s' returned %s" % (cmdline, ret)) output = out.getvalue() # AndorCam3 SimCam should be there for sure (if libandor3-dev is installed) # self.assertTrue("andorcam3.AndorCam3" in output) self.assertTrue("andorcam2.FakeAndorCam2" in output)
def test_help(self): """ It checks handling help option """ try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --help" ret = main.main(cmdline.split()) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s' returned %s" % (cmdline, ret)) output = out.getvalue() self.assertTrue("optional arguments" in output)
except SystemExit, exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) output = out.getvalue() power = float(regex.search(output).group(1)) self.assertGreaterEqual(power, 0, "power should be bigger than 0") # set the new value try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --set-attr Spectra power 0" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) # read the new value try: # change the stdout out = StringIO.StringIO() sys.stdout = out cmdline = "cli --list-prop Spectra" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
def test_check(self): try: cmdline = "cli --check" ret = main.main(cmdline.split()) except SystemExit, exc: ret = exc.code
def test_error_scan(self): try: cmdline = "cli --scan bar.foo" ret = main.main(cmdline.split()) except SystemExit, exc: # because it's handled by argparse ret = exc.code
def test_set_attr(self): # to read attribute power (which is a list of numbers) regex = re.compile(b"\spower.+ value: \[(.*?)\]") # read before try: # change the stdout out = BytesIO() sys.stdout = out cmdline = ["cli", "--list-prop", "Light Engine"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) output = out.getvalue() # Parse each individual power value from the power list power_val_str = [ val_str for val_str in str(regex.search(output).group(1)).split(",") ] power = [ float(re.search(r"([.0-9]+)", val).group(0)) for val in power_val_str ] self.assertTrue(any(pw >= 0 for pw in power), "Power values should be bigger than 0") # set the new value try: # change the stdout out = BytesIO() sys.stdout = out cmdline = [ "cli", "--set-attr", "Light Engine", "power", str([0.0 for _ in power]) ] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) # read the new value try: # change the stdout out = BytesIO() sys.stdout = out cmdline = ["cli", "--list-prop", "Light Engine"] ret = main.main(cmdline) except SystemExit as exc: ret = exc.code self.assertEqual(ret, 0, "trying to run '%s'" % cmdline) output = out.getvalue() power_val_str = [ val_str for val_str in str(regex.search(output).group(1)).split(",") ] power = [ float(re.search(r"([.0-9]+)", val).group(0)) for val in power_val_str ] self.assertTrue(all(pw == 0 for pw in power), "Power values should be 0")