Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
tolstislon committed May 18, 2020
1 parent 7cbb344 commit 905e523
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 21 deletions.
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ flake8 = "==3.8.1"
pep8-naming = "==0.10.0"

[packages]
phone-gen = {editable = true,path = "."}

[requires]
python_version = "3.8"
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

[![Build Status](https://travis-ci.com/tolstislon/phone_gen.svg?branch=master)](https://travis-ci.com/tolstislon/phone_gen)
[![codecov](https://codecov.io/gh/tolstislon/phone-gen/branch/master/graph/badge.svg)](https://codecov.io/gh/tolstislon/phone-gen)

[![PyPI](https://img.shields.io/pypi/v/phone-gen?color=%2301a001&label=version&logo=version)](https://pypi.org/project/phone-gen/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/phone-gen.svg)](https://pypi.org/project/phone-gen/)
[![PyPI - Implementation](https://img.shields.io/pypi/implementation/phone-gen)](https://pypi.org/project/phone-gen/)

Phone number generator for [Google's libphonenumber library](https://github.com/google/libphonenumber)

This module was created exclusively for generating test data, when it is necessary to enter phone numbers in fields that are validated by the `libphonenumber` library or its ports.

Install
----

Installation
----
Install using pip with
```bash
pip install phone-gen
```
Expand All @@ -21,19 +25,43 @@ from phone_gen import PhoneNumber

phone_number = PhoneNumber('GB')

# Get full phone number
# Get a phone number
number = phone_number.get_number()
print(number) # +442908124840

# Get country code
# Get a country code
country_code = phone_number.get_code()
print(country_code) # 44

# Phone number without country code
# Get a phone number without a country code
number = phone_number.get_number(full=False)
print(number) # 183782623
```

##### pytest fixture
```python
import pytest
from phone_gen import PhoneNumber


@pytest.fixture
def phone_number():
def wrap(code):
return PhoneNumber(code).get_number()

yield wrap


def test_one(phone_number):
number = phone_number('DE')
...
```

Resources
----
* [libphonenumber](https://github.com/google/libphonenumber)
* Modified [strgen](https://github.com/paul-wolf/strgen) library


Contributing
----
Expand Down
17 changes: 11 additions & 6 deletions phone_gen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,23 @@ def render(self) -> str:

class PhoneNumber:
def __init__(self, code: str):
self.country = PATTERNS["data"].get(code.upper(), {})
if not self.country:
self._country = PATTERNS["data"].get(code.upper(), {})
if not self._country:
raise NumberGeneratorException("Not found country {}".format(code))
self.generator = NumberGenerator(self.country["pattern"])
self._generator = NumberGenerator(self._country["pattern"])

@property
def info(self) -> str:
return PATTERNS["info"]

def get_code(self) -> str:
return self.country["code"]
return self._country["code"]

def get_number(self, full: bool = True) -> str:
number = self.generator.render()
return "+{}{}".format(self.country["code"], number) if full else number
number = self._generator.render()
# Could not find problem fixme
if (
number.startswith("49") and self._country["code"] == "49"
): # pragma: no cover
return self.get_number(full)
return "+{}{}".format(self._country["code"], number) if full else number
2 changes: 1 addition & 1 deletion phone_gen/patterns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auto-generated file 2020-05-18 00:57:29 UTC
# Auto-generated file 2020-05-18 16:15:00 UTC
# Resource: https://github.com/google/libphonenumber v8.12.3

PATTERNS = {
Expand Down
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[mypy]
python_version = 3.5
ignore_missing_imports = True

[flake8]
max-line-length = 88
count = True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
include_package_data=True,
keywords=[],
classifiers=[
'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
Expand Down
2 changes: 1 addition & 1 deletion tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
addopts =
--cov-report html
--cov-report=xml
--cov=phone_gen tests/
-l
2 changes: 1 addition & 1 deletion tests/test_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from phone_gen.generator import NumberGeneratorException


@pytest.mark.parametrize('count', range(10))
@pytest.mark.parametrize('count', range(15))
@pytest.mark.parametrize('country', PATTERNS['data'].keys())
def test_patterns(country, count):
number = PhoneNumber(country).get_number()
Expand Down

0 comments on commit 905e523

Please sign in to comment.