def test_get_description_illegal_values(self):
        ''' Test what happens if illegal or not existing values are being
            tried to be accessed.
        '''
        config = AppConfig()
        config.init_default_config(os.path.join(self.config_dir,
                'test_data.txt'))

        # try to access a value that does not exist
        with self.assertRaises(AppConfigValueException):
            config.get_description('server', 'alpha')

        # set a new value with no description and access it.
        config.set('server', 'alpha', "12")
        desc, ctype, default = config.get_description('server', 'alpha')
        self.assertTrue(desc == '')
        self.assertTrue(default == '')
        self.assertTrue(ctype == str)

        # access section which does not exist
        with self.assertRaises(AppConfigValueException):
            config.get_description('sunrise', 'alpha')

        # set value of a not existing section and access it again
        config.set('sunrise', 'alpha', 12)
        desc, ctype, default = config.get_description('sunrise', 'alpha')
        self.assertTrue(desc == '')
        self.assertTrue(default == '')
        self.assertTrue(ctype == str)
Example #2
0
    def test_get_description_illegal_values(self):
        ''' Test what happens if illegal or not existing values are being
            tried to be accessed.
        '''
        config = AppConfig()
        config.init_default_config(os.path.join(self.config_dir,
                'test_data.txt'))

        # try to access a value that does not exist
        with self.assertRaises(AppConfigValueException):
            config.get_description('server', 'alpha')

        # set a new value with no description and access it.
        config.set('server', 'alpha', "12")
        desc, ctype, default = config.get_description('server', 'alpha')
        self.assertTrue(desc == '')
        self.assertTrue(default == '')
        self.assertTrue(ctype == str)

        # access section which does not exist
        with self.assertRaises(AppConfigValueException):
            config.get_description('sunrise', 'alpha')

        # set value of a not existing section and access it again
        config.set('sunrise', 'alpha', 12)
        desc, ctype, default = config.get_description('sunrise', 'alpha')
        self.assertTrue(desc == '')
        self.assertTrue(default == '')
        self.assertTrue(ctype == str)
Example #3
0
    def test_save_default_config(self):
        ''' Test the save functionality with a default config file '''
        config = AppConfig()
        config.init_default_config(os.path.join(self.config_dir,
                'test_data.txt'))

        config.save()
        # read the generated default output file (only three sections expected
        # nothing else should be in here since we haven't changed one value.
        # but added the default config file
        sections, values, comments = \
                self._parse_config_file(config.get(config.application_name,
                        'config_file'))
        self.assertTrue(sections == 3)
        self.assertTrue(values == 0)
        self.assertTrue(comments == 0)

        config.save(verbose=True)
        # search the verbose file with 3 lines of comment for each entry
        sections, values, comments = \
                self._parse_config_file(config.get(config.application_name,
                        'config_file'))
        self.assertTrue(sections == 3)
        self.assertTrue(values == 0)
        self.assertTrue(comments == 34)

        config.set('client', 'first', 42)
        config.set('client', 'second', 42)
        config.set('server', 'first', 42)
        config.set('server', 'second', 42)
        config.save()

        config.save()
        # read the config file after two value for each section where set
        sections, values, comments = \
                self._parse_config_file(config.get(config.application_name,
                        'config_file'))
        self.assertTrue(sections == 3)
        self.assertTrue(values == 4)
        self.assertTrue(comments == 0)

        config.save(verbose=True)
        # search the verbose file with 3 lines of comment for each entry and
        # some value where set with a none standard value
        sections, values, comments = \
                self._parse_config_file(config.get(config.application_name,
                        'config_file'))
        self.assertTrue(sections == 3)
        self.assertTrue(values == 4)
        self.assertTrue(comments == 34)

        # load default config
        config.load_default()
        self.assertTrue(config.get('client', 'first') == "42")

        os.remove(config.get(config.application_name, 'config_file'))
Example #4
0
    def test_save_config(self):
        ''' Test the save functionality of the config module '''
        config = AppConfig()
        config.init_default_config(os.path.join(self.config_dir,
                'test_data.txt'))

        config.save(os.path.join(self.config_dir, 'test_default_output.txt'))
        config.save(os.path.join(self.config_dir,
                'test_default_output_verbose.txt'), True)
        # with directory
        config.save(os.path.join(self.config_dir, 'step',
                'test_default_output.txt'))

        config.set('client', 'first', 42)
        config.set('client', 'second', 42)
        config.set('server', 'first', 42)
        config.set('server', 'second', 42)
        config.save(os.path.join(self.config_dir, 'test_save_output.txt'))
        config.save(os.path.join(self.config_dir,
                'test_save_output_verbose.txt'), True)

        # read the generated default output file (only two sections expected
        # nothing else should be in here since we haven't changed one value.
        sections, values, comments = \
                self._parse_config_file('test_default_output.txt')
        self.assertTrue(sections == 2)
        self.assertTrue(values == 0)
        self.assertTrue(comments == 0)

        # search the verbose file with 3 lines of comment for each entry
        sections, values, comments = \
                self._parse_config_file('test_default_output_verbose.txt')
        self.assertTrue(sections == 2)
        self.assertTrue(values == 0)
        self.assertTrue(comments == 30)

        # read the config file after two value for each section where set
        sections, values, comments = \
                self._parse_config_file('test_save_output.txt')
        self.assertTrue(sections == 2)
        self.assertTrue(values == 4)
        self.assertTrue(comments == 0)

        # search the verbose file with 3 lines of comment for each entry and
        # some value where set with a none standard value
        sections, values, comments = \
                self._parse_config_file('test_save_output_verbose.txt')
        self.assertTrue(sections == 2)
        self.assertTrue(values == 4)
        self.assertTrue(comments == 30)
    def test_save_default_config(self):
        ''' Test the save functionality of the config module '''
        config = AppConfig()
        config.init_default_config(os.path.join(self.config_dir,
                'test_data.txt'))

        config.save(os.path.join(self.config_dir, 'test_default_output.txt'))
        config.save(os.path.join(self.config_dir,
                'test_default_output_verbose.txt'), True)
        # with directory
        config.save(os.path.join(self.config_dir, 'step',
                'test_default_output.txt'))

        config.set('client', 'first', 42)
        config.set('client', 'second', 42)
        config.set('server', 'first', 42)
        config.set('server', 'second', 42)
        config.save(os.path.join(self.config_dir, 'test_save_output.txt'))
        config.save(os.path.join(self.config_dir,
                'test_save_output_verbose.txt'), True)

        # read the generated default output file (only two sections expected
        # nothing else should be in here since we haven't changed one value.
        sections, values, comments = \
                self._parse_config_file('test_default_output.txt')
        self.assertTrue(sections == 2)
        self.assertTrue(values == 0)
        self.assertTrue(comments == 0)

        # search the verbose file with 3 lines of comment for each entry
        sections, values, comments = \
                self._parse_config_file('test_default_output_verbose.txt')
        self.assertTrue(sections == 2)
        self.assertTrue(values == 0)
        self.assertTrue(comments == 30)

        # read the config file after two value for each section where set
        sections, values, comments = \
                self._parse_config_file('test_save_output.txt')
        self.assertTrue(sections == 2)
        self.assertTrue(values == 4)
        self.assertTrue(comments == 0)

        # search the verbose file with 3 lines of comment for each entry and
        # some value where set with a none standard value
        sections, values, comments = \
                self._parse_config_file('test_save_output_verbose.txt')
        self.assertTrue(sections == 2)
        self.assertTrue(values == 4)
        self.assertTrue(comments == 30)
Example #6
0
    def test_set_config(self):
        ''' Test seting and getting values from the config object '''
        config = AppConfig()

        # tests without default config loaded
        config.set('client', 'first', 12)
        value = config.get('client', 'first')
        self.assertTrue(type(value) == str)
        # this is a string since we don't now anything about it
        self.assertTrue(value == '12')

        config.set('client', 'third', -16)
        value = config.get('client', 'third')
        self.assertTrue(type(value) == str)
        # this is a string since we don't now anything about it
        self.assertTrue(value == '-16')

        # and now with default config loaded
        config.init_default_config(os.path.join(self.config_dir,
                'test_data.txt'))

        # check previous set values if the previous value remains.
        self._check_value(config, 'client', 'first', 'Aldebarans', str,
                'Start', "12")
        self._check_value(config, 'client', 'third',
                'Amoeboid Zingatularians', int, 12, -16)

        # now do some test for all kind of types
        config.set('client', 'first', 112)
        self._check_value(config, 'client', 'first', 'Aldebarans', str,
                'Start', "112")
        config.set('client', 'second', 12.45)
        if PY2:
            self._check_value(config, 'client', 'second', 'Altairians',
                    unicode, 'Stop', '12.45')
        else:
            self._check_value(config, 'client', 'second', 'Altairians',
                    str, 'Stop', '12.45')
        config.set('client', 'third', -166)
        self._check_value(config, 'client', 'third',
                'Amoeboid Zingatularians', int, 12, -166)
        config.set('client', 'forth', 11)
        self._check_value(config, 'client', 'forth', 'Bartledanians', float,
                12.2, 11.0)
        config.set('client', 'fifth', False)
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, False)
        # the same with a string
        config.set('client', 'fifth', "False")
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, False)
        config.set('client', 'fifth', "True")
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, True)
        # the same with numbers
        config.set('client', 'fifth', 0)
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, False)
        config.set('client', 'fifth', 1)
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, True)
        # with illegal value
        with self.assertRaises(AppConfigValueException):
            config.set('client', 'fifth', 'no')

        config.set('server', 'first', True)
        self._check_value(config, 'server', 'first', 'Betelgeusians', str,
                'End', 'True')
        config.set('server', 'second', "Arther Dent")
        if PY2:
            self._check_value(config, 'server', 'second', 'Blagulon Kappans',
                    unicode, 'Accelerate', 'Arther Dent')
        else:
            self._check_value(config, 'server', 'second', 'Blagulon Kappans',
                    str, 'Accelerate', 'Arther Dent')
        config.set('server', 'third', 42)
        self._check_value(config, 'server', 'third', 'Dentrassis', int, -12,
                42)
        config.set('server', 'forth', 42.43)
        self._check_value(config, 'server', 'forth', 'Dolphins', float,
                3.3333, 42.43)
        config.set('server', 'fifth', True)
        self._check_value(config, 'server', 'fifth',
                "G'Gugvunnts and Vl'hurgs", bool, False, True)
    def test_set_config(self):
        ''' Test seting and getting values from the config object '''
        config = AppConfig()

        # tests without default config loaded
        config.set('client', 'first', 12)
        value = config.get_s('client', 'first')
        self.assertTrue(type(value) == str)
        # this is a string since we don't now anything about it
        self.assertTrue(value == '12')

        config.set('client', 'third', -16)
        value = config.get_s('client', 'third')
        self.assertTrue(type(value) == str)
        # this is a string since we don't now anything about it
        self.assertTrue(value == '-16')

        # and now with default config loaded
        config.init_default_config(os.path.join(self.config_dir,
                'test_data.txt'))

        # check previous set values if the previous value remains.
        self._check_value(config, 'client', 'first', 'Aldebarans', str,
                'Start', "12")
        self._check_value(config, 'client', 'third',
                'Amoeboid Zingatularians', int, 12, -16)

        # now do some test for all kind of types
        config.set('client', 'first', 112)
        self._check_value(config, 'client', 'first', 'Aldebarans', str,
                'Start', "112")
        config.set('client', 'second', 12.45)
        self._check_value(config, 'client', 'second', 'Altairians', unicode,
                'Stop', '12.45')
        config.set('client', 'third', -166)
        self._check_value(config, 'client', 'third',
                'Amoeboid Zingatularians', int, 12, -166)
        config.set('client', 'forth', 11)
        self._check_value(config, 'client', 'forth', 'Bartledanians', float,
                12.2, 11.0)
        config.set('client', 'fifth', False)
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, False)
        # the same with a string
        config.set('client', 'fifth', "False")
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, False)
        config.set('client', 'fifth', "True")
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, True)
        # the same with numbers
        config.set('client', 'fifth', 0)
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, False)
        config.set('client', 'fifth', 1)
        self._check_value(config, 'client', 'fifth', 'Belcerebons', bool,
                True, True)
        # with illegal value
        with self.assertRaises(AppConfigValueException):
            config.set('client', 'fifth', 'no')

        config.set('server', 'first', True)
        self._check_value(config, 'server', 'first', 'Betelgeusians', str,
                'End', 'True')
        config.set('server', 'second', "Arther Dent")
        self._check_value(config, 'server', 'second', 'Blagulon Kappans',
                unicode, 'Accelerate', 'Arther Dent')
        config.set('server', 'third', 42)
        self._check_value(config, 'server', 'third', 'Dentrassis', int, -12,
                42)
        config.set('server', 'forth', 42.43)
        self._check_value(config, 'server', 'forth', 'Dolphins', float,
                3.3333, 42.43)
        config.set('server', 'fifth', True)
        self._check_value(config, 'server', 'fifth',
                "G'Gugvunnts and Vl'hurgs", bool, False, True)