| 1 | #!/usr/bin/env python2
|
| 2 | """
|
| 3 | test_default_args.py
|
| 4 | """
|
| 5 | from __future__ import print_function
|
| 6 |
|
| 7 | import os
|
| 8 |
|
| 9 | from mycpp.mylib import log
|
| 10 |
|
| 11 | from typing import List
|
| 12 |
|
| 13 |
|
| 14 | def f(x, b=False):
|
| 15 | # type: (int, bool) -> None
|
| 16 | log("x = %d", x)
|
| 17 | log("b = %d", b)
|
| 18 |
|
| 19 |
|
| 20 | def g(x, s=''):
|
| 21 | # type: (int, str) -> None
|
| 22 | log("x = %d", x)
|
| 23 | log("s = %r", s)
|
| 24 |
|
| 25 |
|
| 26 | class Foo(object):
|
| 27 |
|
| 28 | def __init__(self, x, y=42):
|
| 29 | # type: (int, int) -> None
|
| 30 | self.x = x
|
| 31 | self.y = y
|
| 32 |
|
| 33 | def Print(self):
|
| 34 | # type: () -> None
|
| 35 | log("x = %d", self.x)
|
| 36 | log("y = %d", self.y)
|
| 37 |
|
| 38 |
|
| 39 | def run_tests():
|
| 40 | # type: () -> None
|
| 41 |
|
| 42 | f(5)
|
| 43 | f(6, True)
|
| 44 | f(7, b=True)
|
| 45 |
|
| 46 | g(99, s='foo')
|
| 47 |
|
| 48 | f1 = Foo(8)
|
| 49 | f2 = Foo(9, 43)
|
| 50 | f3 = Foo(0, y=44)
|
| 51 |
|
| 52 | f1.Print()
|
| 53 | f2.Print()
|
| 54 | f3.Print()
|
| 55 |
|
| 56 | # TODO: Remove all the extra GLOBAL_STR() instances for log() and % !
|
| 57 |
|
| 58 | print("const")
|
| 59 | print("print formatted = %d" % True)
|
| 60 |
|
| 61 | log("const")
|
| 62 | log("log formatted = %d", True)
|
| 63 |
|
| 64 |
|
| 65 | def run_benchmarks():
|
| 66 | # type: () -> None
|
| 67 | raise NotImplementedError()
|
| 68 |
|
| 69 |
|
| 70 | if __name__ == '__main__':
|
| 71 | if os.getenv('BENCHMARK'):
|
| 72 | log('Benchmarking...')
|
| 73 | run_benchmarks()
|
| 74 | else:
|
| 75 | run_tests()
|