Example #1
0
    def test_settings_fs_no_fails(self):
        fs = FileStorage(None)

        self.assertEqual(fs.watcher, None)
        self.assertEqual(fs.load(), {})
        self.assertEqual(fs.loadDefaults(), {})
        self.assertEqual(fs.close(), None)
Example #2
0
    def test_settings_fs_save(self):
        path = os.path.join(self.dir, 'settings.cfg')

        fs = FileStorage(path)
        self.assertEqual(fs.load(), {'here': ''})

        fs.save({'group.node1': 'value'})
        self.assertEqual(fs.load(), {'group.node1': 'value', 'here': ''})
        self.assertEqual(open(path).read(),
                         '[DEFAULT]\ngroup.node1 = value\n\n')
Example #3
0
    def test_settings_fs(self):
        path = os.path.join(self.dir, 'settings.cfg')
        f = open(path, 'wb')
        f.write("""[DEFAULT]\ngroup.node1 = test\ngroup.node2 = 40""")
        f.close()

        fs = FileStorage(path)
        self.assertEqual(fs.load(),
                         {'group.node1': 'test',
                          'group.node2': '40', 'here': ''})
Example #4
0
    def test_settings_fs_save_to_existing(self):
        path = os.path.join(self.dir, 'settings.cfg')
        f = open(path, 'wb')
        f.write('[TEST]\ngroup.node1 = value\n\n')
        f.close()

        fs = FileStorage(path)
        self.assertEqual(fs.load(), {'here': ''})

        fs.save({'group.node1': 'value'})
        self.assertEqual(fs.load(), {'group.node1': 'value', 'here': ''})
        self.assertEqual(
            open(path).read(),
            '[DEFAULT]\ngroup.node1 = value\n\n[TEST]\ngroup.node1 = value\n\n')
Example #5
0
    def test_settings_fs_defaults_include(self):
        path_extra = os.path.join(self.dir, 'defaults-extra.cfg')
        f = open(path_extra, 'wb')
        f.write("""[DEFAULT]\nsection.item = 40""")
        f.close()

        path = os.path.join(self.dir, 'defaults.cfg')
        f = open(path, 'wb')
        f.write("[DEFAULT]\ngroup.node = test\ninclude = %s"%path_extra)
        f.close()

        fs = FileStorage(None, path)
        data = fs.loadDefaults()

        self.assertTrue('group.node' in data)
        self.assertTrue('section.item' in data)
        self.assertEqual([data['group.node'], data['section.item']],
                         ['test', '40'])
Example #6
0
 def test_settings_fs_save_nosettings_file(self):
     fs = FileStorage(None)
     self.assertEqual(fs.save({'group.node1': 'test'}), None)
Example #7
0
    def test_settings_fs_nosettings_file(self):
        path = os.path.join(self.dir, 'settings.cfg')

        fs = FileStorage(path)
        self.assertEqual(fs.load(), {'here': ''})
        self.assertTrue(os.path.exists(path))
Example #8
0
    def test_settings_fs_notexisting_defaults(self):
        fs = FileStorage(None, os.path.join(self.dir, 'defaults.cfg'))

        self.assertEqual(fs.loadDefaults(), {})