Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- added company() to generate stupid company names

- other library cleanup and maintenance
- updated README and tests
  • Loading branch information...
commit ef92033624dc9a8703130e0b9048748694e23628 1 parent 9d3145d
@deepthawtz authored
View
53 README.md
@@ -18,7 +18,7 @@ Faker
=====
A Python library for generating fake user data.
-A port of Ruby's Faker library which is a port of Perl's Data::Faker library.
+Perl's got one, Ruby's got one, now Pythonistas envy no longer.
Usage
=====
@@ -31,6 +31,8 @@ Usage
"mvanilli"
>>> f.email()
"mvanilli@hotmail.com"
+ >>> f.company()
+ "Scrodiant Labs"
OR
@@ -42,25 +44,38 @@ OR
... f.email()
... f.phonenumber()
... f.full_address()
+ ... f.company()
...
- 'Ola Rice'
- 'orice'
- 'orice@hotmail.com'
- '289-554-46105'
- '824 Colleen Square\nFrancescamouth, AK 65473'
- 'Jaron Oberbrunner'
- 'joberbrunner'
- 'joberbrunner@gmail.com'
- '213-543-45170'
- '149 Fay Points 111\nWest Braulioland, MD 63587-2095'
- 'Brielle Hegmann'
- 'bhegmann'
- 'bhegmann@hotmail.com'
- '553-104-17156'
- '96397 Colleen Square\nWest Braulioland, OH 75395'
+ "Ola Rice"
+ "orice"
+ "orice@hotmail.com"
+ "289-554-46105"
+ "824 Colleen Square\nFrancescamouth, AK 65473"
+ "Yeddjam"
+ "Jaron Oberbrunner"
+ "joberbrunner"
+ "joberbrunner@gmail.com"
+ "213-543-45170"
+ "149 Fay Points 111\nWest Braulioland, MD 63587-2095"
+ "Plurbee"
+ "Brielle Hegmann"
+ "bhegmann"
+ "bhegmann@hotmail.com"
+ "553-104-17156"
+ "96397 Colleen Square\nWest Braulioland, OH 75395"
+ "Twispace"
+Installation
+============
+
+pip:
+
+ pip install faker
+
+source:
+
+ git clone git@github.com:deepthawtz/faker.git
+ cd faker
+ python setup.py install
-Feedback
-========
-Any ideas where this should go? Features that would be useful? Bugs?
View
93 faker/__init__.py
@@ -1,17 +1,20 @@
+"""A library for generating fake user data"""
+VERSION = (0,0,2)
+__version__ = ".".join(map(str, VERSION))
+__author__ = "Dylan Clendenin"
+__contact__ = "dylan.clendenin@gmail.com"
+__homepage__ = "https://github.com/deepthawtz/faker"
+__all__ = ("Faker",)
+
import random
import data
import patterns
-from utils import _rand, _numerify, _bothify, _letterify
-
-__all__ = ("Faker",)
+from utils import *
class Faker(object):
- """
- The big fat Faker
- """
def __init__(self):
self._name = ""
@@ -19,102 +22,50 @@ def __init__(self):
self._username = ""
def name(self):
- """
- get a full fake name FIRST and LAST
- """
self._name = " ".join([self.first_name(), self.last_name()])
return self._name
def first_name(self):
- """
- get just a first name
- """
- return _rand(data.FIRST_NAMES)
+ return rand(data.FIRST_NAMES)
def last_name(self):
- """
- get just a last name
- """
- return _rand(data.LAST_NAMES)
+ return rand(data.LAST_NAMES)
def username(self):
- """
- get a fake username (e.g., like real websites require)
- """
first, last = self._name.split()
self._username = "".join([first[:1], last]).lower()
return self._username
def email(self):
- """
- get a fake email address
- """
- self._email = "@".join([self.username(), self._domain()])
+ self._email = "@".join([self.username(), domain()])
return self._email
- def _domain(self):
- """
- helper method for email(), returns a common email domain
- """
- return _rand(data.FREE_EMAIL)
-
def full_address(self):
- """
- a full address: NUMBER, STREET, CITY, STATE and ZIP
- """
- return "%s\n%s, %s %s" % (self.street_address(), self.city(), self.state_abbr(), self.zip_code())
+ return "%s\n%s, %s %s" % (self.street_address(), self.city(), self.state(), self.zip_code())
def phonenumber(self):
- """
- get a phone number (e.g., ###-###-####)
- """
- return _numerify("###-###-#####")
+ return numerify("###-###-#####")
def street_address(self):
- """
- get a street address
- """
- return _numerify(random.choice(["##### %s" % patterns.STREET_NAME(),
+ return numerify(random.choice(["##### %s" % patterns.STREET_NAME(),
"#### %s Ave." % patterns.STREET_NAME(),
"### %s St." % patterns.STREET_NAME(),
- "### %s %s" % (patterns.STREET_NAME(), self._secondary_address()),
- "#### %s %s" % (patterns.STREET_NAME(), self._secondary_address())]))
-
- def _secondary_address(self):
- """
- helper method for street_address(), returns an optional secondary street
- address, like Apt. number for example
- """
- return _numerify(random.choice(["Apt. ###", "Suite ###", ""]))
+ "### %s %s" % (patterns.STREET_NAME(), secondary_address()),
+ "#### %s %s" % (patterns.STREET_NAME(), secondary_address())]))
def city(self):
- """
- get a fake city name
- """
return patterns.CITY()
- def state_abbr(self):
- """
- get a state abbreviation like CA, OH, or FL. Etc...
- """
- return _rand(data.STATE_ABBR)
+ def state(self):
+ return rand(data.STATE_ABBR)
def zip_code(self):
- """
- get a US zipcode
- """
- return _numerify(random.choice(["#####", "#####-####"]))
+ return numerify(random.choice(["#####", "#####-####"]))
- def _uk_postcode(self):
- """
- coming soon? UK addresses
- """
- return _bothify(random.choice(["??# #??","??## #??"]))
+ def company(self):
+ return patterns.COMPANY_NAME()
def lorem(self):
- """
- get a random paragraph of Latin words
- """
paragraph = []
word_list = data.WORDS.split()
random.shuffle(word_list)
View
12 faker/data.py
@@ -35,3 +35,15 @@
WORDS = u"""
alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat
"""
+
+COMPANY_NAME_PREFIX = u"""
+you my twi ya bo ad cloud ini ibi loo live day ni kos ja flo open i yo tub xo pro ra plur clax vert rem scro do kab smug fil zim glif sko zin yedd bling tru blao dot jam zu quirb jib
+"""
+
+COMPANY_NAME_SUFFIX = u"""
+trix ly sy ton era jing la box ga za zing ster sense ify you go nico chi mix mee on doodle scro diant hop ckr sauce nit bee zizzl bio doo qa zee kee space tra fish cloud monkey geo jam ba bo mo star net
+"""
+
+COMPANY_NAME_EXTRA = u"""
+media designs collective systems labs
+"""
View
22 faker/patterns.py
@@ -1,18 +1,26 @@
import random
import data
-from utils import _rand
+from utils import rand
CITY = lambda: random.choice([
- " ".join([_rand(data.CITY_PREFIX), "".join([_rand(data.FIRST_NAMES), _rand(data.CITY_SUFFIX)])]),
- " ".join([_rand(data.CITY_PREFIX), _rand(data.FIRST_NAMES)]),
- "".join([_rand(data.FIRST_NAMES), _rand(data.CITY_SUFFIX)]),
- "".join([_rand(data.LAST_NAMES), _rand(data.CITY_SUFFIX)]),
+ " ".join([rand(data.CITY_PREFIX), "".join([rand(data.FIRST_NAMES), rand(data.CITY_SUFFIX)])]),
+ " ".join([rand(data.CITY_PREFIX), rand(data.FIRST_NAMES)]),
+ "".join([rand(data.FIRST_NAMES), rand(data.CITY_SUFFIX)]),
+ "".join([rand(data.LAST_NAMES), rand(data.CITY_SUFFIX)]),
])
STREET_NAME = lambda: random.choice([
- " ".join([_rand(data.LAST_NAMES), _rand(data.STREET_SUFFIX)]),
- " ".join([_rand(data.FIRST_NAMES), _rand(data.STREET_SUFFIX)])
+ " ".join([rand(data.LAST_NAMES), rand(data.STREET_SUFFIX)]),
+ " ".join([rand(data.FIRST_NAMES), rand(data.STREET_SUFFIX)])
])
+
+COMPANY_NAME = lambda: random.choice([
+ "".join([rand(data.COMPANY_NAME_PREFIX), rand(data.COMPANY_NAME_SUFFIX)]),
+ "".join([rand(data.COMPANY_NAME_PREFIX).capitalize(), rand(data.COMPANY_NAME_SUFFIX)]),
+ "".join([rand(data.COMPANY_NAME_PREFIX).capitalize(), rand(data.COMPANY_NAME_SUFFIX).capitalize()]),
+ "%s %s" % ("".join([rand(data.COMPANY_NAME_PREFIX).capitalize(), rand(data.COMPANY_NAME_SUFFIX)]), rand(data.COMPANY_NAME_EXTRA).capitalize())
+])
+
View
20 faker/utils.py
@@ -1,9 +1,21 @@
import re
import random
+import data
-_rand = lambda x: random.choice(x.split())
-_numerify = lambda x: "".join([re.sub("#", str(random.randint(0,9)), i) for i in x])
-_letterify = lambda x: "".join([re.sub(r"\?", random.choice([chr(i) for i in range(ord('A'), ord('Z')+1)]), y) for y in x])
-_bothify = lambda x: _letterify(_numerify(x))
+
+rand = lambda x: random.choice(x.split())
+numerify = lambda x: "".join([re.sub("#", str(random.randint(0,9)), i) for i in x])
+letterify = lambda x: "".join([re.sub(r"\?", random.choice([chr(i) for i in range(ord('A'), ord('Z')+1)]), y) for y in x])
+bothify = lambda x: letterify(numerify(x))
+
+def domain():
+ return rand(data.FREE_EMAIL)
+
+def secondary_address():
+ return numerify(random.choice(["Apt. ###", "Suite ###", ""]))
+
+def uk_postcode():
+ return bothify(random.choice(["??# #??","??## #??"]))
+
View
16 setup.py
@@ -1,14 +1,16 @@
#!/usr/bin/env python
+import codecs
from setuptools import setup, find_packages
+import faker
setup(name="Faker",
- version="0.0.1",
- description="A port of Ruby's Faker library for generating fake user data",
- long_description="Often you want to generate user data but without all the thinking and typing. This is a library for that.",
- author="Dylan Clendenin",
- author_email="dylan.clendenin@gmail.com",
- url="http://github.com/deepthawtz/faker",
+ version=faker.__version__,
+ description=faker.__doc__,
+ long_description=codecs.open("README.md", "r", "utf-8").read(),
+ author=faker.__author__,
+ author_email=faker.__contact__,
+ url=faker.__homepage__,
packages=find_packages(),
test_suite="nose.collector",
tests_require=["nose"],
@@ -26,4 +28,4 @@
"License :: OSI Approved :: MIT License",
],
license="MIT",
- )
+)
View
11 tests/test_api.py
@@ -11,7 +11,7 @@ def setup():
def test_instance():
ok_(isinstance(f, Faker), msg="object should be instance of Faker")
-def test_fake_name():
+def test_name():
pattern = re.compile(r"(\w+\.? ?){2,3}")
name = f.name()
ok_(pattern.match(name))
@@ -21,7 +21,7 @@ def test_username():
username = f.username()
ok_(pattern.match(username))
-def test_fake_email():
+def test_email():
pattern = re.compile(r".+@.+\.\w+")
email = f.email()
ok_(pattern.match(email))
@@ -48,3 +48,10 @@ def test_phonenumber():
pattern = re.compile(r"\d{3}-\d{3}-\d{4}")
phonenumber = f.phonenumber()
ok_(pattern.match(phonenumber))
+
+def test_company():
+ pattern = re.compile(r"\w{1,3}")
+ for i in range(10):
+ company = f.company()
+ ok_(pattern.match(company))
+
View
13 tests/test_utils.py
@@ -1,25 +1,26 @@
import re
-from faker.utils import _rand, _numerify, _letterify, _bothify
+from faker.utils import *
def test_rand():
possible = ["one", "two", "three"]
string = "one two three"
- output = _rand(string)
+ output = rand(string)
assert output in possible
def test_numerify():
pattern = re.compile(r"\d{3}-\d{4}")
- output = _numerify("###-####")
+ output = numerify("###-####")
assert pattern.match(output)
def test_letterify():
pattern = re.compile(r"[A-Z]{4}")
- output = _letterify("????")
+ output = letterify("????")
assert pattern.match(output)
def test_bothify():
pattern = re.compile(r"[A-Z]{2}\d{1}[A-Z]\d{3}")
- output = _bothify("??#?###")
- assert pattern.match(output)
+ output = bothify("??#?###")
+ assert pattern.match(output)
+
Please sign in to comment.
Something went wrong with that request. Please try again.