|
| 1 | +"""Define types.""" |
| 2 | + |
| 3 | +import enum |
| 4 | + |
| 5 | +import numpy as np |
| 6 | +from nitypes.scalar import Scalar |
| 7 | +from nitypes.waveform import AnalogWaveform |
| 8 | + |
| 9 | + |
| 10 | +class MyIntFlags(enum.IntFlag): |
| 11 | + """Example of an IntFlag enum.""" |
| 12 | + |
| 13 | + VALUE1 = 1 |
| 14 | + VALUE2 = 2 |
| 15 | + VALUE4 = 4 |
| 16 | + |
| 17 | + |
| 18 | +class MyIntEnum(enum.IntEnum): |
| 19 | + """Example of an IntEnum enum.""" |
| 20 | + |
| 21 | + VALUE10 = 10 |
| 22 | + VALUE20 = 20 |
| 23 | + VALUE30 = 30 |
| 24 | + |
| 25 | + |
| 26 | +class MyStrEnum(str, enum.Enum): |
| 27 | + """Example of a mixin string enum.""" |
| 28 | + |
| 29 | + VALUE1 = "value1" |
| 30 | + VALUE2 = "value2" |
| 31 | + VALUE3 = "value3" |
| 32 | + |
| 33 | + |
| 34 | +all_types_with_values = { |
| 35 | + # supported scalar types |
| 36 | + "bool": True, |
| 37 | + "bytes": b"robotext", |
| 38 | + "float": 13.12, |
| 39 | + "int": 42, |
| 40 | + "str": "sample string", |
| 41 | + # supported collection types |
| 42 | + "bool_collection": [True, False, True], |
| 43 | + "bytes_collection": [b"one", b"two", b"three"], |
| 44 | + "float_collection": [1.1, 2.2, 3.3], |
| 45 | + "int_collection": [1, 2, 3], |
| 46 | + "str_collection": ["one", "two", "three"], |
| 47 | + # supported enum and flag types |
| 48 | + "intflags": MyIntFlags.VALUE1 | MyIntFlags.VALUE4, |
| 49 | + "intenum": MyIntEnum.VALUE20, |
| 50 | + "strenum": MyStrEnum.VALUE3, |
| 51 | + "intflags_collection": [MyIntFlags.VALUE1, MyIntFlags.VALUE2, MyIntFlags.VALUE4], |
| 52 | + "intenum_collection": [MyIntEnum.VALUE10, MyIntEnum.VALUE20, MyIntEnum.VALUE30], |
| 53 | + "strenum_collection": [MyStrEnum.VALUE1, MyStrEnum.VALUE2, MyStrEnum.VALUE3], |
| 54 | + # supported collections |
| 55 | + "list": [1, 2, 3], |
| 56 | + "tuple": (4, 5, 6), |
| 57 | + "set": {7, 8, 9}, |
| 58 | + "frozenset": frozenset([10, 11, 12]), |
| 59 | + # NI types |
| 60 | + "nitypes_Scalar": Scalar(42, "m"), |
| 61 | + "nitypes_AnalogWaveform": AnalogWaveform.from_array_1d(np.array([1.0, 2.0, 3.0])), |
| 62 | +} |
0 commit comments