2020-06-03 18:40:05 -04:00
|
|
|
# SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
|
|
|
|
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
|
2017-07-03 18:05:08 -04:00
|
|
|
#
|
2020-06-03 18:40:05 -04:00
|
|
|
# SPDX-License-Identifier: MIT
|
2017-07-03 18:05:08 -04:00
|
|
|
|
|
|
|
# This must be on one line so its skipped when built into tests.
|
|
|
|
"""This file provides helpers to detect particular running conditions and skip the test when appropriate."""
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
def skip():
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-11-16 13:33:48 -05:00
|
|
|
def always():
|
|
|
|
skip()
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
def no_reversed():
|
|
|
|
import builtins
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
if "reversed" not in dir(builtins):
|
|
|
|
skip()
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
def no_bigint():
|
|
|
|
try:
|
|
|
|
# We have to use variables because 1 << 40 causes an exception on parse and
|
|
|
|
# cannot be caught.
|
|
|
|
x = 40
|
|
|
|
x = 1 << x
|
|
|
|
except OverflowError:
|
|
|
|
skip()
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
def board_in(*board):
|
|
|
|
try:
|
|
|
|
import test_env
|
|
|
|
except ImportError:
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
class Env:
|
|
|
|
def __init__(self, board):
|
|
|
|
self.board = board
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
test_env = Env("unknown")
|
|
|
|
if test_env.board in board:
|
|
|
|
skip()
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-08-25 16:00:27 -04:00
|
|
|
def board_not_in(*board):
|
|
|
|
try:
|
|
|
|
import test_env
|
|
|
|
except ImportError:
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-08-25 16:00:27 -04:00
|
|
|
class Env:
|
|
|
|
def __init__(self, board):
|
|
|
|
self.board = board
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-08-25 16:00:27 -04:00
|
|
|
test_env = Env("unknown")
|
|
|
|
if test_env.board not in board:
|
|
|
|
skip()
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
def no_cpython_compat():
|
|
|
|
try:
|
2018-05-14 14:43:34 -04:00
|
|
|
from collections import namedtuple
|
2017-07-03 18:05:08 -04:00
|
|
|
except ImportError:
|
|
|
|
skip()
|
|
|
|
try:
|
|
|
|
T3 = namedtuple("TupComma", "foo bar")
|
|
|
|
except TypeError:
|
|
|
|
skip()
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-07-03 18:05:08 -04:00
|
|
|
def no_slice_assign():
|
|
|
|
try:
|
|
|
|
memoryview
|
|
|
|
except:
|
|
|
|
skip()
|
2021-03-15 09:57:36 -04:00
|
|
|
b1 = bytearray(b"1234")
|
|
|
|
b2 = bytearray(b"5678")
|
2017-07-03 18:05:08 -04:00
|
|
|
m1 = memoryview(b1)
|
|
|
|
m2 = memoryview(b2)
|
|
|
|
try:
|
|
|
|
m2[1:3] = m1[0:2]
|
|
|
|
except TypeError:
|
|
|
|
skip()
|
2017-11-16 13:33:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
def no_reverse_ops():
|
|
|
|
class Foo:
|
|
|
|
def __radd__(self, other):
|
|
|
|
pass
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2017-11-16 13:33:48 -05:00
|
|
|
try:
|
|
|
|
5 + Foo()
|
|
|
|
except TypeError:
|
|
|
|
skip()
|