How to use the mimesis.exceptions.NonEnumerableError function in mimesis

To help you get started, we’ve selected a few mimesis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lk-geimfari / mimesis / tests / test_providers / test_numbers.py View on Github external
def test_matrix(self, numbers):

        with pytest.raises(NonEnumerableError):
            numbers.matrix(num_type='int')

        result = numbers.matrix(rounding=4)
        assert len(result) == 10
        for row in result:
            assert len(row) == 10
            for e in row:
                assert isinstance(e, float)
                assert len(str(e).split('.')[1]) <= 4

        result = numbers.matrix(m=5, n=5, num_type=NumTypes.INTEGERS, start=5)
        assert len(result) == 5
        for row in result:
            assert len(row) == 5
            assert min(row) >= 5
            for e in row:
github lk-geimfari / mimesis / tests / test_providers / test_person.py View on Github external
def test_name_unexpected_gender(self, person):
        with pytest.raises(NonEnumerableError):
            person.name(gender='nil')
github lk-geimfari / mimesis / tests / test_providers / test_code.py View on Github external
def test_ean_non_enum(self, code):
        with pytest.raises(NonEnumerableError):
            code.ean(fmt='nil')
github lk-geimfari / mimesis / tests / test_providers / test_address.py View on Github external
def test_country_code(self, _address, fmt, length):
        iso = _address.country_code(fmt=fmt)

        if fmt is not None:
            assert iso in COUNTRY_CODES[fmt.value]

        assert len(iso) == length or len(iso) in length

        with pytest.raises(NonEnumerableError):
            _address.country_code(fmt='nil')
github lk-geimfari / mimesis / tests / test_providers / test_internet.py View on Github external
def test_network_protocol_exception(self, net):
        with pytest.raises(NonEnumerableError):
            net.network_protocol(layer='nil')
github lk-geimfari / mimesis / tests / test_providers / test_person.py View on Github external
def test_title(self, person, gender, title_type):
        result = person.title(gender=gender, title_type=title_type)
        assert result is not None

        with pytest.raises(NonEnumerableError):
            person.title(title_type='nil')
            person.title(gender='nil')
github lk-geimfari / mimesis / tests / test_providers / test_code.py View on Github external
def test_isbn_non_enum(self, code):
        with pytest.raises(NonEnumerableError):
            code.isbn(fmt='nil')
github lk-geimfari / mimesis / tests / test_providers / test_base.py View on Github external
def test_validate_enum(self, base_data_provider, gender, excepted):
        result = base_data_provider._validate_enum(gender, Gender)

        assert (result == excepted) or (result in excepted)
        assert result in [item.value for item in Gender]

        with pytest.raises(NonEnumerableError):
            base_data_provider._validate_enum('', '')
github lk-geimfari / mimesis / tests / test_builtins / ru / test_russia_spec.py View on Github external
def test_patronymic(russia, gender):
    result = russia.patronymic(gender=gender)

    assert result is not None
    assert len(result) >= 4

    with pytest.raises(NonEnumerableError):
        russia.patronymic(gender='nil')
github lk-geimfari / mimesis / mimesis / providers / payment.py View on Github external
if card_type is None:
            card_type = get_random_item(CardType, rnd=self.random)

        if card_type == CardType.VISA:
            number = self.random.randint(4000, 4999)
        elif card_type == CardType.MASTER_CARD:
            number = self.random.choice([
                self.random.randint(2221, 2720),
                self.random.randint(5100, 5599),
            ])
        elif card_type == CardType.AMERICAN_EXPRESS:
            number = self.random.choice([34, 37])
            length = 15
            regex = re.compile(r'(\d{4})(\d{6})(\d{5})')
        else:
            raise NonEnumerableError(CardType)

        str_num = str(number)
        while len(str_num) < length - 1:
            str_num += self.random.choice(string.digits)

        groups = regex.search(  # type: ignore
            str_num + luhn_checksum(str_num),
        ).groups()
        card = ' '.join(groups)
        return card