예제 #1
0
    def test_load(self, open_mock):
        context_manager_mock = mock.Mock()
        open_mock.return_value = context_manager_mock
        file_mock = mock.Mock()
        iter_mock = mock.Mock()
        iter_mock.return_value = iter(
            self._split_but_keep_seperated(mock_ini_data, '\n'))
        enter_mock = mock.Mock()
        enter_mock.return_value = file_mock
        exit_mock = mock.Mock()
        setattr(context_manager_mock, '__enter__', enter_mock)
        setattr(context_manager_mock, '__exit__', exit_mock)
        setattr(file_mock, '__iter__', iter_mock)

        ini_file = Ini()
        ini_file.load()
        result = {}
        result['test'] = [None, 'wizard']
        result['castSpell'] = [None, True]
        result['punch'] = [None, 1]
        result['ghost'] = ['section', False]
        result_sections = {}
        result_sections['section'] = set()
        result_sections['section'].add('ghost')

        self.assertEqual(ini_file._settings, result)
        self.assertEqual(ini_file._sections._sections, result_sections)
예제 #2
0
    def test_iteration(self):
        ini_file = Ini()
        ini_file['set1'] = 'data'
        ini_file['set2'] = 'great'
        ini_file['set3'] = 'help'
        ini_file['set4'] = 'info'
        ini_file['bob'] = ['wizards', True]

        settings_list = {}
        for setting in ini_file:
            settings_list[setting[0]] = setting[1]

        expected_result = dict([('set1', 'data'), ('set2', 'great'),
                                ('set3', 'help'), ('set4', 'info'),
                                ('bob', True)])
        self.assertEqual(settings_list, expected_result)
예제 #3
0
 def test_get_length_empty(self):
     ini_file = Ini()
     self.assertEqual(len(ini_file), 0)
예제 #4
0
 def test_get_length_not_empty(self):
     ini_file = Ini()
     ini_file['test'] = 'wizard'
     ini_file['castSpell'] = True
     self.assertEqual(len(ini_file), 2)
예제 #5
0
 def test_get_setting_section(self):
     ini_file = Ini()
     ini_file['test'] = ['magicPeople', 'wizard']
     self.assertEqual(ini_file.get_setting_section('test'), 'magicPeople')
예제 #6
0
 def test_get_setting_key_error(self):
     ini_file = Ini()
     with self.assertRaises(KeyError):
         ini_file['test']
예제 #7
0
 def test_add_setting_with_key_type_error(self):
     ini_file = Ini()
     with self.assertRaises(TypeError):
         ini_file[564] = 'wizard'
예제 #8
0
 def test_get_setting(self):
     ini_file = Ini()
     ini_file['test'] = 'wizard'
     self.assertEqual(ini_file['test'], 'wizard')
예제 #9
0
 def test_add_setting(self):
     ini_file = Ini()
     ini_file['test'] = 'wizard'
예제 #10
0
 def test_add_setting_with_section(self):
     ini_file = Ini()
     ini_file['test'] = ('people', 'wizard')
     self.assertEqual(ini_file['test'], 'wizard')
     self.assertEqual(ini_file.get_setting_section('test'), 'people')
예제 #11
0
 def test_instantiate_with_directory(self):
     ini_file = Ini(directory='\\test\\directory')
     self.assertEqual(ini_file.directory, '\\test\\directory')
예제 #12
0
 def test_instantiate_with_filename(self):
     ini_file = Ini(filename='wizard')
     self.assertEqual(ini_file.filename, 'wizard')
예제 #13
0
 def test_instantiate(self):
     ini_file = Ini()
예제 #14
0
from ini_handler.vbini import Ini

if __name__ == '__main__':
    ini_file = Ini()
    print(ini_file)
    print(ini_file.filename)
    print(ini_file.directory)

    print('Items:', len(ini_file))

    ini_file['testKey'] = 'test string'
    ini_file['Another'] = 'True'
    ini_file['setting'] = 1993
    ini_file['FinalSetting'] = 'bob'
    print('')
    print('Items:', len(ini_file))
    print('Item 1:', ini_file['testKey'])
    ini_file['testKey'] = 'new'
    print('Item 1 change:', ini_file['testKey'])
    print('Items:', len(ini_file))

    # del ini_file['testKey']
    # print('')
    # print('Items:', len(ini_file))
    # del ini_file['testKey']

    print('')
    print('')
    ini2 = Ini(filename='testing.ini')
    print(ini2.filename)
    print(ini2)
예제 #15
0
from ini_handler.vbini import Ini

if __name__ == '__main__':
    ini_file = Ini()
    ini_file.load()
    print(ini_file._settings)
    print(ini_file._sections)
    print(ini_file['test'])