Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_setup_locale_unsupported_locale(self):
with pytest.raises(UnsupportedLocale):
BaseDataProvider(locale='nil')
def test_pull_raises(self, locale):
data_provider = BaseDataProvider(locale=locale)
with pytest.raises(FileNotFoundError):
data_provider.pull('something.json')
def test_pull(self, locale, city):
data_provider = BaseDataProvider(locale)
data_provider.pull('address.json')
assert city in data_provider._data['city']
"""Provider of data related to date and time."""
from calendar import monthrange, timegm
from datetime import date, datetime, time, timedelta
from typing import List, Optional, Union
from mimesis.compat import pytz
from mimesis.data import GMT_OFFSETS, ROMAN_NUMS, TIMEZONES
from mimesis.providers.base import BaseDataProvider
from mimesis.typing import Date, DateTime, Time
__all__ = ['Datetime']
class Datetime(BaseDataProvider):
"""Class for generating data related to the date and time."""
def __init__(self, *args, **kwargs):
"""Initialize attributes.
:param locale: Current locale.
"""
super().__init__(*args, **kwargs)
self._datafile = 'datetime.json'
self.pull(self._datafile)
class Meta:
"""Class for metadata."""
name = 'datetime'
from mimesis.data import (
CSS_PROPERTIES,
CSS_SELECTORS,
CSS_SIZE_UNITS,
HTML_CONTAINER_TAGS,
HTML_MARKUP_TAGS,
)
from mimesis.providers.base import BaseDataProvider
from mimesis.providers.internet import Internet
from mimesis.providers.text import Text
__all__ = ['Structure']
class Structure(BaseDataProvider):
"""Class for generating structured data."""
def __init__(self, *args, **kwargs) -> None:
"""Initialize attributes.
:param locale: Current locale.
:param seed: Seed.
"""
super().__init__(*args, **kwargs)
self.__inet = Internet(seed=self.seed)
self.__text = Text('en', seed=self.seed)
class Meta:
"""Class for metadata."""
name = 'structure'
CALLING_CODES,
EMAIL_DOMAINS,
GENDER_SYMBOLS,
SEXUALITY_SYMBOLS,
SOCIAL_NETWORKS,
USERNAMES,
)
from mimesis.enums import Gender, SocialNetwork, TitleType
from mimesis.exceptions import NonEnumerableError
from mimesis.providers.base import BaseDataProvider
from mimesis.random import get_random_item
__all__ = ['Person']
class Person(BaseDataProvider):
"""Class for generating personal data."""
def __init__(self, *args, **kwargs) -> None:
"""Initialize attributes.
:param locale: Current locale.
:param seed: Seed.
"""
super().__init__(*args, **kwargs)
self._datafile = 'person.json'
self.pull(self._datafile)
self._store = {
'age': 0,
}
class Meta:
from typing import Optional, Union
from mimesis.data import (
CALLING_CODES,
CONTINENT_CODES,
COUNTRY_CODES,
SHORTENED_ADDRESS_FMT,
)
from mimesis.enums import CountryCode
from mimesis.providers.base import BaseDataProvider
__all__ = ['Address']
class Address(BaseDataProvider):
"""Class for generate fake address data.
This object provides all the data related to
geographical location.
"""
def __init__(self, *args, **kwargs) -> None:
"""Initialize attributes.
:param locale: Current locale.
"""
super().__init__(*args, **kwargs)
self._datafile = 'address.json'
self.pull(self._datafile)
class Meta:
# -*- coding: utf-8 -*-
"""Provides pseudo-scientific data."""
from typing import Union
from mimesis.data import MATH_FORMULAS
from mimesis.providers.base import BaseDataProvider
__all__ = ['Science']
class Science(BaseDataProvider):
"""Class for generating pseudo-scientific data."""
def __init__(self, *args, **kwargs):
"""Initialize attributes.
:param locale: Current language.
:param seed: Seed.
"""
super().__init__(*args, **kwargs)
self._datafile = 'science.json'
self.pull(self._datafile)
class Meta:
"""Class for metadata."""
name = 'science'
# -*- coding: utf-8 -*-
"""Provides data related to food."""
from mimesis.providers.base import BaseDataProvider
__all__ = ['Food']
class Food(BaseDataProvider):
"""Class for generating data related to food."""
def __init__(self, *args, **kwargs):
"""Initialize attributes.
:param locale: Current locale.
"""
super().__init__(*args, **kwargs)
self._datafile = 'food.json'
self.pull(self._datafile)
class Meta:
"""Class for metadata."""
name = 'food'
# -*- coding: utf-8 -*-
"""Provides data related to text."""
from typing import List, Tuple
from mimesis.data import SAFE_COLORS
from mimesis.providers.base import BaseDataProvider
__all__ = ['Text']
class Text(BaseDataProvider):
"""Class for generating text data."""
def __init__(self, *args, **kwargs):
"""Initialize attributes.
:param locale: Current locale.
:param seed: Seed.
"""
super().__init__(*args, **kwargs)
self._datafile = 'text.json'
self.pull(self._datafile)
class Meta:
"""Class for metadata."""
name = 'text'