-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tolstislon/add_cli
Added cli
- Loading branch information
Showing
11 changed files
with
160 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,4 +133,5 @@ dmypy.json | |
|
||
# Other | ||
Pipfile.lock | ||
phone_gen/__version__.py | ||
phone_gen/__version__.py | ||
/TODO.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import argparse | ||
|
||
from . import __version__ | ||
from ._generator import NumberGeneratorException, PhoneNumber, PhoneNumberNotFound | ||
|
||
parser = argparse.ArgumentParser( | ||
prog="phone-gen", | ||
add_help=True, | ||
description="International phone number generation", | ||
) | ||
parser.add_argument( | ||
"-v", "--version", action="version", version="%(prog)s {}".format(__version__) | ||
) | ||
parser.add_argument("country", help="Country code example: GB", metavar="country") | ||
parser.add_argument( | ||
"-n", | ||
"--not-full", | ||
action="store_false", | ||
help="Get a phone number without a country code", | ||
dest="full", | ||
) | ||
|
||
|
||
def main(): | ||
args = parser.parse_args() | ||
try: | ||
print(PhoneNumber(args.country).get_number(args.full)) | ||
except (PhoneNumberNotFound, NumberGeneratorException) as error: | ||
print("Error: {}".format(error.args[0])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,17 @@ | |
license='MIT License', | ||
author='tolstislon', | ||
author_email='[email protected]', | ||
description='Phone number generator for libphonenumber', | ||
description='International phone number generation', | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
use_scm_version={"write_to": "phone_gen/__version__.py"}, | ||
setup_requires=['setuptools_scm'], | ||
entry_points={ | ||
'console_scripts': ['phone-gen=phone_gen.cli:main'], | ||
}, | ||
python_requires='>=3.5', | ||
include_package_data=True, | ||
keywords=[], | ||
keywords=['testing', 'test-data', 'phone-number', 'phone'], | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Intended Audience :: Developers', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import random | ||
|
||
import phonenumbers | ||
import pytest | ||
|
||
from phone_gen.patterns import PATTERNS | ||
|
||
|
||
@pytest.mark.parametrize('country', random.sample(tuple(PATTERNS['data'].keys()), 20)) | ||
def test_get_country(capfd, country): | ||
os.system('phone-gen {}'.format(country)) | ||
captured = capfd.readouterr() | ||
num_obg = phonenumbers.parse(captured.out, country) | ||
assert phonenumbers.is_valid_number_for_region(num_obg, country) | ||
|
||
|
||
@pytest.mark.parametrize('country', random.sample(tuple(PATTERNS['data'].keys()), 20)) | ||
def test_get_without_country_code(capfd, country): | ||
os.system('phone-gen {} -n'.format(country)) | ||
captured = capfd.readouterr() | ||
code = PATTERNS['data'][country]['code'] | ||
num_obg = phonenumbers.parse('{}{}'.format(code, captured.out), country) | ||
assert phonenumbers.is_valid_number_for_region(num_obg, country) | ||
|
||
|
||
def test_invalid_country(capfd): | ||
os.system('phone-gen qwe') | ||
captured = capfd.readouterr() | ||
assert captured.out.strip() == 'Error: Not found country qwe' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters