def test_repr(): Array = array(complex, ndim=2) shape_str = shape((Arbitrary, Arbitrary)).get_short_str() expected_str = ("NumPy ndarray-like, with numeric type " "compatible to `complex`, " f"and shape `{shape_str}`.") assert Array.get_annotation_str() == expected_str
def test_repr(): pairs = { None: "Array shape arbitrary.", (): "Array shape ().", (0, ): "Array shape (0,).", (None, ): "Array shape (arbitrary,).", (5, 4): "Array shape (5, 4).", (5, None): "Array shape (5, arbitrary).", } for spec, string in pairs.items(): assert shape(spec).get_annotation_str() == string
def test_shapespec_any(): Shape = shape(None) assert not Shape("not a shapespec").is_valid() assert not Shape((4, "4")).is_valid() assert not Shape((4, None)).is_valid() assert not Shape((None, )).is_valid() assert Shape(()).is_valid() assert Shape((4, )).is_valid() assert Shape((5, 4)).is_valid() assert Shape((5, 0)).is_valid() assert Shape((5, False)).is_valid() assert Shape((5, 42098507180)).is_valid() assert Shape((5, 4, 0, 9)).is_valid()
def test_non_tuple_iterable(): Shape = shape() assert not Shape(["one", "love"]).is_valid() assert Shape([1, 3]).is_valid() assert Shape(np.array([1, 3])).is_valid() assert Shape((i for i in range(3))).is_valid()