|
1 | 1 | import ctypes
|
| 2 | +from unittest.mock import |
2 | 3 |
|
3 |
| -from arrayfire_wrapper.defines import AFArray |
| 4 | +import pytest |
| 5 | + |
| 6 | +from arrayfire_wrapper.defines import AFArray, ArrayBuffer, CDimT, CShape, _AFBase, is_arch_x86 |
4 | 7 |
|
5 | 8 |
|
6 | 9 | def test_null_pointer_value() -> None:
|
7 | 10 | assert AFArray.create_null_pointer().value == AFArray(0).value == ctypes.c_void_p(0).value
|
| 11 | + |
| 12 | + |
| 13 | +def test_af_base_create_null_pointer() -> None: |
| 14 | +af_base = _AFBase() |
| 15 | +null_pointer = af_base.create_null_pointer() |
| 16 | +assert isinstance(null_pointer, _AFBase) |
| 17 | + |
| 18 | + |
| 19 | +def test_af_array_create_null_pointer() -> None: |
| 20 | +af_array = AFArray() |
| 21 | +null_pointer = af_array.create_null_pointer() |
| 22 | +assert isinstance(null_pointer, AFArray) |
| 23 | + |
| 24 | + |
| 25 | +def test_array_buffer_creation() -> None: |
| 26 | +array_buffer = ArrayBuffer(address=0x1000, length=10) |
| 27 | + |
| 28 | +assert array_buffer.address == 0x1000 |
| 29 | +assert array_buffer.length == 10 |
| 30 | + |
| 31 | + |
| 32 | +def test_array_buffer_immutable() -> None: |
| 33 | +array_buffer = ArrayBuffer(address=0x2000, length=5) |
| 34 | + |
| 35 | +with pytest.raises(AttributeError): |
| 36 | +array_buffer.address = 0x3000 # type: ignore[misc] |
| 37 | + |
| 38 | +with pytest.raises(AttributeError): |
| 39 | +array_buffer.length = 8 # type: ignore[misc] |
| 40 | + |
| 41 | + |
| 42 | +def test_cshape_creation() -> None: |
| 43 | +c_shape = CShape(1, 2, 3, 4) |
| 44 | +assert c_shape.x1 == 1 |
| 45 | +assert c_shape.x2 == 2 |
| 46 | +assert c_shape.x3 == 3 |
| 47 | +assert c_shape.x4 == 4 |
| 48 | + |
| 49 | + |
| 50 | +def test_cshape_repr() -> None: |
| 51 | +c_shape = CShape(1, 2, 3, 4) |
| 52 | +assert repr(c_shape) == "CShape(1, 2, 3, 4)" |
| 53 | + |
| 54 | + |
| 55 | +def test_cshape_c_array() -> None: |
| 56 | +c_shape = CShape(1, 2, 3, 4) |
| 57 | +c_array = c_shape.c_array |
| 58 | +assert isinstance(c_array, ctypes.Array) |
| 59 | +assert len(c_array) == 4 |
| 60 | +assert c_array[0] == CDimT(1).value |
| 61 | +assert c_array[1] == CDimT(2).value |
| 62 | +assert c_array[2] == CDimT(3).value |
| 63 | +assert c_array[3] == CDimT(4).value |
| 64 | + |
| 65 | + |
| 66 | +@pytest.mark.parametrize( |
| 67 | +"architecture, machine, expected_result", |
| 68 | +[ |
| 69 | +("32bit", "x86", True), |
| 70 | +("32bit", "arm", True), |
| 71 | +("64bit", "x86", False), |
| 72 | +("32bit", "other", False), |
| 73 | +("64bit", "other", False), |
| 74 | +], |
| 75 | +) |
| 76 | +def test_is_arch_x86(architecture: str, machine: str, expected_result: bool) -> None: |
| 77 | +with ("platform.architecture", lambda: (architecture, "")), ("platform.machine", lambda: machine): |
| 78 | +assert is_arch_x86() == expected_result |
0 commit comments