~ubuntu-branches/ubuntu/quantal/python-gevent/quantal

« back to all changes in this revision

Viewing changes to greentest/test__local.py

  • Committer: Bazaar Package Importer
  • Author(s): Örjan Persson
  • Date: 2011-05-17 16:43:20 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110517164320-nwhld2xo6sz58p4m
Tags: 0.13.6-1
New upstream version (Closes: #601863).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest
 
2
from copy import copy
 
3
# Comment the line below to see that the standard thread.local is working correct
 
4
from gevent import monkey; monkey.patch_all()
 
5
 
 
6
 
 
7
from threading import local
 
8
class A(local):
 
9
    __slots__ = ['initialized','obj']
 
10
 
 
11
    path = ''
 
12
    def __init__(self, obj):
 
13
        if not  hasattr(self, 'initialized'):
 
14
            self.obj = obj
 
15
        self.path = ''
 
16
 
 
17
class Obj(object):
 
18
    pass
 
19
 
 
20
class GeventLocalTestCase(unittest.TestCase):
 
21
 
 
22
    def test_copy(self):
 
23
        a = A(Obj())
 
24
        a.path = '123'
 
25
        a.obj.echo = 'test'
 
26
        b = copy(a)
 
27
        """
 
28
        Copy makes a shallow copy. Meaning that the attribute path
 
29
        has to be independent in the original and the copied object because the
 
30
        value is a string, but the attribute obj should be just reference to
 
31
        the instance of the class Obj
 
32
        """
 
33
        self.assertEqual(a.path, b.path, 'The values in the two objects must be equal')
 
34
        self.assertEqual(a.obj, b.obj, 'The values must be equal')
 
35
 
 
36
        b.path = '321'
 
37
        self.assertNotEqual(a.path, b.path, 'The values in the two objects must be different')
 
38
 
 
39
        a.obj.echo = "works"
 
40
        self.assertEqual(a.obj, b.obj, 'The values must be equal')
 
41
 
 
42
    def test_objects(self):
 
43
        """
 
44
        Test which failed in the eventlet?!
 
45
        """
 
46
        a = A({})
 
47
        a.path = '123'
 
48
        b = A({'one':2})
 
49
        b.path = '123'
 
50
        self.assertEqual(a.path, b.path, 'The values in the two objects must be equal')
 
51
 
 
52
        b.path = '321'
 
53
 
 
54
        self.assertNotEqual(a.path, b.path, 'The values in the two objects must be different')
 
55
 
 
56
if __name__ == '__main__':
 
57
    unittest.main()