|
1 | 1 | """ |
2 | 2 | >>> # See gcits.hf for details |
3 | 3 |
|
| 4 | +>>> # obtain an object representing the C library |
4 | 5 | >>> gci = GciLibrary() |
5 | 6 | >>> isinstance(gci, GciLibrary) |
6 | 7 | True |
7 | 8 |
|
| 9 | +>>> # simplest test to see if we have a GCI library |
8 | 10 | >>> gci.version() |
9 | | -'3.4.3 build gss64_3_4_x_branch-45183' |
| 11 | +'3.5.0 build 64bit-46205' |
10 | 12 |
|
11 | | ->>> gci.oopToChar(16668) |
| 13 | +>>> # convert a Smalltalk OOP to an ASCII character |
| 14 | +>>> gci.oopToChar(16668) # $A |
12 | 15 | 65 |
13 | 16 |
|
| 17 | +>>> # this OOP is not a valid character |
14 | 18 | >>> gci.oopToChar(16667) |
15 | 19 | -1 |
16 | 20 |
|
17 | 21 | >>> gci.oopToChar(24860) # $a |
18 | 22 | 97 |
19 | 23 |
|
20 | | ->>> gci.charToOop(65) |
| 24 | +>>> # convert an ASCII code point to a Smalltalk OOP |
| 25 | +>>> gci.charToOop(65) # $A |
21 | 26 | 16668 |
22 | 27 |
|
23 | 28 | >>> gci.charToOop(97) # $a |
24 | 29 | 24860 |
25 | 30 |
|
| 31 | +>>> # we can convert Unicode as well |
26 | 32 | >>> gci.charToOop(1114111) |
27 | 33 | 285212444 |
28 | 34 |
|
| 35 | +>>> # this is not a valid character, so get back OOP_INVALID (1) |
29 | 36 | >>> gci.charToOop(1114112) |
30 | 37 | 1 |
31 | 38 |
|
| 39 | +>>> # convert a double to a Smalltalk OOP |
32 | 40 | >>> try: |
33 | 41 | ... gci.doubleToSmallDouble(1.0) |
34 | 42 | ... except InvalidArgumentError: |
35 | 43 | ... "InvalidArgumentError" |
36 | 44 | 9151314442816847878 |
37 | 45 |
|
| 46 | +>>> # demonstrate that we can properly handle exceptions |
38 | 47 | >>> try: |
39 | 48 | ... gci.doubleToSmallDouble(1e40) |
40 | 49 | ... except InvalidArgumentError: |
|
47 | 56 | >>> gci.I32ToOop(55) |
48 | 57 | 442 |
49 | 58 |
|
| 59 | +>>> # expect an exception for a bad login argument |
50 | 60 | >>> try: |
51 | 61 | ... gci.login(gem_host=gem_host, netldi='badldi', stone='badstone') |
52 | 62 | ... except GciException as ex: |
|
65 | 75 | ... ex.number() # invalid user/password |
66 | 76 | 4051 |
67 | 77 |
|
| 78 | +>>> # using the provided login info we should be successful |
68 | 79 | >>> session = gci.login(gem_host=gem_host, netldi=netldi, stone=stone, gs_user=gs_user, gs_password=gs_password) |
69 | 80 | >>> isinstance(session, int) # successful login |
70 | 81 | True |
71 | 82 |
|
72 | 83 | >>> gci.is_session_valid(session) |
73 | 84 | True |
74 | 85 |
|
| 86 | +>>> # do a name lookup of an object (with a well-known OOP) |
75 | 87 | >>> symbolName = 'Globals' |
76 | 88 | >>> try: |
77 | 89 | ... gci.resolveSymbol(session, symbolName) |
|
86 | 98 | ... ex.number() |
87 | 99 | 2101 |
88 | 100 |
|
| 101 | +>>> # the following should quietly succeed |
89 | 102 | >>> try: |
90 | 103 | ... gci.abort(session) |
91 | 104 | ... except GciException as ex: |
|
101 | 114 | ... except GciException as ex: |
102 | 115 | ... ex.number() |
103 | 116 |
|
| 117 | +>>> # logout should not error |
104 | 118 | >>> try: |
105 | 119 | ... gci.logout(session) |
106 | 120 | ... except GciException as ex: |
107 | 121 | ... ex.number() # invalid session |
108 | 122 |
|
| 123 | +>>> # session should no longer be valid |
109 | 124 | >>> gci.is_session_valid(session) |
110 | 125 | False |
111 | 126 |
|
| 127 | +>>> # subsequent logout attempts should fail |
112 | 128 | >>> try: |
113 | 129 | ... gci.logout(session) |
114 | 130 | ... except GciException as ex: |
|
137 | 153 |
|
138 | 154 | if __name__ == '__main__': |
139 | 155 | import os |
| 156 | + # Create a local login file that is not under version control |
140 | 157 | if (not os.path.isfile('GciLogin.py')): |
141 | 158 | import shutil |
142 | 159 | shutil.copy2('GciDefault.py', 'GciLogin.py') |
| 160 | + # Import interesting things from GciLibrary |
143 | 161 | from GciLibrary import GciLibrary, GciException, InvalidArgumentError |
| 162 | + # Get local login information (not under version control) |
144 | 163 | from GciLogin import * |
| 164 | + # Import testing framework |
145 | 165 | import doctest |
146 | 166 | print('Start tests') |
| 167 | + # Run tests shown in docstring above |
147 | 168 | doctest.testmod() |
148 | 169 | print('End tests') |
0 commit comments