String Types¶
IsAnyStr ¶
IsAnyStr(
*,
min_length: Optional [int ] = None,
max_length: Optional [int ] = None,
case: Literal ["upper", "lower", None] = None,
regex: Union [None, T , Pattern [T ]] = None,
regex_flags: int = 0
)
Bases:
Comparison of str or bytes objects.
This class allow comparison with both str and bytes but is subclassed
by IsStr and IsBytes which restrict comparison to
str or bytes respectively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_length |
|
minimum length of the string/bytes |
None
|
max_length |
|
maximum length of the string/bytes |
None
|
case |
|
check case of the string/bytes |
None
|
regex |
|
regular expression to match the string/bytes with, |
None
|
regex_flags |
|
optional flags for the regular expression |
0
|
Examples:
from dirty_equals import IsAnyStr
assert 'foobar' == IsAnyStr()
assert b'foobar' == IsAnyStr()
assert 123 != IsAnyStr()
assert 'foobar' == IsAnyStr(regex='foo...')
assert 'foobar' == IsAnyStr(regex=b'foo...') # (1)!
assert 'foobar' == IsAnyStr(min_length=6)
assert 'foobar' != IsAnyStr(min_length=8)
assert 'foobar' == IsAnyStr(case='lower')
assert 'Foobar' != IsAnyStr(case='lower')
regexcan be either a string or bytes,IsAnyStrwill take care of conversion so checks work.
IsStr ¶
IsStr(
*,
min_length: Optional [int ] = None,
max_length: Optional [int ] = None,
case: Literal ["upper", "lower", None] = None,
regex: Union [None, T , Pattern [T ]] = None,
regex_flags: int = 0
)
Bases:
Checks if the value is a string, and optionally meets some constraints.
IsStr is a subclass of IsAnyStr and therefore allows all the same arguments.
Examples:
from dirty_equals import IsStr
assert 'foobar' == IsStr()
assert b'foobar' != IsStr()
assert 'foobar' == IsStr(regex='foo...')
assert 'FOOBAR' == IsStr(min_length=5, max_length=10, case='upper')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_length |
|
minimum length of the string/bytes |
None
|
max_length |
|
maximum length of the string/bytes |
None
|
case |
|
check case of the string/bytes |
None
|
regex |
|
regular expression to match the string/bytes with, |
None
|
regex_flags |
|
optional flags for the regular expression |
0
|
Examples:
from dirty_equals import IsAnyStr
assert 'foobar' == IsAnyStr()
assert b'foobar' == IsAnyStr()
assert 123 != IsAnyStr()
assert 'foobar' == IsAnyStr(regex='foo...')
assert 'foobar' == IsAnyStr(regex=b'foo...') # (1)!
assert 'foobar' == IsAnyStr(min_length=6)
assert 'foobar' != IsAnyStr(min_length=8)
assert 'foobar' == IsAnyStr(case='lower')
assert 'Foobar' != IsAnyStr(case='lower')
regexcan be either a string or bytes,IsAnyStrwill take care of conversion so checks work.
IsBytes ¶
IsBytes(
*,
min_length: Optional [int ] = None,
max_length: Optional [int ] = None,
case: Literal ["upper", "lower", None] = None,
regex: Union [None, T , Pattern [T ]] = None,
regex_flags: int = 0
)
Bases:
Checks if the value is a bytes object, and optionally meets some constraints.
IsBytes is a subclass of IsAnyStr and therefore allows all the same arguments.
Examples:
from dirty_equals import IsBytes
assert b'foobar' == IsBytes()
assert 'foobar' != IsBytes()
assert b'foobar' == IsBytes(regex=b'foo...')
assert b'FOOBAR' == IsBytes(min_length=5, max_length=10, case='upper')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_length |
|
minimum length of the string/bytes |
None
|
max_length |
|
maximum length of the string/bytes |
None
|
case |
|
check case of the string/bytes |
None
|
regex |
|
regular expression to match the string/bytes with, |
None
|
regex_flags |
|
optional flags for the regular expression |
0
|
Examples:
from dirty_equals import IsAnyStr
assert 'foobar' == IsAnyStr()
assert b'foobar' == IsAnyStr()
assert 123 != IsAnyStr()
assert 'foobar' == IsAnyStr(regex='foo...')
assert 'foobar' == IsAnyStr(regex=b'foo...') # (1)!
assert 'foobar' == IsAnyStr(min_length=6)
assert 'foobar' != IsAnyStr(min_length=8)
assert 'foobar' == IsAnyStr(case='lower')
assert 'Foobar' != IsAnyStr(case='lower')
regexcan be either a string or bytes,IsAnyStrwill take care of conversion so checks work.