Bytes assertions¶
Assertions for bytes and bytearray values.
Assertions for bytes and bytearray values.
is_valid_utf8 ¶
Assert that val is valid UTF-8.
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val is not valid UTF-8 |
Source code in assertpy2/bytes_mixin.py
is_valid_encoding ¶
Assert that val is valid in the given encoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoding
|
str
|
the encoding to validate against (e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val cannot be decoded with the given encoding |
Source code in assertpy2/bytes_mixin.py
starts_with_bytes ¶
Assert that val starts with the given byte prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
bytes
|
the expected byte prefix. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does not start with the prefix |
Source code in assertpy2/bytes_mixin.py
contains_bytes ¶
Assert that val contains the given byte subsequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub
|
bytes
|
the byte subsequence to find. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does not contain the subsequence |
Source code in assertpy2/bytes_mixin.py
has_byte_at ¶
Assert that the byte at the given index equals the expected value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
zero-based byte index. |
required |
expected
|
int
|
expected byte value (0-255). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if the byte at index does not match |
Source code in assertpy2/bytes_mixin.py
is_hex_equal_to ¶
Assert that val equals the given hex string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_hex
|
str
|
hex string without prefix (e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val does not match the hex string |
Source code in assertpy2/bytes_mixin.py
decoded_as ¶
Decode val and return a new builder with the decoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoding
|
str
|
the encoding to use (default |
'utf-8'
|
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
a new instance with the decoded string as val |
Raises:
| Type | Description |
|---|---|
UnicodeDecodeError
|
if val cannot be decoded |