1 | #!/usr/bin/env python2
|
2 | """
|
3 | test_globals.py
|
4 | """
|
5 | from __future__ import print_function
|
6 |
|
7 | import os
|
8 |
|
9 | from mycpp import mylib
|
10 | from mycpp.mylib import log
|
11 |
|
12 | _ = log # this assignment is ignored
|
13 | unused = log # this too
|
14 |
|
15 | from typing import List
|
16 |
|
17 |
|
18 | class MyClass(object):
|
19 |
|
20 | def __init__(self, x):
|
21 | # type: (int) -> None
|
22 | self.x = x
|
23 |
|
24 | def Print(self):
|
25 | # type: () -> None
|
26 | log("x = %d", self.x)
|
27 |
|
28 |
|
29 | def g(x):
|
30 | # type: (int) -> int
|
31 | print("g %d" % x)
|
32 | return x
|
33 |
|
34 |
|
35 | def run_tests():
|
36 | # type: () -> None
|
37 |
|
38 | for i in xrange(10):
|
39 | mylib.MaybeCollect()
|
40 |
|
41 | new_obj = MyClass(42)
|
42 | new_obj.Print()
|
43 |
|
44 | for j in xrange(3):
|
45 | # _ = g(j) # hm doesn't work
|
46 |
|
47 | # This satisfies lint, the type checker, and is translated correctly by
|
48 | # mycpp
|
49 | unused = g(j)
|
50 |
|
51 |
|
52 | def run_benchmarks():
|
53 | # type: () -> None
|
54 | raise NotImplementedError()
|
55 |
|
56 |
|
57 | if __name__ == '__main__':
|
58 | if os.getenv('BENCHMARK'):
|
59 | log('Benchmarking...')
|
60 | run_benchmarks()
|
61 | else:
|
62 | run_tests()
|