Skip to content

Commit

Permalink
Merge branch 'master' of github.com:joke2k/faker
Browse files Browse the repository at this point in the history
  • Loading branch information
joke2k committed Sep 21, 2015
2 parents 7fdc1d2 + 2b691cd commit 832487a
Show file tree
Hide file tree
Showing 43 changed files with 1,661 additions and 195 deletions.
5 changes: 3 additions & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[bumpversion]
current_version = 0.5.2
current_version = 0.5.3
files = setup.py faker/__init__.py docs/conf.py

commit = True
tag = True
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ python:
- "pypy3"
install:
- pip install -e .
- pip install -r faker/tests/requirements.txt
- pip install coveralls
script:
- coverage run --source=faker setup.py test
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
Changelog
=========

`0.5.3 - TBD`__
---------------

* Added `company_vat` to company `fi_FI` provider. Thanks @kivipe.
* Seed a Random instance instead of the module. Thanks Amy Hanlon.
* Fixed en_GB postcodes to be more realistic. Thanks @mapleoin for the report.
* Fixed support for Python 3 in the python provider. Thanks @derekjamescurtis.
* Fixed U.S. SSN generation. Thanks @jschaf.
* Use environment markers for wheels. Thanks @RonnyPfannschmidt
* Fixed Python3 issue in `pyiterable` and `pystruct` providers. Thanks @derekjamescurtis.
* Fixed `en_GB` postcodes to be more realistic. Thanks @mapleoin.
* Fixed and improved performance of credit card number provider. Thanks @0x000.
* Added Brazilian SSN, aka CPF. Thanks @ericchaves.
* Added female and male names for `fa_IR`. Thanks @afshinrodgar.
* Fixed issues with Decimal objects as input to geo_coordinate. Thanks @davy.
* Fixed bug for `center` set to `None` in geo_coordinate. Thanks @davy.
* Fixed deprecated image URL placeholder services.
* Fixed provider's example formatting in documentation.
* Added en_AU provider. Thanks @xfxf.

`0.5.2 - 11-June-2015 <http://github.com/joke2k/faker/compare/v0.5.1...v0.5.2>`__
---------------------------------------------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Included localized providers:
- `de\_DE <http://fake-factory.readthedocs.org/en/master/locales/de_DE.html>`__ - German
- `dk\_DK <http://fake-factory.readthedocs.org/en/master/locales/dk_DK.html>`__ - Danish
- `el\_GR <http://fake-factory.readthedocs.org/en/master/locales/el_GR.html>`__ - Greek
- `en\_AU <http://fake-factory.readthedocs.org/en/master/locales/en_AU.html>`__ - English (Australia)
- `en\_CA <http://fake-factory.readthedocs.org/en/master/locales/en_CA.html>`__ - English (Canada)
- `en\_GB <http://fake-factory.readthedocs.org/en/master/locales/en_GB.html>`__ - English (Great Britain)
- `en\_US <http://fake-factory.readthedocs.org/en/master/locales/en_US.html>`__ - English (United States)
Expand Down Expand Up @@ -280,6 +281,11 @@ same results.
Tests
-----
Installing dependencies:
.. code:: bash
$ pip install -r faker/tests/requirements.txt
Run tests:
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ install:
- ps: (new-object net.webclient).DownloadFile('https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 'C:/get-pip.py')
- "%PYTHON%/python.exe C:/get-pip.py"
- "%PYTHON%/Scripts/pip.exe install -e ."
- "%PYTHON%/Scripts/pip.exe install -r faker/tests/requirements.txt"
test_script:
- "%PYTHON%/Scripts/pip.exe --version"
- "%PYTHON%/python.exe setup.py test"
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
pre:
- pip install -r faker/tests/requirements.txt
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
# built documents.
#
# The short X.Y version.
version = '0.5.2'
version = '0.5.3'
# The full version, including alpha/beta/rc tags.
release = '0.5.2'
release = '0.5.3'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Included localized providers:
- `de\_DE <http://fake-factory.readthedocs.org/en/master/locales/de_DE.html>`__ - German
- `dk\_DK <http://fake-factory.readthedocs.org/en/master/locales/dk_DK.html>`__ - Danish
- `el\_GR <http://fake-factory.readthedocs.org/en/master/locales/el_GR.html>`__ - Greek
- `en\_AU <http://fake-factory.readthedocs.org/en/master/locales/en_AU.html>`__ - English (Australia)
- `en\_CA <http://fake-factory.readthedocs.org/en/master/locales/en_CA.html>`__ - English (Canada)
- `en\_GB <http://fake-factory.readthedocs.org/en/master/locales/en_GB.html>`__ - English (Great Britain)
- `en\_US <http://fake-factory.readthedocs.org/en/master/locales/en_US.html>`__ - English (United States)
Expand Down
2 changes: 1 addition & 1 deletion faker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = '0.5.2'
VERSION = '0.5.3'

from faker.generator import Generator
from faker.factory import Factory
Expand Down
7 changes: 0 additions & 7 deletions faker/bin/faker

This file was deleted.

21 changes: 8 additions & 13 deletions faker/build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import unicode_literals

import os
import pprint
import sys


Expand Down Expand Up @@ -37,24 +38,18 @@ def write_provider(fh, doc, provider, formatters, excludes=None):
if signature in excludes:
continue
try:
# `pprint` can't format sets of heterogenous types.
if not isinstance(example, set):
example = pprint.pformat(example, indent=4)
lines = text_type(example).expandtabs().splitlines()
except UnicodeEncodeError:
msg = 'error on "{0}" with value "{1}"'.format(signature, example)
raise Exception(msg)
margin = max(30, doc.max_name_len+1)
remains = 150 - margin
separator = '#'
write(fh, '\n')
for line in lines:
for i in range(0, (len(line) // remains) + 1):
write(fh, "\t{fake:<{margin}}{separator} {example}".format(
fake=signature,
separator=separator,
example=line[i*remains:(i+1)*remains],
margin=margin
))
signature = separator = ' '
write(fh, '\n')
write(fh, "\t{fake}\n{example}\n".format(
fake=signature,
example='\n'.join(['\t# ' + line for line in lines]),
))


def write_docs(*args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions faker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


_re_token = re.compile(r'\{\{(\s?)(\w+)(\s?)\}\}')
random = random.Random()


class Generator(object):
Expand Down
3 changes: 2 additions & 1 deletion faker/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# coding=utf-8

import re
import random
import string

from faker.generator import random
from faker.utils.distribution import choice_distribution


Expand Down
8 changes: 5 additions & 3 deletions faker/providers/address/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding=utf-8
from __future__ import unicode_literals
from decimal import Decimal
import random

from .. import BaseProvider
from .. import date_time
from faker.generator import random

localized = True

Expand Down Expand Up @@ -90,11 +90,13 @@ def geo_coordinate(cls, center=None, radius=0.001):
"""
Optionally center the coord and pick a point within radius.
"""
if not center:
if center is None:
return Decimal(str(random.randint(-180000000, 180000000) / 1000000.0)).quantize(Decimal('.000001'))
else:
center = float(center)
radius = float(radius)
geo = random.uniform(center - radius, center + radius)
return Decimal(str(geo))
return Decimal(str(geo)).quantize(Decimal('.000001'))

@classmethod
def latitude(cls):
Expand Down
3 changes: 2 additions & 1 deletion faker/providers/address/el_GR/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# coding=utf-8
from __future__ import unicode_literals
from decimal import Decimal
import random

from .. import Provider as AddressProvider
from faker.generator import random


def contains_point(poly, point):
Expand Down
109 changes: 109 additions & 0 deletions faker/providers/address/en_AU/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from __future__ import unicode_literals

from ..en import Provider as AddressProvider
from faker.generator import random

class Provider(AddressProvider):

city_prefixes = ('North', 'East', 'West', 'South', 'New', 'Lake', 'Port', 'St.')

city_suffixes = (
'town', 'ton', 'land', 'ville', 'berg', 'burgh', 'borough', 'bury', 'view', 'port', 'mouth', 'stad', 'furt',
'chester', 'mouth', 'fort', 'haven', 'side', 'shire')

building_number_formats = ('###', '##', '#')

street_suffixes = (
'Access', 'Alley', 'Alleyway', 'Amble', 'Anchorage', 'Approach', 'Arcade', 'Artery', 'Avenue', 'Basin',
'Beach', 'Bend', 'Block', 'Boulevard', 'Brace', 'Brae', 'Break', 'Bridge', 'Broadway', 'Brow', 'Bypass',
'Byway', 'Causeway', 'Centre', 'Centreway', 'Chase', 'Circle', 'Circlet', 'Circuit', 'Circus', 'Close',
'Colonnade', 'Common', 'Concourse', 'Copse', 'Corner', 'Corso', 'Court', 'Courtyard', 'Cove', 'Crescent',
'Crest', 'Cross', 'Crossing', 'Crossroad', 'Crossway', 'Cruiseway', 'Cul-de-sac', 'Cutting', 'Dale', 'Dell',
'Deviation', 'Dip', 'Distributor', 'Drive', 'Driveway', 'Edge', 'Elbow', 'End', 'Entrance', 'Esplanade',
'Estate', 'Expressway', 'Extension', 'Fairway', 'Fire Track', 'Firetrail', 'Flat', 'Follow', 'Footway',
'Foreshore', 'Formation', 'Freeway', 'Front', 'Frontage', 'Gap', 'Garden', 'Gardens', 'Gate', 'Gates',
'Glade', 'Glen', 'Grange', 'Green', 'Ground', 'Grove', 'Gully', 'Heights', 'Highroad', 'Highway', 'Hill',
'Interchange', 'Intersection', 'Junction', 'Key', 'Landing', 'Lane', 'Laneway', 'Lees', 'Line', 'Link',
'Little', 'Lookout', 'Loop', 'Lower', 'Mall', 'Meander', 'Mew', 'Mews', 'Motorway', 'Mount', 'Nook', 'Outlook',
'Parade', 'Park', 'Parklands', 'Parkway', 'Part', 'Pass', 'Path', 'Pathway', 'Piazza', 'Place', 'Plateau',
'Plaza', 'Pocket', 'Point', 'Port', 'Promenade', 'Quad', 'Quadrangle', 'Quadrant', 'Quay', 'Quays', 'Ramble',
'Ramp', 'Range', 'Reach', 'Reserve', 'Rest', 'Retreat', 'Ride', 'Ridge', 'Ridgeway', 'Right Of Way', 'Ring',
'Rise', 'River', 'Riverway', 'Riviera', 'Road', 'Roads', 'Roadside', 'Roadway', 'Ronde', 'Rosebowl', 'Rotary',
'Round', 'Route', 'Row', 'Rue', 'Run', 'Service Way', 'Siding', 'Slope', 'Sound', 'Spur', 'Square', 'Stairs',
'State Highway', 'Steps', 'Strand', 'Street', 'Strip', 'Subway', 'Tarn', 'Terrace', 'Thoroughfare', 'Tollway',
'Top', 'Tor', 'Towers', 'Track', 'Trail', 'Trailer', 'Triangle', 'Trunkway', 'Turn', 'Underpass', 'Upper',
'Vale', 'Viaduct', 'View', 'Villas', 'Vista', 'Wade', 'Walk', 'Walkway', 'Way', 'Wynd')

postcode_formats = (
# as per https://en.wikipedia.org/wiki/Postcodes_in_Australia
# NSW
'1###',
'20##', '21##', '22##', '23##', '24##', '25##',
'2619', '262#', '263#', '264#', '265#', '266#', '267#', '268#', '269#', '27##', '28##',
'292#', '293#', '294#', '295#', '296#', '297#', '298#', '299#',
# ACT
'02##',
'260#', '261#',
'290#', '291#', '2920',
# VIC
'3###',
'8###',
# QLD
'4###',
'9###',
# SA
'5###',
# WA
'6###',
# TAS
'7###',
# NT
'08##',
'09##',
)

states = (
'Australian Capital Territory', 'New South Wales', 'Northern Territory', 'Queensland', 'South Australia',
'Tasmania', 'Victoria', 'Western Australia')

states_abbr = (
'ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC', 'WA')

city_formats = (
'{{city_prefix}} {{first_name}}{{city_suffix}}',
'{{city_prefix}} {{first_name}}',
'{{first_name}}{{city_suffix}}',
'{{last_name}}{{city_suffix}}',
)

street_name_formats = (
'{{first_name}} {{street_suffix}}',
'{{last_name}} {{street_suffix}}'
)

street_address_formats = (
'{{building_number}} {{street_name}}',
'{{secondary_address}}\n {{building_number}} {{street_name}}',
)

address_formats = (
"{{street_address}}\n{{city}}, {{state_abbr}}, {{postcode}}",
)

secondary_address_formats = ('Apt. ###', 'Flat ##', 'Suite ###', 'Unit ##', 'Level #', '### /', '## /', '# /')

@classmethod
def city_prefix(cls):
return cls.random_element(cls.city_prefixes)

@classmethod
def secondary_address(cls):
return cls.numerify(cls.random_element(cls.secondary_address_formats))

@classmethod
def state(cls):
return cls.random_element(cls.states)

@classmethod
def state_abbr(cls):
return cls.random_element(cls.states_abbr)
50 changes: 49 additions & 1 deletion faker/providers/address/en_GB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,44 @@ class Provider(AddressProvider):
'view', 'views', 'village', 'village', 'villages', 'ville', 'vista', 'vista', 'walk', 'walks', 'wall', 'way',
'ways', 'well', 'wells')

postcode_formats = ('??#? #??', '?#? #??', '?# #??', '?## #??', '??# #??', '??## #??',)
POSTAL_ZONES = (
'AB', 'AL', 'B' , 'BA', 'BB', 'BD', 'BH', 'BL', 'BN', 'BR',
'BS', 'BT', 'CA', 'CB', 'CF', 'CH', 'CM', 'CO', 'CR', 'CT',
'CV', 'CW', 'DA', 'DD', 'DE', 'DG', 'DH', 'DL', 'DN', 'DT',
'DY', 'E' , 'EC', 'EH', 'EN', 'EX', 'FK', 'FY', 'G' , 'GL',
'GY', 'GU', 'HA', 'HD', 'HG', 'HP', 'HR', 'HS', 'HU', 'HX',
'IG', 'IM', 'IP', 'IV', 'JE', 'KA', 'KT', 'KW', 'KY', 'L' ,
'LA', 'LD', 'LE', 'LL', 'LN', 'LS', 'LU', 'M' , 'ME', 'MK',
'ML', 'N' , 'NE', 'NG', 'NN', 'NP', 'NR', 'NW', 'OL', 'OX',
'PA', 'PE', 'PH', 'PL', 'PO', 'PR', 'RG', 'RH', 'RM', 'S' ,
'SA', 'SE', 'SG', 'SK', 'SL', 'SM', 'SN', 'SO', 'SP', 'SR',
'SS', 'ST', 'SW', 'SY', 'TA', 'TD', 'TF', 'TN', 'TQ', 'TR',
'TS', 'TW', 'UB', 'W' , 'WA', 'WC', 'WD', 'WF', 'WN', 'WR',
'WS', 'WV', 'YO', 'ZE'
)

POSTAL_ZONES_ONE_CHAR = [zone for zone in POSTAL_ZONES if len(zone) == 1]
POSTAL_ZONES_TWO_CHARS = [zone for zone in POSTAL_ZONES if len(zone) == 2]

postcode_formats = (
'AN NEE',
'ANN NEE',
'PN NEE',
'PNN NEE',
'ANC NEE',
'PND NEE',
)

_postcode_sets = {
' ': ' ',
'N': [str(i) for i in range(0, 10)],
'A': POSTAL_ZONES_ONE_CHAR,
'B': 'ABCDEFGHKLMNOPQRSTUVWXY',
'C': 'ABCDEFGHJKSTUW',
'D': 'ABEHMNPRVWXY',
'E': 'ABDEFGHJLNPQRSTUWXYZ',
'P': POSTAL_ZONES_TWO_CHARS,
}

city_formats = (
'{{city_prefix}} {{first_name}}{{city_suffix}}',
Expand All @@ -61,6 +98,17 @@ class Provider(AddressProvider):
)
secondary_address_formats = ('Flat #', 'Flat ##', 'Flat ##?', 'Studio #', 'Studio ##', 'Studio ##?')

@classmethod
def postcode(cls):
"""
See http://web.archive.org/web/20090930140939/http://www.govtalk.gov.uk/gdsc/html/noframes/PostCode-2-1-Release.htm
"""
postcode = ''
pattern = cls.random_element(cls.postcode_formats)
for placeholder in pattern:
postcode += cls.random_element(cls._postcode_sets[placeholder])
return postcode

@classmethod
def city_prefix(cls):
return cls.random_element(cls.city_prefixes)
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/address/en_US/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
import random

from ..en import Provider as AddressProvider
from faker.generator import random


class Provider(AddressProvider):
Expand Down
Loading

0 comments on commit 832487a

Please sign in to comment.