robotframework-mimesislibrary 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- MimesisLibrary/__init__.py +206 -0
- MimesisLibrary/keywords/__init__.py +37 -0
- MimesisLibrary/keywords/address.py +176 -0
- MimesisLibrary/keywords/code.py +84 -0
- MimesisLibrary/keywords/cryptographic.py +98 -0
- MimesisLibrary/keywords/datetime_kw.py +129 -0
- MimesisLibrary/keywords/development.py +80 -0
- MimesisLibrary/keywords/finance.py +126 -0
- MimesisLibrary/keywords/food.py +78 -0
- MimesisLibrary/keywords/hardware.py +130 -0
- MimesisLibrary/keywords/internet.py +175 -0
- MimesisLibrary/keywords/numeric.py +106 -0
- MimesisLibrary/keywords/path.py +70 -0
- MimesisLibrary/keywords/payment.py +98 -0
- MimesisLibrary/keywords/person.py +278 -0
- MimesisLibrary/keywords/science.py +91 -0
- MimesisLibrary/keywords/text.py +170 -0
- MimesisLibrary/keywords/transport.py +50 -0
- MimesisLibrary/utils.py +96 -0
- MimesisLibrary/version.py +2 -0
- robotframework_mimesislibrary-1.0.0.dist-info/METADATA +183 -0
- robotframework_mimesislibrary-1.0.0.dist-info/RECORD +24 -0
- robotframework_mimesislibrary-1.0.0.dist-info/WHEEL +4 -0
- robotframework_mimesislibrary-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""MimesisLibrary — Robot Framework keyword library wrapping the Mimesis fake-data generator.
|
|
2
|
+
|
|
3
|
+
Usage in Robot Framework::
|
|
4
|
+
|
|
5
|
+
*** Settings ***
|
|
6
|
+
Library MimesisLibrary # Default locale: English
|
|
7
|
+
Library MimesisLibrary locale=TR # Turkish default locale
|
|
8
|
+
Library MimesisLibrary locale=EN seed=42 # Reproducible data
|
|
9
|
+
|
|
10
|
+
All keywords that produce locale-dependent output accept an optional ``locale``
|
|
11
|
+
argument that overrides the library-level default for that single call::
|
|
12
|
+
|
|
13
|
+
${arabic_name}= Fake First Name locale=AR
|
|
14
|
+
${french_city}= Fake City locale=FR
|
|
15
|
+
|
|
16
|
+
Locale-independent keywords (e.g. ``Fake UUID``, ``Fake IPv4``) ignore the
|
|
17
|
+
``locale`` argument.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from mimesis import (
|
|
23
|
+
Address,
|
|
24
|
+
Code,
|
|
25
|
+
Cryptographic,
|
|
26
|
+
Datetime,
|
|
27
|
+
Development,
|
|
28
|
+
Finance,
|
|
29
|
+
Food,
|
|
30
|
+
Hardware,
|
|
31
|
+
Internet,
|
|
32
|
+
Numeric,
|
|
33
|
+
Path,
|
|
34
|
+
Payment,
|
|
35
|
+
Person,
|
|
36
|
+
Science,
|
|
37
|
+
Text,
|
|
38
|
+
Transport,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
from MimesisLibrary.keywords import (
|
|
42
|
+
AddressKeywords,
|
|
43
|
+
CodeKeywords,
|
|
44
|
+
CryptographicKeywords,
|
|
45
|
+
DatetimeKeywords,
|
|
46
|
+
DevelopmentKeywords,
|
|
47
|
+
FinanceKeywords,
|
|
48
|
+
FoodKeywords,
|
|
49
|
+
HardwareKeywords,
|
|
50
|
+
InternetKeywords,
|
|
51
|
+
NumericKeywords,
|
|
52
|
+
PathKeywords,
|
|
53
|
+
PaymentKeywords,
|
|
54
|
+
PersonKeywords,
|
|
55
|
+
ScienceKeywords,
|
|
56
|
+
TextKeywords,
|
|
57
|
+
TransportKeywords,
|
|
58
|
+
)
|
|
59
|
+
from MimesisLibrary.utils import resolve_locale
|
|
60
|
+
from MimesisLibrary.version import VERSION
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class MimesisLibrary(
|
|
64
|
+
PersonKeywords,
|
|
65
|
+
AddressKeywords,
|
|
66
|
+
InternetKeywords,
|
|
67
|
+
CodeKeywords,
|
|
68
|
+
CryptographicKeywords,
|
|
69
|
+
DatetimeKeywords,
|
|
70
|
+
FinanceKeywords,
|
|
71
|
+
FoodKeywords,
|
|
72
|
+
HardwareKeywords,
|
|
73
|
+
NumericKeywords,
|
|
74
|
+
PathKeywords,
|
|
75
|
+
PaymentKeywords,
|
|
76
|
+
ScienceKeywords,
|
|
77
|
+
TextKeywords,
|
|
78
|
+
TransportKeywords,
|
|
79
|
+
DevelopmentKeywords,
|
|
80
|
+
):
|
|
81
|
+
"""Robot Framework keyword library for generating fake / synthetic test data
|
|
82
|
+
using the `Mimesis <https://mimesis.name/>`_ data generator.
|
|
83
|
+
|
|
84
|
+
= Scope =
|
|
85
|
+
|
|
86
|
+
The library scope is ``GLOBAL``: a single set of Mimesis provider instances
|
|
87
|
+
is shared across the entire test run. This is intentional — Mimesis providers
|
|
88
|
+
are heavy objects that load JSON data files on construction, so reusing them
|
|
89
|
+
is more efficient than re-creating them for every test.
|
|
90
|
+
|
|
91
|
+
= Import Parameters =
|
|
92
|
+
|
|
93
|
+
| =Parameter= | =Type= | =Default= | =Description= |
|
|
94
|
+
| ``locale`` | ``str`` | ``"en"`` | Default locale for locale-dependent keywords |
|
|
95
|
+
| ``seed`` | ``int`` | ``None`` | RNG seed for reproducible data generation |
|
|
96
|
+
|
|
97
|
+
= Locale Support =
|
|
98
|
+
|
|
99
|
+
Locale-dependent keywords (Person, Address, Food, Text, Finance, Datetime)
|
|
100
|
+
accept an optional ``locale`` argument. Pass any
|
|
101
|
+
`Mimesis locale code <https://mimesis.name/latest/locales.html>`_
|
|
102
|
+
(case-insensitive), for example ``"TR"``, ``"AR"``, ``"DE"``.
|
|
103
|
+
|
|
104
|
+
Locale-independent keywords (Internet, Code, Cryptographic, Hardware, etc.)
|
|
105
|
+
silently ignore the ``locale`` argument if passed.
|
|
106
|
+
|
|
107
|
+
= Seed / Reproducibility =
|
|
108
|
+
|
|
109
|
+
Pass ``seed`` at import time to make data generation reproducible::
|
|
110
|
+
|
|
111
|
+
Library MimesisLibrary seed=42
|
|
112
|
+
|
|
113
|
+
= Examples =
|
|
114
|
+
|
|
115
|
+
| Library MimesisLibrary locale=TR
|
|
116
|
+
|
|
|
117
|
+
| *** Test Cases ***
|
|
118
|
+
| Mixed Locale Example
|
|
119
|
+
| ${tr_name}= Fake Full Name locale=TR
|
|
120
|
+
| ${ar_name}= Fake Full Name locale=AR
|
|
121
|
+
| ${uuid}= Fake UUID
|
|
122
|
+
| ${ip}= Fake IPv4
|
|
123
|
+
| Log Many ${tr_name} ${ar_name} ${uuid} ${ip}
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
# Robot Framework library metadata
|
|
127
|
+
ROBOT_LIBRARY_SCOPE = "GLOBAL"
|
|
128
|
+
ROBOT_LIBRARY_VERSION = VERSION
|
|
129
|
+
ROBOT_LIBRARY_DOC_FORMAT = "reST"
|
|
130
|
+
|
|
131
|
+
def __init__(self, locale: str = "en", seed: int | None = None) -> None:
|
|
132
|
+
"""Initialise MimesisLibrary and instantiate all Mimesis providers.
|
|
133
|
+
|
|
134
|
+
:param locale: Default locale code for locale-dependent keywords (default: ``"en"``).
|
|
135
|
+
:param seed: Optional RNG seed for reproducible data generation.
|
|
136
|
+
"""
|
|
137
|
+
# Resolve the locale string to a Locale enum value
|
|
138
|
+
self._locale = resolve_locale(locale)
|
|
139
|
+
self._seed = int(seed) if seed is not None else None
|
|
140
|
+
|
|
141
|
+
# Locale-dependent providers — share the library default locale
|
|
142
|
+
self._person = Person(locale=self._locale, seed=self._seed)
|
|
143
|
+
self._address = Address(locale=self._locale, seed=self._seed)
|
|
144
|
+
self._food = Food(locale=self._locale, seed=self._seed)
|
|
145
|
+
self._text = Text(locale=self._locale, seed=self._seed)
|
|
146
|
+
self._finance = Finance(locale=self._locale, seed=self._seed)
|
|
147
|
+
self._datetime = Datetime(locale=self._locale, seed=self._seed)
|
|
148
|
+
|
|
149
|
+
# Locale-independent providers — no locale argument accepted
|
|
150
|
+
self._code = Code(seed=self._seed)
|
|
151
|
+
self._cryptographic = Cryptographic(seed=self._seed)
|
|
152
|
+
self._development = Development(seed=self._seed)
|
|
153
|
+
self._hardware = Hardware(seed=self._seed)
|
|
154
|
+
self._internet = Internet(seed=self._seed)
|
|
155
|
+
self._numeric = Numeric(seed=self._seed)
|
|
156
|
+
self._path = Path(seed=self._seed)
|
|
157
|
+
self._payment = Payment(seed=self._seed)
|
|
158
|
+
self._science = Science(seed=self._seed)
|
|
159
|
+
self._transport = Transport(seed=self._seed)
|
|
160
|
+
|
|
161
|
+
# ------------------------------------------------------------------ #
|
|
162
|
+
# Library-level control keywords
|
|
163
|
+
# ------------------------------------------------------------------ #
|
|
164
|
+
|
|
165
|
+
def get_mimesis_library_version(self) -> str:
|
|
166
|
+
"""Return the installed version of MimesisLibrary.
|
|
167
|
+
|
|
168
|
+
:returns: A version string (e.g. ``"1.0.0"``).
|
|
169
|
+
|
|
170
|
+
Examples:
|
|
171
|
+
| ${version}= | Get Mimesis Library Version |
|
|
172
|
+
"""
|
|
173
|
+
return VERSION
|
|
174
|
+
|
|
175
|
+
def set_seed(self, seed: int) -> None:
|
|
176
|
+
"""Re-initialise all providers with a new RNG seed.
|
|
177
|
+
|
|
178
|
+
Calling this keyword mid-suite allows you to switch between reproducible
|
|
179
|
+
and non-reproducible data generation.
|
|
180
|
+
|
|
181
|
+
:param seed: New integer seed value.
|
|
182
|
+
|
|
183
|
+
Examples:
|
|
184
|
+
| Set Seed 42
|
|
185
|
+
"""
|
|
186
|
+
self._seed = int(seed)
|
|
187
|
+
|
|
188
|
+
# Reinitialise locale-dependent providers with the new seed
|
|
189
|
+
self._person = Person(locale=self._locale, seed=self._seed)
|
|
190
|
+
self._address = Address(locale=self._locale, seed=self._seed)
|
|
191
|
+
self._food = Food(locale=self._locale, seed=self._seed)
|
|
192
|
+
self._text = Text(locale=self._locale, seed=self._seed)
|
|
193
|
+
self._finance = Finance(locale=self._locale, seed=self._seed)
|
|
194
|
+
self._datetime = Datetime(locale=self._locale, seed=self._seed)
|
|
195
|
+
|
|
196
|
+
# Reinitialise locale-independent providers
|
|
197
|
+
self._code = Code(seed=self._seed)
|
|
198
|
+
self._cryptographic = Cryptographic(seed=self._seed)
|
|
199
|
+
self._development = Development(seed=self._seed)
|
|
200
|
+
self._hardware = Hardware(seed=self._seed)
|
|
201
|
+
self._internet = Internet(seed=self._seed)
|
|
202
|
+
self._numeric = Numeric(seed=self._seed)
|
|
203
|
+
self._path = Path(seed=self._seed)
|
|
204
|
+
self._payment = Payment(seed=self._seed)
|
|
205
|
+
self._science = Science(seed=self._seed)
|
|
206
|
+
self._transport = Transport(seed=self._seed)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Keyword mixin modules exported from the keywords sub-package."""
|
|
2
|
+
|
|
3
|
+
from MimesisLibrary.keywords.address import AddressKeywords
|
|
4
|
+
from MimesisLibrary.keywords.code import CodeKeywords
|
|
5
|
+
from MimesisLibrary.keywords.cryptographic import CryptographicKeywords
|
|
6
|
+
from MimesisLibrary.keywords.datetime_kw import DatetimeKeywords
|
|
7
|
+
from MimesisLibrary.keywords.development import DevelopmentKeywords
|
|
8
|
+
from MimesisLibrary.keywords.finance import FinanceKeywords
|
|
9
|
+
from MimesisLibrary.keywords.food import FoodKeywords
|
|
10
|
+
from MimesisLibrary.keywords.hardware import HardwareKeywords
|
|
11
|
+
from MimesisLibrary.keywords.internet import InternetKeywords
|
|
12
|
+
from MimesisLibrary.keywords.numeric import NumericKeywords
|
|
13
|
+
from MimesisLibrary.keywords.path import PathKeywords
|
|
14
|
+
from MimesisLibrary.keywords.payment import PaymentKeywords
|
|
15
|
+
from MimesisLibrary.keywords.person import PersonKeywords
|
|
16
|
+
from MimesisLibrary.keywords.science import ScienceKeywords
|
|
17
|
+
from MimesisLibrary.keywords.text import TextKeywords
|
|
18
|
+
from MimesisLibrary.keywords.transport import TransportKeywords
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"AddressKeywords",
|
|
22
|
+
"CodeKeywords",
|
|
23
|
+
"CryptographicKeywords",
|
|
24
|
+
"DatetimeKeywords",
|
|
25
|
+
"DevelopmentKeywords",
|
|
26
|
+
"FinanceKeywords",
|
|
27
|
+
"FoodKeywords",
|
|
28
|
+
"HardwareKeywords",
|
|
29
|
+
"InternetKeywords",
|
|
30
|
+
"NumericKeywords",
|
|
31
|
+
"PathKeywords",
|
|
32
|
+
"PaymentKeywords",
|
|
33
|
+
"PersonKeywords",
|
|
34
|
+
"ScienceKeywords",
|
|
35
|
+
"TextKeywords",
|
|
36
|
+
"TransportKeywords",
|
|
37
|
+
]
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""Address provider keywords — wraps :class:`mimesis.Address`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from mimesis import Address
|
|
6
|
+
|
|
7
|
+
from MimesisLibrary.utils import resolve_locale
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AddressKeywords:
|
|
11
|
+
"""Keywords for generating address-related fake data.
|
|
12
|
+
|
|
13
|
+
All keywords accept an optional ``locale`` argument that overrides the
|
|
14
|
+
library-level default locale for that single call.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def _get_address(self, locale: str | None) -> Address:
|
|
18
|
+
"""Return an Address provider, using per-call locale if given."""
|
|
19
|
+
if locale is not None:
|
|
20
|
+
return Address(locale=resolve_locale(locale), seed=self._seed)
|
|
21
|
+
return self._address # type: ignore[attr-defined]
|
|
22
|
+
|
|
23
|
+
def fake_city(self, locale: str | None = None) -> str:
|
|
24
|
+
"""Return a randomly selected city name.
|
|
25
|
+
|
|
26
|
+
:param locale: Optional locale code override.
|
|
27
|
+
:returns: A city name string.
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
| ${city}= | Fake City | |
|
|
31
|
+
| ${city}= | Fake City | locale=TR |
|
|
32
|
+
"""
|
|
33
|
+
return self._get_address(locale).city()
|
|
34
|
+
|
|
35
|
+
def fake_country(self, locale: str | None = None) -> str:
|
|
36
|
+
"""Return a randomly selected country name.
|
|
37
|
+
|
|
38
|
+
:param locale: Optional locale code override.
|
|
39
|
+
:returns: A country name string.
|
|
40
|
+
|
|
41
|
+
Examples:
|
|
42
|
+
| ${country}= | Fake Country | |
|
|
43
|
+
| ${country}= | Fake Country | locale=DE |
|
|
44
|
+
"""
|
|
45
|
+
return self._get_address(locale).country()
|
|
46
|
+
|
|
47
|
+
def fake_country_code(self, locale: str | None = None) -> str:
|
|
48
|
+
"""Return a randomly selected ISO country code.
|
|
49
|
+
|
|
50
|
+
:param locale: Optional locale code override.
|
|
51
|
+
:returns: A two-letter country code string (e.g. ``"TR"``).
|
|
52
|
+
|
|
53
|
+
Examples:
|
|
54
|
+
| ${code}= | Fake Country Code |
|
|
55
|
+
"""
|
|
56
|
+
return self._get_address(locale).country_code()
|
|
57
|
+
|
|
58
|
+
def fake_street_name(self, locale: str | None = None) -> str:
|
|
59
|
+
"""Return a randomly generated street name.
|
|
60
|
+
|
|
61
|
+
:param locale: Optional locale code override.
|
|
62
|
+
:returns: A street name string.
|
|
63
|
+
|
|
64
|
+
Examples:
|
|
65
|
+
| ${street}= | Fake Street Name | |
|
|
66
|
+
| ${street}= | Fake Street Name | locale=FR |
|
|
67
|
+
"""
|
|
68
|
+
return self._get_address(locale).street_name()
|
|
69
|
+
|
|
70
|
+
def fake_street_number(self) -> str:
|
|
71
|
+
"""Return a randomly generated street (building) number.
|
|
72
|
+
|
|
73
|
+
:returns: A street number string.
|
|
74
|
+
|
|
75
|
+
Examples:
|
|
76
|
+
| ${number}= | Fake Street Number |
|
|
77
|
+
"""
|
|
78
|
+
return self._address.street_number() # type: ignore[attr-defined]
|
|
79
|
+
|
|
80
|
+
def fake_street_suffix(self, locale: str | None = None) -> str:
|
|
81
|
+
"""Return a randomly selected street suffix (e.g. ``"Avenue"``).
|
|
82
|
+
|
|
83
|
+
:param locale: Optional locale code override.
|
|
84
|
+
:returns: A street suffix string.
|
|
85
|
+
|
|
86
|
+
Examples:
|
|
87
|
+
| ${suffix}= | Fake Street Suffix |
|
|
88
|
+
"""
|
|
89
|
+
return self._get_address(locale).street_suffix()
|
|
90
|
+
|
|
91
|
+
def fake_address(self, locale: str | None = None) -> str:
|
|
92
|
+
"""Return a full randomly generated address string.
|
|
93
|
+
|
|
94
|
+
:param locale: Optional locale code override.
|
|
95
|
+
:returns: A full address string.
|
|
96
|
+
|
|
97
|
+
Examples:
|
|
98
|
+
| ${addr}= | Fake Address | |
|
|
99
|
+
| ${addr}= | Fake Address | locale=TR |
|
|
100
|
+
"""
|
|
101
|
+
return self._get_address(locale).address()
|
|
102
|
+
|
|
103
|
+
def fake_zip_code(self, locale: str | None = None) -> str:
|
|
104
|
+
"""Return a randomly generated postal / ZIP code.
|
|
105
|
+
|
|
106
|
+
:param locale: Optional locale code override.
|
|
107
|
+
:returns: A ZIP/postal code string.
|
|
108
|
+
|
|
109
|
+
Examples:
|
|
110
|
+
| ${zip}= | Fake Zip Code | |
|
|
111
|
+
| ${zip}= | Fake Zip Code | locale=DE |
|
|
112
|
+
"""
|
|
113
|
+
return self._get_address(locale).zip_code()
|
|
114
|
+
|
|
115
|
+
def fake_state(self, locale: str | None = None) -> str:
|
|
116
|
+
"""Return a randomly selected state, province or region name.
|
|
117
|
+
|
|
118
|
+
:param locale: Optional locale code override.
|
|
119
|
+
:returns: A state/region name string.
|
|
120
|
+
|
|
121
|
+
Examples:
|
|
122
|
+
| ${state}= | Fake State |
|
|
123
|
+
"""
|
|
124
|
+
return self._get_address(locale).state()
|
|
125
|
+
|
|
126
|
+
def fake_latitude(self) -> float:
|
|
127
|
+
"""Return a randomly generated latitude coordinate.
|
|
128
|
+
|
|
129
|
+
:returns: A float in the range ``[-90.0, 90.0]``.
|
|
130
|
+
|
|
131
|
+
Examples:
|
|
132
|
+
| ${lat}= | Fake Latitude |
|
|
133
|
+
"""
|
|
134
|
+
return self._address.latitude() # type: ignore[attr-defined]
|
|
135
|
+
|
|
136
|
+
def fake_longitude(self) -> float:
|
|
137
|
+
"""Return a randomly generated longitude coordinate.
|
|
138
|
+
|
|
139
|
+
:returns: A float in the range ``[-180.0, 180.0]``.
|
|
140
|
+
|
|
141
|
+
Examples:
|
|
142
|
+
| ${lon}= | Fake Longitude |
|
|
143
|
+
"""
|
|
144
|
+
return self._address.longitude() # type: ignore[attr-defined]
|
|
145
|
+
|
|
146
|
+
def fake_coordinates(self) -> dict:
|
|
147
|
+
"""Return a dict with randomly generated ``latitude`` and ``longitude``.
|
|
148
|
+
|
|
149
|
+
:returns: A dictionary ``{"latitude": float, "longitude": float}``.
|
|
150
|
+
|
|
151
|
+
Examples:
|
|
152
|
+
| ${coords}= | Fake Coordinates |
|
|
153
|
+
| Log | ${coords["latitude"]} |
|
|
154
|
+
"""
|
|
155
|
+
return self._address.coordinates() # type: ignore[attr-defined]
|
|
156
|
+
|
|
157
|
+
def fake_continent(self, locale: str | None = None) -> str:
|
|
158
|
+
"""Return a randomly selected continent name.
|
|
159
|
+
|
|
160
|
+
:param locale: Optional locale code override.
|
|
161
|
+
:returns: A continent name string.
|
|
162
|
+
|
|
163
|
+
Examples:
|
|
164
|
+
| ${cont}= | Fake Continent |
|
|
165
|
+
"""
|
|
166
|
+
return self._get_address(locale).continent()
|
|
167
|
+
|
|
168
|
+
def fake_calling_code(self) -> str:
|
|
169
|
+
"""Return a randomly selected international calling code.
|
|
170
|
+
|
|
171
|
+
:returns: A calling code string (e.g. ``"+90"``).
|
|
172
|
+
|
|
173
|
+
Examples:
|
|
174
|
+
| ${code}= | Fake Calling Code |
|
|
175
|
+
"""
|
|
176
|
+
return self._address.calling_code() # type: ignore[attr-defined]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Code provider keywords — wraps :class:`mimesis.Code`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CodeKeywords:
|
|
7
|
+
"""Keywords for generating various code and barcode fake data.
|
|
8
|
+
|
|
9
|
+
:class:`mimesis.Code` is locale-independent; these keywords do not
|
|
10
|
+
accept a ``locale`` parameter.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def fake_ean(self, fmt: str = "EAN13") -> str:
|
|
14
|
+
"""Return a randomly generated EAN barcode.
|
|
15
|
+
|
|
16
|
+
:param fmt: EAN format — ``"EAN13"`` (default) or ``"EAN8"``.
|
|
17
|
+
:returns: An EAN barcode string.
|
|
18
|
+
|
|
19
|
+
Examples:
|
|
20
|
+
| ${ean}= | Fake EAN | |
|
|
21
|
+
| ${ean}= | Fake EAN | fmt=EAN8 |
|
|
22
|
+
"""
|
|
23
|
+
from mimesis.enums import EANFormat
|
|
24
|
+
|
|
25
|
+
ean_format = EANFormat[fmt.upper()]
|
|
26
|
+
return self._code.ean(fmt=ean_format) # type: ignore[attr-defined]
|
|
27
|
+
|
|
28
|
+
def fake_imei(self) -> str:
|
|
29
|
+
"""Return a randomly generated IMEI number.
|
|
30
|
+
|
|
31
|
+
:returns: A 15-digit IMEI string.
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
| ${imei}= | Fake IMEI |
|
|
35
|
+
"""
|
|
36
|
+
return self._code.imei() # type: ignore[attr-defined]
|
|
37
|
+
|
|
38
|
+
def fake_isbn(self, fmt: str = "ISBN13") -> str:
|
|
39
|
+
"""Return a randomly generated ISBN number.
|
|
40
|
+
|
|
41
|
+
:param fmt: ISBN format — ``"ISBN13"`` (default) or ``"ISBN10"``.
|
|
42
|
+
:returns: An ISBN string.
|
|
43
|
+
|
|
44
|
+
Examples:
|
|
45
|
+
| ${isbn}= | Fake ISBN | |
|
|
46
|
+
| ${isbn}= | Fake ISBN | fmt=ISBN10 |
|
|
47
|
+
"""
|
|
48
|
+
from mimesis.enums import ISBNFormat
|
|
49
|
+
|
|
50
|
+
isbn_format = ISBNFormat[fmt.upper()]
|
|
51
|
+
return self._code.isbn(fmt=isbn_format) # type: ignore[attr-defined]
|
|
52
|
+
|
|
53
|
+
def fake_pin(self, mask: str = "####") -> str:
|
|
54
|
+
"""Return a randomly generated PIN code.
|
|
55
|
+
|
|
56
|
+
:param mask: Digit mask — ``"#"`` is replaced with a random digit.
|
|
57
|
+
Default is ``"####"`` (4-digit PIN).
|
|
58
|
+
:returns: A PIN string.
|
|
59
|
+
|
|
60
|
+
Examples:
|
|
61
|
+
| ${pin}= | Fake PIN | |
|
|
62
|
+
| ${pin}= | Fake PIN | mask=###### |
|
|
63
|
+
"""
|
|
64
|
+
return self._code.pin(mask=mask) # type: ignore[attr-defined]
|
|
65
|
+
|
|
66
|
+
def fake_locale_code(self) -> str:
|
|
67
|
+
"""Return a randomly selected locale code string (e.g. ``"en-US"``).
|
|
68
|
+
|
|
69
|
+
:returns: A locale code string.
|
|
70
|
+
|
|
71
|
+
Examples:
|
|
72
|
+
| ${lc}= | Fake Locale Code |
|
|
73
|
+
"""
|
|
74
|
+
return self._code.locale_code() # type: ignore[attr-defined]
|
|
75
|
+
|
|
76
|
+
def fake_issn(self) -> str:
|
|
77
|
+
"""Return a randomly generated ISSN number.
|
|
78
|
+
|
|
79
|
+
:returns: An ISSN string.
|
|
80
|
+
|
|
81
|
+
Examples:
|
|
82
|
+
| ${issn}= | Fake ISSN |
|
|
83
|
+
"""
|
|
84
|
+
return self._code.issn() # type: ignore[attr-defined]
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Cryptographic provider keywords — wraps :class:`mimesis.Cryptographic`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CryptographicKeywords:
|
|
7
|
+
"""Keywords for generating cryptographic tokens, hashes and identifiers.
|
|
8
|
+
|
|
9
|
+
:class:`mimesis.Cryptographic` is locale-independent.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def fake_uuid(self) -> str:
|
|
13
|
+
"""Return a randomly generated UUID (version 4) string.
|
|
14
|
+
|
|
15
|
+
:returns: A UUID string (e.g. ``"550e8400-e29b-41d4-a716-446655440000"``).
|
|
16
|
+
|
|
17
|
+
Examples:
|
|
18
|
+
| ${uuid}= | Fake UUID |
|
|
19
|
+
"""
|
|
20
|
+
return str(self._cryptographic.uuid()) # type: ignore[attr-defined]
|
|
21
|
+
|
|
22
|
+
def fake_token_hex(self, entropy: int = 32) -> str:
|
|
23
|
+
"""Return a random URL-safe hexadecimal token.
|
|
24
|
+
|
|
25
|
+
:param entropy: Number of random bytes (default: 32).
|
|
26
|
+
:returns: A hex string of length ``entropy * 2``.
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
| ${token}= | Fake Token Hex | |
|
|
30
|
+
| ${token}= | Fake Token Hex | entropy=16 |
|
|
31
|
+
"""
|
|
32
|
+
return self._cryptographic.token_hex(entropy=int(entropy)) # type: ignore[attr-defined]
|
|
33
|
+
|
|
34
|
+
def fake_token_urlsafe(self, entropy: int = 32) -> str:
|
|
35
|
+
"""Return a random URL-safe base64-encoded token.
|
|
36
|
+
|
|
37
|
+
:param entropy: Number of random bytes (default: 32).
|
|
38
|
+
:returns: A URL-safe base64 string.
|
|
39
|
+
|
|
40
|
+
Examples:
|
|
41
|
+
| ${token}= | Fake Token URL Safe |
|
|
42
|
+
"""
|
|
43
|
+
return self._cryptographic.token_urlsafe(entropy=int(entropy)) # type: ignore[attr-defined]
|
|
44
|
+
|
|
45
|
+
def fake_token_bytes(self, entropy: int = 32) -> bytes:
|
|
46
|
+
"""Return a random byte string.
|
|
47
|
+
|
|
48
|
+
:param entropy: Number of random bytes (default: 32).
|
|
49
|
+
:returns: A ``bytes`` object.
|
|
50
|
+
|
|
51
|
+
Examples:
|
|
52
|
+
| ${raw}= | Fake Token Bytes |
|
|
53
|
+
"""
|
|
54
|
+
return self._cryptographic.token_bytes(entropy=int(entropy)) # type: ignore[attr-defined]
|
|
55
|
+
|
|
56
|
+
def fake_md5(self) -> str:
|
|
57
|
+
"""Return a randomly generated MD5 hash string.
|
|
58
|
+
|
|
59
|
+
:returns: A 32-character hex string.
|
|
60
|
+
|
|
61
|
+
Examples:
|
|
62
|
+
| ${md5}= | Fake MD5 |
|
|
63
|
+
"""
|
|
64
|
+
from mimesis.enums import Algorithm
|
|
65
|
+
return self._cryptographic.hash(algorithm=Algorithm.MD5) # type: ignore[attr-defined]
|
|
66
|
+
|
|
67
|
+
def fake_sha1(self) -> str:
|
|
68
|
+
"""Return a randomly generated SHA-1 hash string.
|
|
69
|
+
|
|
70
|
+
:returns: A 40-character hex string.
|
|
71
|
+
|
|
72
|
+
Examples:
|
|
73
|
+
| ${sha1}= | Fake SHA1 |
|
|
74
|
+
"""
|
|
75
|
+
from mimesis.enums import Algorithm
|
|
76
|
+
return self._cryptographic.hash(algorithm=Algorithm.SHA1) # type: ignore[attr-defined]
|
|
77
|
+
|
|
78
|
+
def fake_sha256(self) -> str:
|
|
79
|
+
"""Return a randomly generated SHA-256 hash string.
|
|
80
|
+
|
|
81
|
+
:returns: A 64-character hex string.
|
|
82
|
+
|
|
83
|
+
Examples:
|
|
84
|
+
| ${sha256}= | Fake SHA256 |
|
|
85
|
+
"""
|
|
86
|
+
from mimesis.enums import Algorithm
|
|
87
|
+
return self._cryptographic.hash(algorithm=Algorithm.SHA256) # type: ignore[attr-defined]
|
|
88
|
+
|
|
89
|
+
def fake_sha512(self) -> str:
|
|
90
|
+
"""Return a randomly generated SHA-512 hash string.
|
|
91
|
+
|
|
92
|
+
:returns: A 128-character hex string.
|
|
93
|
+
|
|
94
|
+
Examples:
|
|
95
|
+
| ${sha512}= | Fake SHA512 |
|
|
96
|
+
"""
|
|
97
|
+
from mimesis.enums import Algorithm
|
|
98
|
+
return self._cryptographic.hash(algorithm=Algorithm.SHA512) # type: ignore[attr-defined]
|