OILS / mycpp / examples / test_globals.py View on Github | oilshell.org

62 lines, 30 significant
1#!/usr/bin/env python2
2"""
3test_globals.py
4"""
5from __future__ import print_function
6
7import os
8
9from mycpp import mylib
10from mycpp.mylib import log
11
12_ = log # this assignment is ignored
13unused = log # this too
14
15from typing import List
16
17
18class 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
29def g(x):
30 # type: (int) -> int
31 print("g %d" % x)
32 return x
33
34
35def 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
52def run_benchmarks():
53 # type: () -> None
54 raise NotImplementedError()
55
56
57if __name__ == '__main__':
58 if os.getenv('BENCHMARK'):
59 log('Benchmarking...')
60 run_benchmarks()
61 else:
62 run_tests()