コード例 #1
0
ファイル: common.py プロジェクト: AlexUlrich/digsby
class NestedDictDatastoreTests(DictDatastoreTests):
    def setUp(self):
        self.data = {
            'a': {'b': {'c': 0},
                  'd': {'e': 'f'},
                  'g': 'h',
                  },
            'i': 'j',
        }
        key = lambda x: tuple(x.split('.'))
        self.flat_data = dict([(key('a.b.c'), 0),
                               (key('a.d.e'), 'f'),
                               (key('a.g'), 'h'),
                               (key('i'), 'j')])

        self.datastore = NestedDictDatastore(data = self.data)

    def tearDown(self):
        del self.data
        del self.flat_data
        del self.datastore

    def test_set_new(self):
        for k, v in sorted(self.datastore.items(), reverse=True):
            new_k0 = (('new ' + k[0]),)
            new_k = new_k0 + k[1:]
            self.datastore.set(new_k, v)
            new_v = self.datastore.get(new_k)

            if isinstance(new_v, type(self.datastore)):
                new_v = new_v.data
            self.assertEqual(v, new_v)

    def test_items(self):
        items = sorted(list(self.datastore.items()))
        for k, v in items:
            self.assertEqual(type(k), tuple)
        self.assertEqual(items, sorted(list(self.flat_data.items())))

    def test_get_success(self):
        for key in self.datastore.keys():
            try:
                val = self.datastore.get(key)
            except Exception:
                pass
            if isinstance(val, type(self.datastore)):
                val = val.data
            self.assertEqual(val, self.flat_data[key], (key, val, self.flat_data[key]))

        for key in self.flat_data.keys():
            if not all(isinstance(x, basestring) for x in key):
                continue
            string_key = '.'.join(key)
            self.assertEqual(self.flat_data[key], self.datastore.get(key))
            self.assertEqual(self.flat_data[key], self.datastore.get(string_key))

    def test_keys(self):
        self.assertEqual(set(self.datastore.keys()), set(self.flat_data.keys()))
コード例 #2
0
ファイル: common.py プロジェクト: sgricci/digsby
    def setUp(self):
        self.data = {
            'a': {
                'b': {
                    'c': 0
                },
                'd': {
                    'e': 'f'
                },
                'g': 'h',
            },
            'i': 'j',
        }
        key = lambda x: tuple(x.split('.'))
        self.flat_data = dict([(key('a.b.c'), 0), (key('a.d.e'), 'f'),
                               (key('a.g'), 'h'), (key('i'), 'j')])

        self.datastore = NestedDictDatastore(data=self.data)
コード例 #3
0
ファイル: common.py プロジェクト: AlexUlrich/digsby
    def setUp(self):
        self.data = {
            'a': {'b': {'c': 0},
                  'd': {'e': 'f'},
                  'g': 'h',
                  },
            'i': 'j',
        }
        key = lambda x: tuple(x.split('.'))
        self.flat_data = dict([(key('a.b.c'), 0),
                               (key('a.d.e'), 'f'),
                               (key('a.g'), 'h'),
                               (key('i'), 'j')])

        self.datastore = NestedDictDatastore(data = self.data)
コード例 #4
0
ファイル: common.py プロジェクト: sgricci/digsby
class NestedDictDatastoreTests(DictDatastoreTests):
    def setUp(self):
        self.data = {
            'a': {
                'b': {
                    'c': 0
                },
                'd': {
                    'e': 'f'
                },
                'g': 'h',
            },
            'i': 'j',
        }
        key = lambda x: tuple(x.split('.'))
        self.flat_data = dict([(key('a.b.c'), 0), (key('a.d.e'), 'f'),
                               (key('a.g'), 'h'), (key('i'), 'j')])

        self.datastore = NestedDictDatastore(data=self.data)

    def tearDown(self):
        del self.data
        del self.flat_data
        del self.datastore

    def test_set_new(self):
        for k, v in sorted(self.datastore.items(), reverse=True):
            new_k0 = (('new ' + k[0]), )
            new_k = new_k0 + k[1:]
            self.datastore.set(new_k, v)
            new_v = self.datastore.get(new_k)

            if isinstance(new_v, type(self.datastore)):
                new_v = new_v.data
            self.assertEqual(v, new_v)

    def test_items(self):
        items = sorted(list(self.datastore.items()))
        for k, v in items:
            self.assertEqual(type(k), tuple)
        self.assertEqual(items, sorted(list(self.flat_data.items())))

    def test_get_success(self):
        for key in self.datastore.keys():
            try:
                val = self.datastore.get(key)
            except Exception:
                pass
            if isinstance(val, type(self.datastore)):
                val = val.data
            self.assertEqual(val, self.flat_data[key],
                             (key, val, self.flat_data[key]))

        for key in self.flat_data.keys():
            if not all(isinstance(x, basestring) for x in key):
                continue
            string_key = '.'.join(key)
            self.assertEqual(self.flat_data[key], self.datastore.get(key))
            self.assertEqual(self.flat_data[key],
                             self.datastore.get(string_key))

    def test_keys(self):
        self.assertEqual(set(self.datastore.keys()),
                         set(self.flat_data.keys()))