Пример #1
0
    def test_init(self):

        d = DictionaryDogma('CF', {}, None)
        self.assertEqual(d._religion, 'CF')
        self.assertEqual(d._beliefs, {})
        self.assertEqual(d._dataObject, {})
        self.assertEqual(d.__class__.__name__, 'CFDictionaryDogma')

        d = DictionaryDogma('CF', {})
        self.assertEqual(d._dataObject, {})

        d = DictionaryDogma('CF', {}, {'gi': 'joe'})
        self.assertEqual(d._dataObject, {'gi': 'joe'})
Пример #2
0
    def test_dogma_get(self):

        beliefs = {'foo':'bar','bat':'baz'}
        d = DictionaryDogma('CF',beliefs,{'bar':'boo'})

        self.assertEqual(d._get('bar'),'boo')
        with self.assertRaises(KeyError):
            d._get('bzzz')

        self.assertEqual(d.foo, 'boo')

        with self.assertRaises(AttributeError):
            d.not_an_att

        with self.assertRaises(DogmaGetterSetterException):
            d.bat
Пример #3
0
    def test_dogma_get(self):

        beliefs = {'foo': 'bar', 'bat': 'baz'}
        d = DictionaryDogma('CF', beliefs, {'bar': 'boo'})

        self.assertEqual(d._get('bar'), 'boo')
        with self.assertRaises(KeyError):
            d._get('bzzz')

        self.assertEqual(d.foo, 'boo')

        with self.assertRaises(AttributeError):
            d.not_an_att

        with self.assertRaises(DogmaGetterSetterException):
            d.bat
Пример #4
0
    def test_dogma_del(self):

        beliefs = {'foo':'bar','bat':'baz'}
        d = DictionaryDogma('CF',beliefs,{'bar':'boo'})

        self.assertEqual(d._dataObject.get('bar'),'boo')
        d._del('bar')
        self.assertEqual(d._dataObject.get('bar'),None)

        d._dataObject['bar'] = 'bamboo'
        self.assertEqual(d.foo, 'bamboo')
        del d.foo

        self.assertEqual(d._dataObject.get('bar'), None)

        with self.assertRaises(DogmaGetterSetterException):
            d.foo

        # Call it again!
        with self.assertRaises(DogmaDeleteException):
            del d.foo

        with self.assertRaises(AttributeError):
            del d.not_an_att
Пример #5
0
    def test_dogma_del(self):

        beliefs = {'foo': 'bar', 'bat': 'baz'}
        d = DictionaryDogma('CF', beliefs, {'bar': 'boo'})

        self.assertEqual(d._dataObject.get('bar'), 'boo')
        d._del('bar')
        self.assertEqual(d._dataObject.get('bar'), None)

        d._dataObject['bar'] = 'bamboo'
        self.assertEqual(d.foo, 'bamboo')
        del d.foo

        self.assertEqual(d._dataObject.get('bar'), None)

        with self.assertRaises(DogmaGetterSetterException):
            d.foo

        # Call it again!
        with self.assertRaises(DogmaDeleteException):
            del d.foo

        with self.assertRaises(AttributeError):
            del d.not_an_att
Пример #6
0
    def test_dogma_validate_teaching(self):

        beliefs = {'foo': 'bar', 'bat': 'baz'}
        d = DictionaryDogma('CF', beliefs, None)

        ret = d._validate_teaching('foo', 'bar')
        assert_is(ret, 'bar')

        DictionaryDogma._validate_teaching('foo', 'bar')
        assert_is(ret, 'bar')

        with assert_raises_regexp(DictionaryDogmaException, """The belief """):
            ret = d._validate_teaching('foo', [])

        with assert_raises_regexp(DictionaryDogmaException, """The belief """):
            beliefs = {'foo': [], 'bat': 'baz'}
            d = DictionaryDogma('CF', beliefs, None)
Пример #7
0
    def test_dogma_set(self):

        beliefs = {'foo': 'bar', 'bat': 'baz'}
        d = DictionaryDogma('CF', beliefs)

        self.assertEqual(d._dataObject.get('bar'), None)
        d._set('bar', 'bizzar!')
        self.assertEqual(d._dataObject.get('bar'), 'bizzar!')

        d = DictionaryDogma('CF', beliefs)
        self.assertEqual(d._dataObject.get('bar'), None)
        d.foo = 'how bizzar!'
        self.assertEqual(d._dataObject.get('bar'), 'how bizzar!')

        with self.assertRaisesRegexp(
                AttributeError,
                """Blasphemy! You can't create the new beliefs"""):
            d.not_an_att = 5
Пример #8
0
    def test_dogma_set(self):

        beliefs = {'foo':'bar','bat':'baz'}
        d = DictionaryDogma('CF',beliefs)

        self.assertEqual(d._dataObject.get('bar'),None)
        d._set('bar','bizzar!')
        self.assertEqual(d._dataObject.get('bar'),'bizzar!')

        d = DictionaryDogma('CF',beliefs)
        self.assertEqual(d._dataObject.get('bar'),None)
        d.foo = 'how bizzar!'
        self.assertEqual(d._dataObject.get('bar'),'how bizzar!')

        with self.assertRaisesRegexp(AttributeError,"""Blasphemy! You can't create the new beliefs"""):
            d.not_an_att = 5
Пример #9
0
    def test_dogma_validate_teaching(self):

        beliefs = {'foo':'bar','bat':'baz'}
        d = DictionaryDogma('CF',beliefs,None)

        ret = d._validate_teaching('foo','bar')
        self.assertIs(ret, 'bar')

        DictionaryDogma._validate_teaching('foo','bar')
        self.assertIs(ret, 'bar')

        with self.assertRaisesRegexp(DictionaryDogmaException,"""The belief """):
            ret = d._validate_teaching('foo',[])


        with self.assertRaisesRegexp(DictionaryDogmaException,"""The belief """):
            beliefs = {'foo':[],'bat':'baz'}
            d = DictionaryDogma('CF',beliefs,None)