コード例 #1
0
ファイル: test_cache.py プロジェクト: RootForum/magrathea
    def test_03(self):
        """
        Test Case 03:
        Test persistent data creation (dictionary interface).

        Test is passed if data persistence can be verified via both, dictionary and property interface.
        """
        global db_name
        obj1 = Cache.get_instance(db_name)
        obj1['test'] = 'test data'
        del obj1
        obj2 = Cache.get_instance(db_name)
        self.assertIn('test', obj2)
        self.assertEqual(obj2['test'], 'test data')
        self.assertTrue(hasattr(obj2, 'test'))
        self.assertEqual(obj2.test, 'test data')
        del obj2
コード例 #2
0
ファイル: test_cache.py プロジェクト: RootForum/magrathea
    def test_07(self):
        """
        Test Case 07:
        Test :py:meth:`~magrathea.core.cache.Cache.sanitize` method.

        Test is passed if :py:class:`~magrathea.core.cache.Cache` object still has the same content afterwards.
        """
        global db_name
        obj1 = Cache.get_instance(db_name)
        obj1['test'] = 'test data'
        del obj1
        obj2 = Cache.get_instance(db_name)
        obj2.sanitize()
        del obj2
        obj3 = Cache.get_instance(db_name)
        self.assertIn('test', obj3)
        del obj3
コード例 #3
0
ファイル: test_cache.py プロジェクト: RootForum/magrathea
    def test_02(self):
        """
        Test Case 02:
        Try getting a :py:class:`magrathea.core.cache.Cache` via its
        :py:meth:`~magrathea.core.cache.Cache.get_instance` method

        Test is passed if instantiated object proves being a :py:class:`magrathea.core.cache.Cache` instance.
        """
        obj = Cache.get_instance()
        self.assertIsInstance(obj, Cache)
コード例 #4
0
ファイル: test_cache.py プロジェクト: RootForum/magrathea
    def test_08(self):
        """
        Test Case 08:
        Test :py:meth:`~magrathea.core.cache.Cache.erase` method.

        Test is passed if :py:class:`~magrathea.core.cache.Cache` object is reset to an empty state.
        """
        global db_name
        obj1 = Cache.get_instance(db_name)
        obj1['test'] = 'test data'
        del obj1
        obj2 = Cache.get_instance(db_name)
        self.assertIn('test', obj2)
        obj2.erase()
        self.assertDictEqual(dict(obj2), {})
        del obj2
        obj3 = Cache.get_instance(db_name)
        self.assertEqual(dict(obj3), {})
        del obj3
コード例 #5
0
ファイル: test_cache.py プロジェクト: RootForum/magrathea
    def test_05(self):
        """
        Test Case 05:
        Test persistent data delete (dictionary interface)

        Test is passed if persistent delete can be verified by both, dictionary and property interface.
        """
        global db_name
        obj1 = Cache.get_instance(db_name)
        obj1['test'] = 'test data'
        del obj1
        obj2 = Cache.get_instance(db_name)
        self.assertIn('test', obj2)
        del obj2['test']
        self.assertNotIn('test', obj2)
        del obj2
        obj3 = Cache.get_instance(db_name)
        self.assertNotIn('test', obj3)
        self.assertFalse(hasattr(obj3, 'test'))
        del obj3
コード例 #6
0
ファイル: test_cache.py プロジェクト: RootForum/magrathea
    def test_04(self):
        """
        Test Case 04:
        Test persistent data update (dictionary interface).

        Test is passed if persistent update can be verified via both, dictionary and property interface.
        """
        global db_name
        obj1 = Cache.get_instance(db_name)
        obj1['test'] = 'test data'
        del obj1
        obj2 = Cache.get_instance(db_name)
        self.assertIn('test', obj2)
        obj2['test'] = 'other data'
        del obj2
        obj3 = Cache.get_instance(db_name)
        self.assertIn('test', obj3)
        self.assertEqual(obj3['test'], 'other data')
        self.assertTrue(hasattr(obj3, 'test'))
        self.assertEqual(obj3.test, 'other data')
        del obj3