示例#1
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
示例#2
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
示例#3
0
 def test_constructor(self):
     """
     Test object creation
     """
     config = CommConfig()
     self.assertTrue(config)
示例#4
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):