# -*- coding: utf-8 -*-

import struct

import pytest
from xTool.cython.bytes_order import (
    endian_uchar_to_bytes,
    endian_ushort_to_bytes,
    endian_uint_to_bytes,
    endian_byte_to_uchar,
    endian_byte_to_ushort,
    endian_byte_to_uint)


def test_endian_uchar_to_bytes():
    actual = endian_uchar_to_bytes(0x12)
    assert len(actual) == 1
    assert actual.hex() == "12"

    with pytest.raises(OverflowError):
        endian_uchar_to_bytes(0x1234)


def test_endian_ushort_to_bytes():
    actual = endian_ushort_to_bytes(0x1234)
    assert len(actual) == 2
    assert actual.hex() == "1234"


def test_endian_uint_to_bytes():
    actual = endian_uint_to_bytes(0x12345678)
    assert len(actual) == 4
    assert actual.hex() == "12345678"


def test_endian_byte_to_uchar():
    package = struct.pack('>B', 0x12)
    assert package.hex() == "12"
    actual = endian_byte_to_uchar(package)
    assert actual == 0x12


def test_endian_byte_to_ushort():
    package = struct.pack('>H', 0x1234)
    assert package.hex() == "1234"
    actual = endian_byte_to_ushort(package)
    assert actual == 0x1234


def test_endian_byte_to_uint():
    package = struct.pack('>I', 0x12345678)
    assert package.hex() == "12345678"
    actual = endian_byte_to_uint(package)
    assert actual == 0x12345678

d5e7c2eda85fc3e5851e652126d6df499e9c7d2a
<mask token>


def test_endian_uint_to_bytes():
    actual = endian_uint_to_bytes(305419896)
    assert len(actual) == 4
    assert actual.hex() == '12345678'


<mask token>


def test_endian_byte_to_ushort():
    package = struct.pack('>H', 4660)
    assert package.hex() == '1234'
    actual = endian_byte_to_ushort(package)
    assert actual == 4660


<mask token>

<mask token>


def test_endian_uint_to_bytes():
    actual = endian_uint_to_bytes(305419896)
    assert len(actual) == 4
    assert actual.hex() == '12345678'


<mask token>


def test_endian_byte_to_ushort():
    package = struct.pack('>H', 4660)
    assert package.hex() == '1234'
    actual = endian_byte_to_ushort(package)
    assert actual == 4660


def test_endian_byte_to_uint():
    package = struct.pack('>I', 305419896)
    assert package.hex() == '12345678'
    actual = endian_byte_to_uint(package)
    assert actual == 305419896

<mask token>


def test_endian_uchar_to_bytes():
    actual = endian_uchar_to_bytes(18)
    assert len(actual) == 1
    assert actual.hex() == '12'
    with pytest.raises(OverflowError):
        endian_uchar_to_bytes(4660)


def test_endian_ushort_to_bytes():
    actual = endian_ushort_to_bytes(4660)
    assert len(actual) == 2
    assert actual.hex() == '1234'


def test_endian_uint_to_bytes():
    actual = endian_uint_to_bytes(305419896)
    assert len(actual) == 4
    assert actual.hex() == '12345678'


def test_endian_byte_to_uchar():
    package = struct.pack('>B', 18)
    assert package.hex() == '12'
    actual = endian_byte_to_uchar(package)
    assert actual == 18


def test_endian_byte_to_ushort():
    package = struct.pack('>H', 4660)
    assert package.hex() == '1234'
    actual = endian_byte_to_ushort(package)
    assert actual == 4660


def test_endian_byte_to_uint():
    package = struct.pack('>I', 305419896)
    assert package.hex() == '12345678'
    actual = endian_byte_to_uint(package)
    assert actual == 305419896

import struct
import pytest
from xTool.cython.bytes_order import endian_uchar_to_bytes, endian_ushort_to_bytes, endian_uint_to_bytes, endian_byte_to_uchar, endian_byte_to_ushort, endian_byte_to_uint


def test_endian_uchar_to_bytes():
    actual = endian_uchar_to_bytes(18)
    assert len(actual) == 1
    assert actual.hex() == '12'
    with pytest.raises(OverflowError):
        endian_uchar_to_bytes(4660)


def test_endian_ushort_to_bytes():
    actual = endian_ushort_to_bytes(4660)
    assert len(actual) == 2
    assert actual.hex() == '1234'


def test_endian_uint_to_bytes():
    actual = endian_uint_to_bytes(305419896)
    assert len(actual) == 4
    assert actual.hex() == '12345678'


def test_endian_byte_to_uchar():
    package = struct.pack('>B', 18)
    assert package.hex() == '12'
    actual = endian_byte_to_uchar(package)
    assert actual == 18


def test_endian_byte_to_ushort():
    package = struct.pack('>H', 4660)
    assert package.hex() == '1234'
    actual = endian_byte_to_ushort(package)
    assert actual == 4660


def test_endian_byte_to_uint():
    package = struct.pack('>I', 305419896)
    assert package.hex() == '12345678'
    actual = endian_byte_to_uint(package)
    assert actual == 305419896

# -*- coding: utf-8 -*-

import struct

import pytest
from xTool.cython.bytes_order import (
    endian_uchar_to_bytes,
    endian_ushort_to_bytes,
    endian_uint_to_bytes,
    endian_byte_to_uchar,
    endian_byte_to_ushort,
    endian_byte_to_uint)


def test_endian_uchar_to_bytes():
    actual = endian_uchar_to_bytes(0x12)
    assert len(actual) == 1
    assert actual.hex() == "12"

    with pytest.raises(OverflowError):
        endian_uchar_to_bytes(0x1234)


def test_endian_ushort_to_bytes():
    actual = endian_ushort_to_bytes(0x1234)
    assert len(actual) == 2
    assert actual.hex() == "1234"


def test_endian_uint_to_bytes():
    actual = endian_uint_to_bytes(0x12345678)
    assert len(actual) == 4
    assert actual.hex() == "12345678"


def test_endian_byte_to_uchar():
    package = struct.pack('>B', 0x12)
    assert package.hex() == "12"
    actual = endian_byte_to_uchar(package)
    assert actual == 0x12


def test_endian_byte_to_ushort():
    package = struct.pack('>H', 0x1234)
    assert package.hex() == "1234"
    actual = endian_byte_to_ushort(package)
    assert actual == 0x1234


def test_endian_byte_to_uint():
    package = struct.pack('>I', 0x12345678)
    assert package.hex() == "12345678"
    actual = endian_byte_to_uint(package)
    assert actual == 0x12345678
