Ejemplo n.º 1
0
 def test_8_config_read_multi(self):
     # create an ethernet config
     self.test_4_config_write_ethernet()
     ethernet_config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.ETHERNET)
     # stuff it into a multi-comm config
     config = { 'comm': {'method': 'multi', 'configs': {'test': {'comm': ethernet_config.dict()}}}}
     # dump the new config to a file
     open(self.config_file(), 'wb').write(yaml.dump(config))
     # load the config from file, verify the embedded config matches the original ethernet config
     multi_config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.MULTI)
     self.assertEqual(multi_config.configs['test'].dict(), ethernet_config.dict())
 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)
Ejemplo n.º 3
0
    def test_6_config_write_serial(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(),
                                                 ConfigTypes.SERIAL)
        config.device_os_port = DEVICE_OS_PORT
        config.device_baud = DEVICE_BAUD
        config.device_data_bits = DEVICE_DATA_BITS
        config.device_parity = DEVICE_PARITY
        config.device_stop_bits = DEVICE_STOP_BITS
        config.device_flow_control = DEVICE_FLOW_CONTROL
        config.data_port = DATA_PORT
        config.command_port = COMMAND_PORT

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

        config.store_to_file()

        # order isnt the same, so lets turn it into an array of label: value's then sort and compare.
        self.assertEqual(
            sorted(
                string.replace(self.config_serial_content(), "\n",
                               '').split('  ')),
            sorted(string.replace(self.read_config(), "\n", '').split('  ')))
Ejemplo n.º 4
0
    def test_4_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(),
                                                 ConfigTypes.ETHERNET)
        config.device_addr = INSTRUMENT_ADDR
        config.device_port = INSTRUMENT_PORT
        config.data_port = DATA_PORT
        config.command_port = COMMAND_PORT

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

        config.store_to_file()

        # order isnt the same, so lets turn it into an array of label: value's then sort and compare.
        self.assertEqual(
            sorted(
                string.replace(self.config_ethernet_content(), "\n",
                               '').split('  ')),
            sorted(string.replace(self.read_config(), "\n", '').split('  ')))
Ejemplo n.º 5
0
    def test_6_config_write_serial(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(), ConfigTypes.SERIAL)
        config.device_os_port = DEVICE_OS_PORT
        config.device_baud = DEVICE_BAUD
        config.device_data_bits = DEVICE_DATA_BITS
        config.device_parity = DEVICE_PARITY
        config.device_stop_bits = DEVICE_STOP_BITS
        config.device_flow_control = DEVICE_FLOW_CONTROL
        config.data_port = DATA_PORT
        config.command_port = COMMAND_PORT

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

        config.store_to_file()

        # order isnt the same, so lets turn it into an array of label: value's then sort and compare.
        self.assertEqual(sorted(string.replace(self.config_serial_content(), "\n", '').split('  ')),
                         sorted(string.replace(self.read_config(), "\n", '').split('  ')))
Ejemplo n.º 6
0
 def test_5_config_read_ethernet(self):
     config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.ETHERNET)
     
     self.assertEqual(config.device_addr, INSTRUMENT_ADDR)
     self.assertEqual(config.device_port, INSTRUMENT_PORT)
     self.assertEqual(config.data_port, DATA_PORT)
     self.assertEqual(config.command_port, COMMAND_PORT)
 def test_5_config_read_ethernet(self):
     config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.ETHERNET)
     
     self.assertEqual(config.device_addr, INSTRUMENT_ADDR)
     self.assertEqual(config.device_port, INSTRUMENT_PORT)
     self.assertEqual(config.data_port, DATA_PORT)
     self.assertEqual(config.command_port, COMMAND_PORT)
Ejemplo n.º 8
0
    def test_7_config_read_serial(self):
        config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.SERIAL)

        self.assertEqual(config.device_os_port, DEVICE_OS_PORT)
        self.assertEqual(config.device_baud, DEVICE_BAUD)
        self.assertEqual(config.device_data_bits, DEVICE_DATA_BITS)
        self.assertEqual(config.device_parity, DEVICE_PARITY)
        self.assertEqual(config.device_stop_bits, DEVICE_STOP_BITS)
        self.assertEqual(config.device_flow_control, DEVICE_FLOW_CONTROL)
        self.assertEqual(config.data_port, DATA_PORT)
        self.assertEqual(config.command_port, COMMAND_PORT)
    def test_7_config_read_serial(self):
        config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.SERIAL)

        self.assertEqual(config.device_os_port, DEVICE_OS_PORT)
        self.assertEqual(config.device_baud, DEVICE_BAUD)
        self.assertEqual(config.device_data_bits, DEVICE_DATA_BITS)
        self.assertEqual(config.device_parity, DEVICE_PARITY)
        self.assertEqual(config.device_stop_bits, DEVICE_STOP_BITS)
        self.assertEqual(config.device_flow_control, DEVICE_FLOW_CONTROL)
        self.assertEqual(config.data_port, DATA_PORT)
        self.assertEqual(config.command_port, COMMAND_PORT)
Ejemplo n.º 10
0
 def test_8_config_read_multi(self):
     # create an ethernet config
     self.test_4_config_write_ethernet()
     ethernet_config = CommConfig.get_config_from_type(
         self.config_file(), ConfigTypes.ETHERNET)
     # stuff it into a multi-comm config
     config = {
         'comm': {
             'method': 'multi',
             'configs': {
                 'test': {
                     'comm': ethernet_config.dict()
                 }
             }
         }
     }
     # dump the new config to a file
     open(self.config_file(), 'wb').write(yaml.dump(config))
     # load the config from file, verify the embedded config matches the original ethernet config
     multi_config = CommConfig.get_config_from_type(self.config_file(),
                                                    ConfigTypes.MULTI)
     self.assertEqual(multi_config.configs['test'].dict(),
                      ethernet_config.dict())
 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())
 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 = INSTRUMENT_ADDR
     config.device_port = INSTRUMENT_PORT
     config.data_port = DATA_PORT
     config.command_port = COMMAND_PORT
     
     log.debug("CONFIG: %s" % config.serialize())
     
     config.store_to_file()
     
     self.assertEqual(self.config_content(), self.read_config())
Ejemplo n.º 13
0
    def test_4_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(), ConfigTypes.ETHERNET)
        config.device_addr = INSTRUMENT_ADDR
        config.device_port = INSTRUMENT_PORT
        config.data_port = DATA_PORT
        config.command_port = COMMAND_PORT
        
        log.debug("CONFIG: %s" % config.serialize())
        
        config.store_to_file()

        # order isnt the same, so lets turn it into an array of label: value's then sort and compare.
        self.assertEqual(sorted(string.replace(self.config_ethernet_content(), "\n", '').split('  ')),
                         sorted(string.replace(self.read_config(), "\n", '').split('  ')))
         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):
     types = CommConfig.valid_type_list()
     log.debug( "types: %s" % types)
     
     known_types = ['ethernet']
     
     self.assertEqual(sorted(types), sorted(known_types))
     
 def test_config_write_ethernet(self):
     log.debug("Config File: %s" % self.config_file())
Ejemplo n.º 15
0
            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_3_comm_config_type_list(self):
        types = CommConfig.valid_type_list()
        log.debug("types: %s" % types)

        known_types = [
            ConfigTypes.ETHERNET, ConfigTypes.RSN, ConfigTypes.SERIAL,
            ConfigTypes.BOTPT, ConfigTypes.MULTI
        ]

        self.assertEqual(sorted(types), sorted(known_types))