Пример #1
0
    def test_daemon(self):
        # First there should be not backend running
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")

        # run the backend as a daemon
        # we cannot run it normally as the child would also think he's in a unittest
        cmdline = "--log-level=2 --log-target=testdaemon.log --daemonize %s" % SIM_CONFIG
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(1) # give some time to start

        # now it should say it's starting, and eventually running
        ret = self._wait_backend_starts(5)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # stop the backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(5) # give some time to stop

        # backend should be stopped by now
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Back-end not stopped: ret = %d" % ret)

        os.remove("test.log")
        os.remove("testdaemon.log")
Пример #2
0
    def test_properties_set(self):
        """Test creating component with specific properties"""
        filename = "example-secom.odm.yaml"
        cmdline = "--log-level=2 --log-target=testdaemon.log --daemonize %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        # eventually it should say it's running
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check that the specific properties are set
        ccd = model.getComponent(role="ccd")
        self.assertEqual(ccd.exposureTime.value, 0.3)

        ebeam = model.getComponent(role="e-beam")
        self.assertEqual(ebeam.horizontalFoV.value, 1e-6)

        # stop the backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(5) # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("testdaemon.log")
Пример #3
0
    def test_daemon(self):
        # First there should be not backend running
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")

        # run the backend as a daemon
        # we cannot run it normally as the child would also think he's in a unittest
        cmdline = "--log-level=2 --log-target=testdaemon.log --daemonize %s" % SIM_CONFIG
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(1) # give some time to start

        # now it should say it's starting, and eventually running
        ret = self._wait_backend_starts(5)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # stop the backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(5) # give some time to stop

        # backend should be stopped by now
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Back-end not stopped: ret = %d" % ret)

        os.remove("test.log")
        os.remove("testdaemon.log")
Пример #4
0
    def test_properties_set(self):
        """Test creating component with specific properties"""
        filename = "example-secom.odm.yaml"
        cmdline = "--log-level=2 --log-target=testdaemon.log --daemonize %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        # eventually it should say it's running
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check that the specific properties are set
        ccd = model.getComponent(role="ccd")
        self.assertEqual(ccd.exposureTime.value, 0.3)

        ebeam = model.getComponent(role="e-beam")
        self.assertEqual(ebeam.horizontalFoV.value, 1e-6)

        # stop the backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(5) # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("testdaemon.log")
Пример #5
0
 def test_error_instantiate(self):
     """Test config files which should fail on instantiation"""
     # Only for the config files that cannot fail on a standard validation
     filename = "semantic-error-3.odm.yaml"
     cmdline = "odemisd --log-target=test.log %s" % filename
     ret = main.main(cmdline.split())
     if ret == 0:
         # We also need to stop the backend then
         cmdline = "odemisd --kill"
         ret = main.main(cmdline.split())
         self.fail("no error detected in erroneous config file '%s'" % filename)
     os.remove("test.log")
Пример #6
0
 def test_validate_pass(self):
     cmdline = "odemisd --log-level=2 --log-target=test.log --validate %s" % filename
     ret = main.main(cmdline.split())
     self.assertEqual(
         ret, 0, "error detected in correct config "
         "file '%s'" % filename)
     os.remove("test.log")
Пример #7
0
 def test_validate_error(self):
     logging.info("testing run with %s (should fail)", filename)
     cmdline = "odemisd --log-level=2 --log-target=test.log --validate %s" % filename
     ret = main.main(cmdline.split())
     self.assertNotEqual(ret, 0, "no error detected in erroneous config "
                                 "file '%s'" % filename)
     os.remove("test.log")
Пример #8
0
 def test_validate_pass(self):
     logging.info("testing run with %s (should succeed)", filename)
     cmdline = "odemisd --log-level=2 --log-target=test.log --validate %s" % filename
     ret = main.main(cmdline.split())
     self.assertEqual(ret, 0, "error detected in correct config "
                              "file '%s'" % filename)
     os.remove("test.log")
Пример #9
0
 def test_validate_pass(self):
     logging.info("testing run with %s (should succeed)", filename)
     cmdline = "odemisd --log-level=2 --log-target=test.log --validate %s" % filename
     ret = main.main(cmdline.split())
     self.assertEqual(ret, 0, "error detected in correct config "
                              "file '%s'" % filename)
     os.remove("test.log")
Пример #10
0
 def test_validate_error(self):
     logging.info("testing run with %s (should fail)", filename)
     cmdline = "odemisd --log-level=2 --log-target=test.log --validate %s" % filename
     ret = main.main(cmdline.split())
     self.assertNotEqual(ret, 0, "no error detected in erroneous config "
                                 "file '%s'" % filename)
     os.remove("test.log")
Пример #11
0
    def test_error_instantiate(self):
        """Test config files which should fail on instantiation"""
        # Only for the config files that cannot fail on a standard validation
        filename = "semantic-error-3.odm.yaml"
        cmdline = "odemisd --log-target=test.log %s" % filename
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        # now it should say it's starting, and eventually failed
        ret = self._wait_backend_starts(5)
        if ret == 0:
            # We also need to stop the backend then
            cmdline = "odemisd --kill"
            ret = main.main(cmdline.split())
            self.fail("no error detected in erroneous config file '%s'" % filename)

        os.remove("test.log")
Пример #12
0
    def test_error_instantiate(self):
        """Test config files which should fail on instantiation"""
        # Only for the config files that cannot fail on a standard validation
        filename = "semantic-error-3.odm.yaml"
        cmdline = "odemisd --log-target=test.log %s" % filename
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        # now it should say it's starting, and eventually failed
        ret = self._wait_backend_starts(5)
        if ret == 0:
            # We also need to stop the backend then
            cmdline = "odemisd --kill"
            ret = main.main(cmdline.split())
            self.fail("no error detected in erroneous config file '%s'" % filename)

        os.remove("test.log")
Пример #13
0
    def test_log(self):
        cmdline = "odemisd --log-level=2 --log-target=test.log --validate %s" % SIM_CONFIG
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        # a log file?
        st = os.stat("test.log") # this tests also that the file is created
        self.assertGreater(st.st_size, 0)
        os.remove("test.log")
Пример #14
0
 def test_error_command_line(self):
     """
     It checks handling when no config file is provided
     """
     try:
         cmdline = "odemisd --validate"
         ret = main.main(cmdline.split())
     except SystemExit, exc: # because it's handled by argparse
         ret = exc.code
Пример #15
0
    def test_log(self):
        cmdline = "odemisd --log-level=2 --log-target=test.log --validate %s" % SIM_CONFIG
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        # a log file?
        st = os.stat("test.log") # this tests also that the file is created
        self.assertGreater(st.st_size, 0)
        os.remove("test.log")
Пример #16
0
 def test_error_command_line(self):
     """
     It checks handling when no config file is provided
     """
     try:
         cmdline = "odemisd --validate"
         ret = main.main(cmdline.split())
     except SystemExit, exc:  # because it's handled by argparse
         ret = exc.code
Пример #17
0
 def test_error_command_line(self):
     """
     It checks handling when no config file is provided
     """
     try:
         cmdline = "odemisd --validate"
         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)
Пример #18
0
 def test_error_command_line(self):
     """
     It checks handling when no config file is provided
     """
     try:
         cmdline = "odemisd --validate"
         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)
Пример #19
0
    def test_multiple_parents_new(self):
        """Test creating component with multiple parents"""
        filename = "multiple-parents-new-style.odm.yaml"
        cmdline = "--log-level=2 --log-target=testdaemon.log --daemonize %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s' gave status %d" % (cmdline, ret))

        # eventually it should say it's running
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # stop the backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(5) # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("testdaemon.log")
Пример #20
0
    def test_multiple_parents(self):
        """Test creating component with multiple parents"""
        filename = "multiple-parents.odm.yaml"
        cmdline = "--log-level=2 --log-target=testdaemon.log --daemonize %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s' gave status %d" % (cmdline, ret))

        # eventually it should say it's running
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # stop the backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(5) # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("testdaemon.log")
Пример #21
0
    def test_multiple_parents(self):
        """Test creating component with multiple parents"""
        filename = "multiple-parents.odm.yaml"
        cmdline = ODEMISD_CMD + " --log-level=2 --log-target=testdaemon.log --daemonize %s" % filename
        ret = subprocess.call(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        # now it should say it's running
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "command '%s' returned %d" % (cmdline, ret))

        # stop the backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)

        time.sleep(5)  # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("testdaemon.log")
Пример #22
0
    def test_help(self):
        """
        It checks handling help option
        """
        try:
            # change the stdout
            out = StringIO.StringIO()
            sys.stdout = out

            cmdline = "odemisd --help"
            ret = main.main(cmdline.split())
        except SystemExit, exc:
            ret = exc.code
Пример #23
0
    def test_help(self):
        """
        It checks handling help option
        """
        try:
            # change the stdout
            out = StringIO.StringIO()
            sys.stdout = out

            cmdline = "odemisd --help"
            ret = main.main(cmdline.split())
        except SystemExit, exc:
            ret = exc.code
Пример #24
0
    def test_no_persistent(self):
        """Test initialization with persistent data but without a settings file"""
        # Start backend without any settings file defined. As it's not running
        # as root, it will run without persistent data stored.
        # => just show warnings in the log file, and runs fine.
        filename = "sim-persistent.odm.yaml"
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        cmdline = "--log-level=2 --log-target=test.log --daemonize %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Restart backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        main.main(cmdline.split())
        time.sleep(5)
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        os.remove("test.log")
Пример #25
0
    def test_no_persistent(self):
        """Test initialization with persistent data but without a settings file"""
        # Start backend without any settings file defined. As it's not running
        # as root, it will run without persistent data stored.
        # => just show warnings in the log file, and runs fine.
        filename = "sim-persistent.odm.yaml"
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        cmdline = "--log-level=2 --log-target=test.log --daemonize %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Restart backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        main.main(cmdline.split())
        time.sleep(5)
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        os.remove("test.log")
Пример #26
0
    def test_help(self):
        """
        It checks handling help option
        """
        try:
            # change the stdout
            out = StringIO.StringIO()
            sys.stdout = out

            cmdline = "odemisd --help"
            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("positional arguments" in output)
Пример #27
0
    def test_help(self):
        """
        It checks handling help option
        """
        try:
            # change the stdout
            out = StringIO.StringIO()
            sys.stdout = out

            cmdline = "odemisd --help"
            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("positional arguments" in output)
Пример #28
0
    def _wait_backend_starts(self, timeout=5):
        """
        Wait until the backend status is different from "STARTING" (3)
        timeout (0<float): maximum time to wait
        return (int): the new status
        """
        time.sleep(1)
        end = time.time() + timeout
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        while time.time() < end:
            ret = main.main(cmdline.split())
            if ret == 3:
                logging.info("Backend is starting...")
                time.sleep(1)
            else:
                break
        else:
            self.fail("Backend still in starting status after %g s" % timeout)

        return ret
Пример #29
0
    def _wait_backend_starts(self, timeout=5):
        """
        Wait until the backend status is different from "STARTING" (3)
        timeout (0<float): maximum time to wait
        return (int): the new status
        """
        time.sleep(1)
        end = time.time() + timeout
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        while time.time() < end:
            ret = main.main(cmdline.split())
            if ret == 3:
                logging.info("Backend is starting...")
                time.sleep(1)
            else:
                break
        else:
            self.fail("Backend still in starting status after %g s" % timeout)

        return ret
Пример #30
0
    def test_persistent_data_broken_file(self):
        """Test initialization with persistent data with a broken file"""

        # Create broken settings file
        broken_data = {}
        broken_data['non_existing_comp'] = {'properties': {'exposureTime': 5}}
        broken_data['Andor SimCam'] = {'properties': {'not_a_property': 10}}
        broken_data['Andor SimCam'] = {'unknown_type': {'': 10}}
        broken_data[''] = {'properties': {'not_a_property': 10}}

        with open("test-settings-broken.yaml", "w+") as f:
            yaml.dump(broken_data, f)

        # Same test as before, should still work with other persistent data
        # The broken data should be ignored and a warning should be issued.

        # Start backend with persistent data specified in yaml file
        filename = "sim-persistent.odm.yaml"
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        cmdline = "--log-level=2 --log-target=test.log --daemonize --settings=test-settings-broken.yaml %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check if default properties for stage.speed are set properly
        stage = model.getComponent(role='stage')
        self.assertEqual(stage.speed.value, {'x': 0.1, 'y': 0.1})

        # New property and metadata values
        res = [512, 512]
        gain = 1.0
        expt = 3.0
        pxs = [5e-07, 5e-07]
        speed = {'x': 0.3, 'y': 0.3}

        # Change persistent data
        ccd = model.getComponent(role='ccd')
        ccd.resolution.value = res
        ccd.gain.value = gain
        ccd.exposureTime.value = expt
        ccd.updateMetadata({model.MD_SENSOR_PIXEL_SIZE: pxs})
        stage = model.getComponent(role='stage')
        stage.speed.value = speed

        # Check if persistent VAs are written to file before closing
        time.sleep(1)
        with open('test-settings-broken.yaml', 'r') as f:
            f_content = yaml.load(f)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["resolution"], res)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["gain"], gain)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["exposureTime"], expt)

        # Restart backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        main.main(cmdline.split())
        time.sleep(5)
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        cmdline = "--log-level=2 --log-target=test.log --daemonize --settings=test-settings-broken.yaml %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(5)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check values of persistent data
        ccd = model.getComponent(role="ccd")
        self.assertEqual(ccd.resolution.value, tuple(res))
        self.assertEqual(ccd.gain.value, gain)
        self.assertEqual(ccd.exposureTime.value, expt)
        self.assertEqual(ccd.getMetadata()[model.MD_SENSOR_PIXEL_SIZE], pxs)
        stage = model.getComponent(role="stage")
        self.assertEqual(stage.speed.value, speed)

        # Clean up
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(5)  # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("test-settings-broken.yaml")
Пример #31
0
    def test_persistent_data(self):
        """Test initialization with persistent data"""

        # Start backend with persistent data specified in yaml file
        filename = "sim-persistent.odm.yaml"
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        if os.path.isfile("test-settings.yaml"):
            os.remove("test-settings.yaml")
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        cmdline = "--log-level=2 --log-target=test.log --daemonize --settings=test-settings.yaml %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check if default properties for stage.speed and SimCam metadata are set
        stage = model.getComponent(role='stage')
        ccd = model.getComponent(role='ccd')
        self.assertEqual(stage.speed.value, {'x': 0.1, 'y': 0.1})
        init_pos_cor = [5.e-6, -62.1e-6]
        self.assertEqual(ccd.getMetadata()[model.MD_POS_COR], init_pos_cor)

        # New property and metadata values
        res = [512, 512]
        gain = 1.0
        expt = 3.0
        pxs = [5e-07, 5e-07]
        speed = {'x': 0.3, 'y': 0.3}
        pos_cor = (-9.e-6, -7.3e-6)  # Will be stored as a _list_

        # Change persistent data
        ccd.resolution.value = res
        ccd.gain.value = gain
        ccd.exposureTime.value = expt
        ccd.updateMetadata({model.MD_SENSOR_PIXEL_SIZE: pxs,
                            model.MD_POS_COR: pos_cor})
        stage = model.getComponent(role='stage')
        stage.speed.value = speed

        time.sleep(1)  # make sure the backend is done writing the VA values to the settings file
        # Check if persistent VAs are written to file before closing
        with open('test-settings.yaml', 'r+') as f:
            f_content = yaml.load(f)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["resolution"], res)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["gain"], gain)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["exposureTime"], expt)

        # End backend => metadata should also be saved
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        main.main(cmdline.split())
        time.sleep(5)
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")

        with open('test-settings.yaml', 'r+') as f:
            f_content = yaml.load(f)
        self.assertEqual(f_content["Andor SimCam"]["metadata"]["SENSOR_PIXEL_SIZE"], pxs)
        self.assertEqual(f_content["Andor SimCam"]["metadata"]["POS_COR"], list(pos_cor))

        # Restart backend
        logging.debug("Restarting backend...")
        cmdline = "--log-level=2 --log-target=test.log --daemonize --settings=test-settings.yaml %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(5)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check values of persistent data
        ccd = model.getComponent(role="ccd")
        self.assertEqual(ccd.resolution.value, tuple(res))
        self.assertEqual(ccd.gain.value, gain)
        self.assertEqual(ccd.exposureTime.value, expt)
        self.assertEqual(ccd.getMetadata()[model.MD_SENSOR_PIXEL_SIZE], pxs)
        self.assertEqual(ccd.getMetadata()[model.MD_POS_COR], list(pos_cor))
        stage = model.getComponent(role="stage")
        self.assertEqual(stage.speed.value, speed)

        # Clean up
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(5)  # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("test-settings.yaml")
Пример #32
0
 def test_validate_error(self):
     cmdline = "odemisd --log-target=test.log --validate %s" % filename
     ret = main.main(cmdline.split())
     self.assertNotEqual(ret, 0, "no error detected in erroneous config "
                         "file '%s'" % filename)
     os.remove("test.log")
Пример #33
0
    def test_persistent_data(self):
        """Test initialization with persistent data"""

        # Start backend with persistent data specified in yaml file
        filename = "sim-persistent.odm.yaml"
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        if os.path.isfile("test-settings.yaml"):
            os.remove("test-settings.yaml")
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        cmdline = "--log-level=2 --log-target=test.log --daemonize --settings=test-settings.yaml %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check if default properties for stage.speed and SimCam metadata are set
        stage = model.getComponent(role='stage')
        ccd = model.getComponent(role='ccd')
        self.assertEqual(stage.speed.value, {'x': 0.1, 'y': 0.1})
        init_pos_cor = [5.e-6, -62.1e-6]
        self.assertEqual(ccd.getMetadata()[model.MD_POS_COR], init_pos_cor)

        # New property and metadata values
        res = [512, 512]
        gain = 1.0
        expt = 3.0
        pxs = [5e-07, 5e-07]
        speed = {'x': 0.3, 'y': 0.3}
        pos_cor = (-9.e-6, -7.3e-6)  # Will be stored as a _list_

        # Change persistent data
        ccd.resolution.value = res
        ccd.gain.value = gain
        ccd.exposureTime.value = expt
        ccd.updateMetadata({model.MD_SENSOR_PIXEL_SIZE: pxs,
                            model.MD_POS_COR: pos_cor})
        stage = model.getComponent(role='stage')
        stage.speed.value = speed

        time.sleep(1)  # make sure the backend is done writing the VA values to the settings file
        # Check if persistent VAs are written to file before closing
        with open('test-settings.yaml', 'r+') as f:
            f_content = yaml.load(f)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["resolution"], res)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["gain"], gain)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["exposureTime"], expt)

        # End backend => metadata should also be saved
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        main.main(cmdline.split())
        time.sleep(5)
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")

        with open('test-settings.yaml', 'r+') as f:
            f_content = yaml.load(f)
        self.assertEqual(f_content["Andor SimCam"]["metadata"]["SENSOR_PIXEL_SIZE"], pxs)
        self.assertEqual(f_content["Andor SimCam"]["metadata"]["POS_COR"], list(pos_cor))

        # Restart backend
        logging.debug("Restarting backend...")
        cmdline = "--log-level=2 --log-target=test.log --daemonize --settings=test-settings.yaml %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(5)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check values of persistent data
        ccd = model.getComponent(role="ccd")
        self.assertEqual(ccd.resolution.value, tuple(res))
        self.assertEqual(ccd.gain.value, gain)
        self.assertEqual(ccd.exposureTime.value, expt)
        self.assertEqual(ccd.getMetadata()[model.MD_SENSOR_PIXEL_SIZE], pxs)
        self.assertEqual(ccd.getMetadata()[model.MD_POS_COR], list(pos_cor))
        stage = model.getComponent(role="stage")
        self.assertEqual(stage.speed.value, speed)

        # Clean up
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(5)  # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("test-settings.yaml")
Пример #34
0
    def test_persistent_data_broken_file(self):
        """Test initialization with persistent data with a broken file"""

        # Create broken settings file
        broken_data = {'non_existing_comp': {'properties': {'exposureTime': 5}},
                       'FakeRedStoneStage': {'properties': {'not_a_property': 10}},
                       'Andor SimCam': {'unknown_type': {'': 10}},
                       '': {'properties': {'not_a_property': 10}}}

        with open("test-settings-broken.yaml", "w+") as f:
            yaml.dump(broken_data, f)

        # Same test as before, should still work with other persistent data
        # The broken data should be ignored and a warning should be issued.

        # Start backend with persistent data specified in yaml file
        filename = "sim-persistent.odm.yaml"
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        cmdline = "--log-level=2 --log-target=test.log --daemonize --settings=test-settings-broken.yaml %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(10)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check if default properties for stage.speed are set properly
        stage = model.getComponent(role='stage')
        self.assertEqual(stage.speed.value, {'x': 0.1, 'y': 0.1})

        # New property and metadata values
        res = [512, 512]
        gain = 1.0
        expt = 3.0
        pxs = [5e-07, 5e-07]
        speed = {'x': 0.3, 'y': 0.3}

        # Change persistent data
        ccd = model.getComponent(role='ccd')
        ccd.resolution.value = res
        ccd.gain.value = gain
        ccd.exposureTime.value = expt
        ccd.updateMetadata({model.MD_SENSOR_PIXEL_SIZE: pxs})
        stage = model.getComponent(role='stage')
        stage.speed.value = speed

        # Check if persistent VAs are written to file before closing
        time.sleep(1)
        with open('test-settings-broken.yaml', 'r') as f:
            f_content = yaml.load(f)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["resolution"], res)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["gain"], gain)
        self.assertEqual(f_content["Andor SimCam"]["properties"]["exposureTime"], expt)

        # Restart backend
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        main.main(cmdline.split())
        time.sleep(5)
        cmdline = "odemisd --log-level=2 --log-target=test.log --check"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 2, "Backend is said to be running")
        cmdline = "--log-level=2 --log-target=test.log --daemonize --settings=test-settings-broken.yaml %s" % filename
        ret = subprocess.call(ODEMISD_CMD + cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(1)  # give some time to start
        ret = self._wait_backend_starts(5)
        self.assertEqual(ret, 0, "backend status check returned %d" % (ret,))

        # Check values of persistent data
        ccd = model.getComponent(role="ccd")
        self.assertEqual(ccd.resolution.value, tuple(res))
        self.assertEqual(ccd.gain.value, gain)
        self.assertEqual(ccd.exposureTime.value, expt)
        self.assertEqual(ccd.getMetadata()[model.MD_SENSOR_PIXEL_SIZE], pxs)
        stage = model.getComponent(role="stage")
        self.assertEqual(stage.speed.value, speed)

        # Clean up
        cmdline = "odemisd --log-level=2 --log-target=test.log --kill"
        ret = main.main(cmdline.split())
        self.assertEqual(ret, 0, "trying to run '%s'" % cmdline)
        time.sleep(5)  # give some time to stop
        ret = main.main(cmdline.split())
        os.remove("test.log")
        os.remove("test-settings-broken.yaml")
Пример #35
0
 def test_validate_pass(self):
     cmdline = "odemisd --log-level=2 --validate %s" % filename
     ret = main.main(cmdline.split())
     self.assertEqual(ret, 0, "error detected in correct config "
                         "file '%s'" % filename)