def test_2_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
class TestCommConfig(MiUnitTest): """ 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_ethernet_content(self): return "comm:\n" +\ " command_port: %d\n" % (COMMAND_PORT) + \ " data_port: %d\n" % (DATA_PORT) + \ " device_addr: %s\n" % (INSTRUMENT_ADDR) + \ " device_port: %d\n" % (INSTRUMENT_PORT) + \ " host: %s\n" % (HOST) + \ " sniffer_port: %d\n" % (SNIFFER_PORT) + \ " method: ethernet\n" def config_serial_content(self): return "comm:\n" +\ " command_port: %d\n" % (COMMAND_PORT) +\ " data_port: %d\n" % (DATA_PORT) +\ " device_os_port: %s\n" % (DEVICE_OS_PORT) + \ " device_baud: %d\n" % (DEVICE_BAUD) + \ " device_data_bits: %d\n" % (DEVICE_DATA_BITS) + \ " device_parity: %d\n" % (DEVICE_PARITY) + \ " device_stop_bits: %d\n" % (DEVICE_STOP_BITS) + \ " device_flow_control: %d\n" % (DEVICE_FLOW_CONTROL) + \ " host: %s\n" % (HOST) + \ " sniffer_port: %d\n" % (SNIFFER_PORT) + \ " method: serial\n" def write_ethernet_config(self): ofile = open(self.config_file(), "w") ofile.write(self.config_ethernet_content()) ofile.close() def write_serial_config(self): ofile = open(self.config_file(), "w") ofile.write(self.config_serial_content()) ofile.close() def read_config(self): infile = open(self.config_file(), "r") result = infile.read() infile.close() return result def test_1_constructor(self): """ Test object creation """ config = CommConfig() self.assertTrue(config) def test_2_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
def test_1_constructor(self): """ Test object creation """ config = CommConfig() self.assertTrue(config)
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_3_comm_config_type_list(self):