Example #1
0
 def fetch_comm_config(self):
     """
     @brief collect connection information for the logger from the user
     """
     config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename())
     self.comm_config = CommConfig.get_config_from_console(config_path)
     self.comm_config.get_from_console()
Example #2
0
    def __init__(self, metadata, log_file = None):
        """
        @brief Constructor
        @param metadata IDK Metadata object
        @param log_file File to store test results.  If none specified log to STDOUT
        """
        repo_dir = Config().get("working_repo")
        if(not repo_dir):
            raise IDKConfigMissing()
        
        # Ion scripts need to be run from the base os the repo dir so it has access
        # to resources using relative pathing.  So we just do 
        os.chdir(repo_dir)
        
        self.metadata = metadata
        if(not self.metadata.driver_name):
            raise DriverNotStarted()

        if( log_file ):
            self.log_fh = open(log_file, "w")
        else:
            self.log_fh = sys.stdout
            
        config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename())
        self.comm_config = CommConfig.get_config_from_file(config_path)
        if(not self.comm_config):
            raise CommConfigReadFail(msg=config_path)

        self.test_runner = nose.core.TextTestRunner(stream=self.log_fh)
Example #3
0
    def __init__(self, metadata, log_file=None):
        """
        @brief Constructor
        @param metadata IDK Metadata object
        @param log_file File to store test results.  If none specified log to STDOUT
        """
        repo_dir = Config().get("working_repo")
        if (not repo_dir):
            raise IDKConfigMissing()

        # Ion scripts need to be run from the base os the repo dir so it has access
        # to resources using relative pathing.  So we just do
        os.chdir(repo_dir)

        self.metadata = metadata
        if (not self.metadata.driver_name):
            raise DriverNotStarted()

        if (log_file):
            self.log_fh = open(log_file, "w")
        else:
            self.log_fh = sys.stdout

        config_path = "%s/%s" % (self.metadata.driver_dir(),
                                 CommConfig.config_filename())
        self.comm_config = CommConfig.get_config_from_file(config_path)
        if (not self.comm_config):
            raise CommConfigReadFail(msg=config_path)

        self.test_runner = nose.core.TextTestRunner(stream=self.log_fh)
Example #4
0
 def fetch_comm_config(self):
     """
     @brief collect connection information for the logger from the user
     """
     config_path = "%s/%s" % (self.metadata.driver_dir(),
                              CommConfig.config_filename())
     self.comm_config = CommConfig.get_config_from_console(config_path)
     self.comm_config.get_from_console()
Example #5
0
 def test_comm_config_type_list(self):
     types = CommConfig.valid_type_list()
     log.debug( "types: %s" % types)
     
     known_types = ['ethernet']
     
     self.assertEqual(sorted(types), sorted(known_types))
Example #6
0
 def test_config_read_ethernet(self):
     config = CommConfig.get_config_from_type(self.config_file(), "ethernet")
     
     self.assertEqual(config.device_addr, 'localhost')
     self.assertEqual(config.device_port, 1000)
     self.assertEqual(config.server_addr, 'localhost')
     self.assertEqual(config.server_port, 2000)
Example #7
0
    def test_comm_config_type_list(self):
        types = CommConfig.valid_type_list()
        log.debug("types: %s" % types)

        known_types = ['ethernet']

        self.assertEqual(sorted(types), sorted(known_types))
Example #8
0
 def overwrite(self):
     """
     @brief Overwrite the current files with what is stored in the current metadata file.
     """
     self.metadata = Metadata()
     self.comm_config = CommConfig.get_config_from_file(self.metadata)
     self.generate_code(force = True)
Example #9
0
 def overwrite(self):
     """
     @brief Overwrite the current files with what is stored in the current metadata file.
     """
     self.metadata = Metadata()
     self.comm_config = CommConfig.get_config_from_file(self.metadata)
     self.generate_code(force=True)
Example #10
0
    def test_config_read_ethernet(self):
        config = CommConfig.get_config_from_type(self.config_file(),
                                                 "ethernet")

        self.assertEqual(config.device_addr, 'localhost')
        self.assertEqual(config.device_port, 1000)
        self.assertEqual(config.server_addr, 'localhost')
        self.assertEqual(config.server_port, 2000)
Example #11
0
 def test_exceptions(self):
     """
     Test exceptions raised by the CommConfig object
     """
     ## No exception thrown if file doesn't exist
     error = None
     try:
         config = CommConfig("this_file_does_not_exist.foo")
     except CommConfigReadFail, e:
         error = e
Example #12
0
    def init_comm_config(self):
        """
        @brief Create the comm config object by reading the comm_config.yml file.
        """
        log.info("Initialize comm config")
        config_file = self.comm_config_file()

        log.debug(" -- reading comm config from: %s" % config_file)
        if not os.path.exists(config_file):
            raise TestNoCommConfig(msg="Missing comm config.  Try running start_driver or switch_driver")

        self.comm_config = CommConfig.get_config_from_file(config_file)
Example #13
0
    def comm_config_file(self):
        """
        @brief Return the path the the driver comm config yaml file.
        @return if comm_config.yml exists return the full path
        """
        repo_dir = Config().get("working_repo")
        driver_path = self._test_config.driver_module
        p = re.compile("\.")
        driver_path = p.sub("/", driver_path)
        abs_path = "%s/%s/%s" % (repo_dir, os.path.dirname(driver_path), CommConfig.config_filename())

        log.debug(abs_path)
        return abs_path
Example #14
0
    def comm_config_file(self):
        """
        @brief Return the path the the driver comm config yaml file.
        @return if comm_config.yml exists return the full path
        """
        repo_dir = Config().get('working_repo')
        driver_path = self._test_config.driver_module
        p = re.compile('\.')
        driver_path = p.sub('/', driver_path)
        abs_path = "%s/%s/%s" % (repo_dir, os.path.dirname(driver_path),
                                 CommConfig.config_filename())

        log.debug(abs_path)
        return abs_path
Example #15
0
    def init_comm_config(self):
        """
        @brief Create the comm config object by reading the comm_config.yml file.
        """
        log.info("Initialize comm config")
        config_file = self.comm_config_file()

        log.debug(" -- reading comm config from: %s" % config_file)
        if not os.path.exists(config_file):
            raise TestNoCommConfig(
                msg=
                "Missing comm config.  Try running start_driver or switch_driver"
            )

        self.comm_config = CommConfig.get_config_from_file(config_file)
Example #16
0
 def test_config_write_ethernet(self):
     log.debug("Config File: %s" % self.config_file())
     if exists(self.config_file()):
         log.debug(" -- remove %s" % self.config_file())
         remove(self.config_file())
         
     self.assertFalse(exists(self.config_file()))
     
     config = CommConfig.get_config_from_type(self.config_file(), "ethernet")
     config.device_addr = 'localhost'
     config.device_port = 1000
     config.server_addr = 'localhost'
     config.server_port = 2000
     
     log.debug("CONFIG: %s" % config.serialize())
     
     config.store_to_file()
     
     self.assertEqual(self.config_content(), self.read_config())
Example #17
0
    def __init__(self, metadata, log_file = None):
        """
        @brief Constructor
        @param metadata IDK Metadata object
        @param log_file File to store test results.  If none specified log to STDOUT
        """
        self.metadata = metadata
        if(not self.metadata.name):
            raise Exception('No drivers initialized.  run start_driver')

        if( log_file ):
            self.log_fh = open(log_file, "w")
        else:
            self.log_fh = sys.stdout

        self.comm_config = CommConfig.get_config_from_type(metadata, 'ethernet')
        if(not self.comm_config):
            raise Exception('No comm config file found!')

        self.test_runner = nose.core.TextTestRunner(stream=self.log_fh)
Example #18
0
    def test_config_write_ethernet(self):
        log.debug("Config File: %s" % self.config_file())
        if exists(self.config_file()):
            log.debug(" -- remove %s" % self.config_file())
            remove(self.config_file())

        self.assertFalse(exists(self.config_file()))

        config = CommConfig.get_config_from_type(self.config_file(),
                                                 "ethernet")
        config.device_addr = 'localhost'
        config.device_port = 1000
        config.server_addr = 'localhost'
        config.server_port = 2000

        log.debug("CONFIG: %s" % config.serialize())

        config.store_to_file()

        self.assertEqual(self.config_content(), self.read_config())
Example #19
0
 def fetch_comm_config(self):
     """
     @brief collect connection information for the logger from the user
     """
     self.comm_config = CommConfig.get_config_from_console(self.metadata)
     self.comm_config.get_from_console()
Example #20
0
        except CommConfigReadFail, e:
            error = e
        self.assertFalse(error)

        error = None
        try:
            config = CommConfig()
            config.read_from_file("/tmp")
        except CommConfigReadFail, e:
            log.debug("caught error %s" % e)
            error = e
        self.assertTrue(error)

        error = None
        try:
            config = CommConfig()
            config.store_to_file()
        except NoConfigFileSpecified, e:
            log.debug("caught error %s" % e)
            error = e
        self.assertTrue(error)

        error = None
        try:
            config = CommConfig.get_config_from_type(self.config_file(), "foo")
        except InvalidCommType, e:
            log.debug("caught error %s" % e)
            error = e
        self.assertTrue(error)

    def test_comm_config_type_list(self):
Example #21
0
class TestCommConfig(unittest.TestCase):
    """
    Test the comm config object.  
    """
    def setUp(self):
        """
        Setup the test case
        """
        if not exists(ROOTDIR):
            makedirs(ROOTDIR)

        self.write_config()

    def config_file(self):
        return "%s/comm_config.yml" % ROOTDIR

    def config_content(self):
        return "comm:\n" + \
               "  device_addr: localhost\n" + \
               "  device_port: 1000\n" + \
               "  method: ethernet\n" + \
               "  server_addr: localhost\n" + \
               "  server_port: 2000\n"

    def write_config(self):
        ofile = open(self.config_file(), "w")
        ofile.write(self.config_content())
        ofile.close()

    def read_config(self):
        infile = open(self.config_file(), "r")
        result = infile.read()
        infile.close()
        return result

    def test_constructor(self):
        """
        Test object creation
        """
        config = CommConfig()
        self.assertTrue(config)

    def test_exceptions(self):
        """
        Test exceptions raised by the CommConfig object
        """
        ## No exception thrown if file doesn't exist
        error = None
        try:
            config = CommConfig("this_file_does_not_exist.foo")
        except CommConfigReadFail, e:
            error = e
        self.assertFalse(error)

        error = None
        try:
            config = CommConfig()
            config.read_from_file("/tmp")
        except CommConfigReadFail, e:
            log.debug("caught error %s" % e)
            error = e
Example #22
0
     except CommConfigReadFail, e:
         error = e
     self.assertFalse(error)
     
     error = None
     try:
         config = CommConfig()
         config.read_from_file("/tmp");
     except CommConfigReadFail, e:
         log.debug("caught error %s" % e)
         error = e
     self.assertTrue(error)
     
     error = None
     try:
         config = CommConfig()
         config.store_to_file();
     except NoConfigFileSpecified, e:
         log.debug("caught error %s" % e)
         error = e
     self.assertTrue(error)
     
     error = None
     try:
         config = CommConfig.get_config_from_type(self.config_file(), "foo")
     except InvalidCommType, e:
         log.debug("caught error %s" % e)
         error = e
     self.assertTrue(error)
 
 def test_comm_config_type_list(self):
Example #23
0
 def test_constructor(self):
     """
     Test object creation
     """
     config = CommConfig()
     self.assertTrue(config)