Skip to content

Commit

Permalink
v0.1.0, much more options added
Browse files Browse the repository at this point in the history
  • Loading branch information
Atrox committed Mar 26, 2015
1 parent 5720155 commit 2daa319
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 42 deletions.
25 changes: 2 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
Expand Down Expand Up @@ -32,23 +29,5 @@ var/
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/
# IDEA
.idea
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Haikunator
# HaikunatorPY

[![Build Status](https://img.shields.io/travis/Atrox/haikunatorpy.svg?style=flat-square)](https://travis-ci.org/Atrox/haikunatorpy)
[![Latest Version](https://img.shields.io/pypi/v/haikunator.svg?style=flat-square)](https://pypi.python.org/pypi/haikunator)
Expand All @@ -18,18 +18,37 @@ Haikunator is pretty simple. There is nothing to configure and it only has a sin
```python
from haikunator import haikunate

haikunate() # => "caring-butterfly-0291"
# default usage
haikunate() # => "wispy-dust-1337"

# Hex
haikunate(True) # => "autumn-pine-c42c"
# custom length (default=4)
haikunate(tokenLength=6) # => "patient-king-887265"

# use hex instead of numbers
haikunate(tokenHex=True) # => "purple-breeze-98e1"

# use custom chars instead of numbers/hex
haikunate(tokenChars='HAIKUNATE') # => "summer-atom-IHEA"

# don't include a token
haikunate(tokenLength=0) # => "cold-wildflower"

# use a different delimiter
haikunate(delimiter='.') # => "restless.sea.7976"

# no token, space delimiter
haikunate(tokenLength=0, delimiter=' ') # => "delicate haze"

# no token, empty delimiter
haikunate(tokenLength=0, delimiter='') # => "billowingleaf"
```

## Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

- [Report bugs](https://github.com/atrox/haikunator/issues)
- Fix bugs and [submit pull requests](https://github.com/atrox/haikunator/pulls)
- [Report bugs](https://github.com/atrox/haikunatorpy/issues)
- Fix bugs and [submit pull requests](https://github.com/atrox/haikunatorpy/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features

Expand Down
28 changes: 19 additions & 9 deletions haikunator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
from six.moves import range


def haikunate(hex=False):
# example output:
# 'dawn-ring-1337'
def haikunate(delimiter='-', tokenLength=4, tokenHex=False, tokenChars='0123456789'):
"""
Generate Heroku-like random names to use in your applications.
:param delimiter:
:param tokenLength:
:param tokenHex:
:param tokenChars:
:return: string
"""
adjs = ['afternoon', 'aged', 'ancient', 'autumn', 'billowing',
'bitter', 'black', 'blue', 'bold', 'broken',
'calm', 'caring', 'cold', 'cool', 'crimson',
Expand Down Expand Up @@ -41,9 +47,13 @@ def haikunate(hex=False):
'waterfall', 'wave', 'wave', 'wildflower', 'wind',
'wood',
]
if hex:
suffix = '0123456789abcdef'
else:
suffix = '0123456789'
return ('-'.join([choice(adjs), choice(nouns),
''.join(choice(suffix) for x in range(4))]))

if tokenHex:
tokenChars = "0123456789abcdef"

adj = choice(adjs)
noun = choice(nouns)
token = ''.join(choice(tokenChars) for _ in range(tokenLength))

sections = [adj, noun, token]
return delimiter.join(filter(None, sections))
31 changes: 29 additions & 2 deletions haikunator/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,35 @@


class HaikunatorTests(unittest.TestCase):
def test_basics(self):
six.assertRegex(self, haikunate(), "((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+))(-)(\d+)")
def test_default_use(self):
six.assertRegex(self, haikunate(), "((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+))(-)(\\d{4})$")

def test_hex_use(self):
six.assertRegex(self, haikunate(tokenHex=True), "((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+))(-)(.{4})$")

def test_9digits_use(self):
six.assertRegex(self, haikunate(tokenLength=9), "((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+))(-)(\\d{9})$")

def test_9digitsashex_use(self):
six.assertRegex(self, haikunate(tokenHex=True, tokenLength=9), "((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+))(-)(.{9})$")

def test_wont_return_same(self):
self.assertNotEqual(haikunate(), haikunate())

def test_drops_token(self):
six.assertRegex(self, haikunate(tokenLength=0), "((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+))$")

def test_permits_optional_delimiter(self):
six.assertRegex(self, haikunate(delimiter='.'), "((?:[a-z][a-z]+))(\\.)((?:[a-z][a-z]+))(\\.)(\\d+)$")

def test_spacedelimiter_and_notoken(self):
six.assertRegex(self, haikunate(delimiter=' ', tokenLength=0), "((?:[a-z][a-z]+))( )((?:[a-z][a-z]+))$")

def test_onesingleword(self):
six.assertRegex(self, haikunate(delimiter='', tokenLength=0), "((?:[a-z][a-z]+))$")

def test_customchars(self):
six.assertRegex(self, haikunate(tokenChars='A'), "((?:[a-z][a-z]+))(-)((?:[a-z][a-z]+))(-)(AAAA)$")

if __name__ == '__main__':
unittest.main()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup

CLASSIFIERS = [
'Development Status :: 3 - Alpha',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: OS Independent',
Expand All @@ -20,7 +20,7 @@
author_email='[email protected]',
description='Heroku-like random name generator for python.',
license='GPLv3',
version='0.0.2',
version='0.1.0',
url='https://github.com/Atrox/haikunatorpy',
packages=['haikunator'],
test_suite='haikunator.tests',
Expand Down

0 comments on commit 2daa319

Please sign in to comment.