aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/sqlalchemy_migrate-0.7.2-py2.7.egg/migrate/tests/versioning/test_keyedinstance.py
blob: b2f87ac4b8feaa3f8a2f8365b82fa43aba72505c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
# -*- coding: utf-8 -*-

from migrate.tests import fixture
from migrate.versioning.util.keyedinstance import *

class TestKeydInstance(fixture.Base):
    def test_unique(self):
        """UniqueInstance should produce unique object instances"""
        class Uniq1(KeyedInstance):
            @classmethod
            def _key(cls,key):
                return str(key)
            def __init__(self,value):
                self.value=value
        class Uniq2(KeyedInstance):
            @classmethod
            def _key(cls,key):
                return str(key)
            def __init__(self,value):
                self.value=value
        
        a10 = Uniq1('a')

        # Different key: different instance
        b10 = Uniq1('b')
        self.assert_(a10 is not b10)

        # Different class: different instance
        a20 = Uniq2('a')
        self.assert_(a10 is not a20)

        # Same key/class: same instance
        a11 = Uniq1('a')
        self.assert_(a10 is a11)

        # __init__ is called
        self.assertEquals(a10.value,'a')

        # clear() causes us to forget all existing instances
        Uniq1.clear()
        a12 = Uniq1('a')
        self.assert_(a10 is not a12)

        self.assertRaises(NotImplementedError, KeyedInstance._key)