/usr/lib/python2.7/dist-packages/migrate/tests/versioning/test_keyedinstance.py is in python-migrate 0.10.0-3ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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.assertTrue(a10 is not b10)
# Different class: different instance
a20 = Uniq2('a')
self.assertTrue(a10 is not a20)
# Same key/class: same instance
a11 = Uniq1('a')
self.assertTrue(a10 is a11)
# __init__ is called
self.assertEqual(a10.value,'a')
# clear() causes us to forget all existing instances
Uniq1.clear()
a12 = Uniq1('a')
self.assertTrue(a10 is not a12)
self.assertRaises(NotImplementedError, KeyedInstance._key)
|