| 1 | #!/usr/bin/env python2
 | 
| 2 | """
 | 
| 3 | conditional.py
 | 
| 4 | """
 | 
| 5 | from __future__ import print_function
 | 
| 6 | 
 | 
| 7 | import os
 | 
| 8 | import sys
 | 
| 9 | 
 | 
| 10 | from typing import List
 | 
| 11 | 
 | 
| 12 | from mycpp import mylib
 | 
| 13 | from mycpp.mylib import log
 | 
| 14 | 
 | 
| 15 | 
 | 
| 16 | def run_tests():
 | 
| 17 |     # type: () -> None
 | 
| 18 | 
 | 
| 19 |     # NOTE: Output is meant to be inspected
 | 
| 20 |     if mylib.CPP:
 | 
| 21 |         log('CPP')
 | 
| 22 |     else:
 | 
| 23 |         log('CPP')
 | 
| 24 | 
 | 
| 25 |     if mylib.PYTHON:
 | 
| 26 |         log('PYTHON')
 | 
| 27 |     else:
 | 
| 28 |         log('PYTHON')
 | 
| 29 | 
 | 
| 30 |     if 0:
 | 
| 31 |         log('ZERO')
 | 
| 32 | 
 | 
| 33 |     log('int = %d', int('123'))
 | 
| 34 |     log('bool = %d', bool(42))
 | 
| 35 | 
 | 
| 36 |     mylist = []  # type: List[int]
 | 
| 37 | 
 | 
| 38 |     #if mylist:  # translation time error
 | 
| 39 |     if len(mylist):
 | 
| 40 |         print('mylist')
 | 
| 41 | 
 | 
| 42 |     # translation error
 | 
| 43 |     #x = 1 if mylist else 2
 | 
| 44 |     x = 1 if len(mylist) else 2
 | 
| 45 | 
 | 
| 46 |     log("x = %d", x)
 | 
| 47 | 
 | 
| 48 |     # Expressions where parens are needed
 | 
| 49 |     a = False
 | 
| 50 |     if a and (False or True):
 | 
| 51 |         print('yes')
 | 
| 52 |     else:
 | 
| 53 |         print('no')
 | 
| 54 | 
 | 
| 55 | 
 | 
| 56 | def run_benchmarks():
 | 
| 57 |     # type: () -> None
 | 
| 58 |     raise NotImplementedError()
 | 
| 59 | 
 | 
| 60 | 
 | 
| 61 | if __name__ == '__main__':
 | 
| 62 |     if os.getenv('BENCHMARK'):
 | 
| 63 |         log('Benchmarking...')
 | 
| 64 |         run_benchmarks()
 | 
| 65 |     else:
 | 
| 66 |         run_tests()
 |