~ed.so/duplicity/reuse-passphrase-for-signing-fix

« back to all changes in this revision

Viewing changes to testing/statictest.py

  • Committer: bescoto
  • Date: 2002-10-29 01:49:46 UTC
  • Revision ID: vcs-imports@canonical.com-20021029014946-3m4rmm5plom7pl6q
Initial checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest, types, sys
 
2
sys.path.insert(0, "../src")
 
3
from static import *
 
4
 
 
5
 
 
6
class D:
 
7
        def foo(x, y):
 
8
                return x, y
 
9
        def bar(self, x):
 
10
                return 3, x
 
11
        def _hello(self):
 
12
                return self
 
13
 
 
14
MakeStatic(D)
 
15
 
 
16
 
 
17
class C:
 
18
        _a = 0
 
19
        def get(cls):
 
20
                return cls._a
 
21
        def inc(cls):
 
22
                cls._a = cls._a + 1
 
23
 
 
24
MakeClass(C)
 
25
 
 
26
 
 
27
class StaticMethodsTest(unittest.TestCase):
 
28
        """Test StaticMethods module"""
 
29
        def testType(self):
 
30
                """Methods should have type StaticMethod"""
 
31
                assert type(D.foo) is types.FunctionType
 
32
                assert type(D.bar) is types.FunctionType
 
33
 
 
34
        def testStatic(self):
 
35
                """Methods should be callable without instance"""
 
36
                assert D.foo(1,2) == (1,2)
 
37
                assert D.bar(3,4) == (3,4)
 
38
 
 
39
        def testBound(self):
 
40
                """Methods should also work bound"""
 
41
                d = D()
 
42
                assert d.foo(1,2) == (1,2)
 
43
                assert d.bar(3,4) == (3,4)
 
44
 
 
45
        def testStatic_(self):
 
46
                """_ Methods should be untouched"""
 
47
                d = D()
 
48
                self.assertRaises(TypeError, d._hello, 4)
 
49
                assert d._hello() is d
 
50
 
 
51
 
 
52
class ClassMethodsTest(unittest.TestCase):
 
53
        def test(self):
 
54
                """Test MakeClass function"""
 
55
                assert C.get() == 0
 
56
                C.inc()
 
57
                assert C.get() == 1
 
58
                C.inc()
 
59
                assert C.get() == 2
 
60
        
 
61
 
 
62
if __name__ == "__main__":
 
63
        unittest.main()