diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basics/exceptpoly.py | 380 | ||||
-rw-r--r-- | tests/basics/floordivide.py | 29 | ||||
-rw-r--r-- | tests/basics/generator-exc.py | 53 | ||||
-rw-r--r-- | tests/basics/math-fun-bool.py | 12 | ||||
-rw-r--r-- | tests/basics/math-fun.py | 9 | ||||
-rw-r--r-- | tests/basics/modulo.py | 36 |
6 files changed, 513 insertions, 6 deletions
diff --git a/tests/basics/exceptpoly.py b/tests/basics/exceptpoly.py new file mode 100644 index 0000000000..0e5ac2d1a3 --- /dev/null +++ b/tests/basics/exceptpoly.py @@ -0,0 +1,380 @@ +try: + raise ArithmeticError +except Exception: + print("Caught ArithmeticError via Exception") + +try: + raise ArithmeticError +except ArithmeticError: + print("Caught ArithmeticError") + +try: + raise AssertionError +except Exception: + print("Caught AssertionError via Exception") + +try: + raise AssertionError +except AssertionError: + print("Caught AssertionError") + +try: + raise AttributeError +except Exception: + print("Caught AttributeError via Exception") + +try: + raise AttributeError +except AttributeError: + print("Caught AttributeError") + +try: + raise BufferError +except Exception: + print("Caught BufferError via Exception") + +try: + raise BufferError +except BufferError: + print("Caught BufferError") + +try: + raise BytesWarning +except Warning: + print("Caught BytesWarning via Warning") + +try: + raise BytesWarning +except BytesWarning: + print("Caught BytesWarning") + +try: + raise DeprecationWarning +except Warning: + print("Caught DeprecationWarning via Warning") + +try: + raise DeprecationWarning +except DeprecationWarning: + print("Caught DeprecationWarning") + +try: + raise EOFError +except Exception: + print("Caught EOFError via Exception") + +try: + raise EOFError +except EOFError: + print("Caught EOFError") + +try: + raise EnvironmentError +except Exception: + print("Caught EnvironmentError via Exception") + +try: + raise EnvironmentError +except EnvironmentError: + print("Caught EnvironmentError") + +try: + raise Exception +except BaseException: + print("Caught Exception via BaseException") + +try: + raise Exception +except Exception: + print("Caught Exception") + +try: + raise FloatingPointError +except ArithmeticError: + print("Caught FloatingPointError via ArithmeticError") + +try: + raise FloatingPointError +except FloatingPointError: + print("Caught FloatingPointError") + +try: + raise FutureWarning +except Warning: + print("Caught FutureWarning via Warning") + +try: + raise FutureWarning +except FutureWarning: + print("Caught FutureWarning") + +try: + raise IOError +except Exception: + print("Caught IOError via Exception") + +try: + raise IOError +except IOError: + print("Caught IOError") + +try: + raise ImportError +except Exception: + print("Caught ImportError via Exception") + +try: + raise ImportError +except ImportError: + print("Caught ImportError") + +try: + raise ImportWarning +except Warning: + print("Caught ImportWarning via Warning") + +try: + raise ImportWarning +except ImportWarning: + print("Caught ImportWarning") + +try: + raise IndentationError +except SyntaxError: + print("Caught IndentationError via SyntaxError") + +try: + raise IndentationError +except IndentationError: + print("Caught IndentationError") + +try: + raise IndexError +except LookupError: + print("Caught IndexError via LookupError") + +try: + raise IndexError +except IndexError: + print("Caught IndexError") + +try: + raise KeyError +except LookupError: + print("Caught KeyError via LookupError") + +try: + raise KeyError +except KeyError: + print("Caught KeyError") + +try: + raise LookupError +except Exception: + print("Caught LookupError via Exception") + +try: + raise LookupError +except LookupError: + print("Caught LookupError") + +try: + raise MemoryError +except Exception: + print("Caught MemoryError via Exception") + +try: + raise MemoryError +except MemoryError: + print("Caught MemoryError") + +try: + raise NameError +except Exception: + print("Caught NameError via Exception") + +try: + raise NameError +except NameError: + print("Caught NameError") + +try: + raise NotImplementedError +except RuntimeError: + print("Caught NotImplementedError via RuntimeError") + +try: + raise NotImplementedError +except NotImplementedError: + print("Caught NotImplementedError") + +try: + raise OSError +except Exception: + print("Caught OSError via Exception") + +try: + raise OSError +except OSError: + print("Caught OSError") + +try: + raise OverflowError +except ArithmeticError: + print("Caught OverflowError via ArithmeticError") + +try: + raise OverflowError +except OverflowError: + print("Caught OverflowError") + +try: + raise PendingDeprecationWarning +except Warning: + print("Caught PendingDeprecationWarning via Warning") + +try: + raise PendingDeprecationWarning +except PendingDeprecationWarning: + print("Caught PendingDeprecationWarning") + +try: + raise ReferenceError +except Exception: + print("Caught ReferenceError via Exception") + +try: + raise ReferenceError +except ReferenceError: + print("Caught ReferenceError") + +try: + raise ResourceWarning +except Warning: + print("Caught ResourceWarning via Warning") + +try: + raise ResourceWarning +except ResourceWarning: + print("Caught ResourceWarning") + +try: + raise RuntimeError +except Exception: + print("Caught RuntimeError via Exception") + +try: + raise RuntimeError +except RuntimeError: + print("Caught RuntimeError") + +try: + raise RuntimeWarning +except Warning: + print("Caught RuntimeWarning via Warning") + +try: + raise RuntimeWarning +except RuntimeWarning: + print("Caught RuntimeWarning") + +try: + raise SyntaxError +except Exception: + print("Caught SyntaxError via Exception") + +try: + raise SyntaxError +except SyntaxError: + print("Caught SyntaxError") + +try: + raise SyntaxWarning +except Warning: + print("Caught SyntaxWarning via Warning") + +try: + raise SyntaxWarning +except SyntaxWarning: + print("Caught SyntaxWarning") + +try: + raise SystemError +except Exception: + print("Caught SystemError via Exception") + +try: + raise SystemError +except SystemError: + print("Caught SystemError") + +try: + raise TabError +except IndentationError: + print("Caught TabError via IndentationError") + +try: + raise TabError +except TabError: + print("Caught TabError") + +try: + raise TypeError +except Exception: + print("Caught TypeError via Exception") + +try: + raise TypeError +except TypeError: + print("Caught TypeError") + +try: + raise UnboundLocalError +except NameError: + print("Caught UnboundLocalError via NameError") + +try: + raise UnboundLocalError +except UnboundLocalError: + print("Caught UnboundLocalError") + +try: + raise UserWarning +except Warning: + print("Caught UserWarning via Warning") + +try: + raise UserWarning +except UserWarning: + print("Caught UserWarning") + +try: + raise ValueError +except Exception: + print("Caught ValueError via Exception") + +try: + raise ValueError +except ValueError: + print("Caught ValueError") + +try: + raise Warning +except Exception: + print("Caught Warning via Exception") + +try: + raise Warning +except Warning: + print("Caught Warning") + +try: + raise ZeroDivisionError +except ArithmeticError: + print("Caught ZeroDivisionError via ArithmeticError") + +try: + raise ZeroDivisionError +except ZeroDivisionError: + print("Caught ZeroDivisionError") + diff --git a/tests/basics/floordivide.py b/tests/basics/floordivide.py new file mode 100644 index 0000000000..930313d6c1 --- /dev/null +++ b/tests/basics/floordivide.py @@ -0,0 +1,29 @@ +# check modulo matches python definition + +# This tests compiler version +print(123 // 7) +print(-123 // 7) +print(123 // -7) +print(-123 // -7) + +a = 10000001 +b = 10000000 +print(a // b) +print(a // -b) +print(-a // b) +print(-a // -b) + +if True: + a = 987654321987987987987987987987 + b = 19 + + print(a // b) + print(a // -b) + print(-a // b) + print(-a // -b) + a = 10000000000000000000000000000000000000000000 + b = 100 + print(a // b) + print(a // -b) + print(-a // b) + print(-a // -b) diff --git a/tests/basics/generator-exc.py b/tests/basics/generator-exc.py new file mode 100644 index 0000000000..09aca5d9a0 --- /dev/null +++ b/tests/basics/generator-exc.py @@ -0,0 +1,53 @@ +# Test proper handling of exceptions within generator across yield +def gen(): + try: + yield 1 + raise ValueError + except ValueError: + print("Caught") + yield 2 + +for i in gen(): + print(i) + + +# Test throwing exceptions out of generator +def gen2(): + yield 1 + raise ValueError + yield 2 + yield 3 + +g = gen2() +print(next(g)) +try: + print(next(g)) +except ValueError: + print("ValueError") + +try: + print(next(g)) +except StopIteration: + print("StopIteration") + + +# Test throwing exception into generator +def gen3(): + yield 1 + try: + yield 2 + except ValueError: + print("ValueError received") + yield 3 + yield 4 + yield 5 + +g = gen3() +print(next(g)) +print(next(g)) +print("out of throw:", g.throw(ValueError)) +print(next(g)) +try: + print("out of throw2:", g.throw(ValueError)) +except ValueError: + print("Boomerang ValueError caught") diff --git a/tests/basics/math-fun-bool.py b/tests/basics/math-fun-bool.py new file mode 100644 index 0000000000..cf718d4b80 --- /dev/null +++ b/tests/basics/math-fun-bool.py @@ -0,0 +1,12 @@ +# Test the bool functions from math + +from math import isfinite, isnan, isinf + +test_values = [1, 0, -1, 1.0, 0.0, -1.0, float('NaN'), float('Inf'), + -float('NaN'), -float('Inf')] + +functions = [isfinite, isnan, isinf] + +for val in test_values: + for f in functions: + print(f(val)) diff --git a/tests/basics/math-fun.py b/tests/basics/math-fun.py index f5ffbf40d5..1301dc2a5b 100644 --- a/tests/basics/math-fun.py +++ b/tests/basics/math-fun.py @@ -5,8 +5,6 @@ from math import * test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.] p_test_values = [0.1, 0.5, 1.23456] unit_range_test_values = [-1., -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.] -#IEEE_test_values = [1, 0, float('NaN'), float('Inf'), -float('NaN'), -float('Inf')] -#TODO: float('NaN') functions = [(sqrt, p_test_values), (exp, test_values), @@ -30,7 +28,6 @@ functions = [(sqrt, p_test_values), (fabs, test_values), (floor, test_values), #(frexp, test_values), - #(isfinite, [1, 0, float('NaN'), float('Inf')]) (trunc, test_values) ] @@ -42,8 +39,8 @@ binary_functions = [(copysign, [(23., 42.), (-23., 42.), (23., -42.), (-23., -42.), (1., 0.0), (1., -0.0)]) ] -#for function, test_vals in binary_functions: -# for value1, value2 in test_vals: -# print("{:8.7f}".format(function(value1, value2))) +for function, test_vals in binary_functions: + for value1, value2 in test_vals: + print("{:8.7f}".format(function(value1, value2))) diff --git a/tests/basics/modulo.py b/tests/basics/modulo.py new file mode 100644 index 0000000000..4d83db6ec8 --- /dev/null +++ b/tests/basics/modulo.py @@ -0,0 +1,36 @@ +# check modulo matches python definition +# This test compiler version +print(123 % 7) +print(-123 % 7) +print(123 % -7) +print(-123 % -7) + +a = 321 +b = 19 +print(a % b) +print(a % -b) +print(-a % b) +print(-a % -b) + + +a = 987654321987987987987987987987 +b = 19 + +print(a % b) +print(a % -b) +print(-a % b) +print(-a % -b) + +if False: + print(1.23456 % 0.7) + print(-1.23456 % 0.7) + print(1.23456 % -0.7) + print(-1.23456 % -0.7) + + a = 1.23456 + b = 0.7 + print(a % b) + print(a % -b) + print(-a % b) + print(-a % -b) + |