inflection-0.3.1/ 0000755 0000765 0000024 00000000000 12521353554 014070 5 ustar janne staff 0000000 0000000 inflection-0.3.1/CHANGES.rst 0000644 0000765 0000024 00000001561 12521353365 015675 0 ustar janne staff 0000000 0000000 Changelog
---------
Here you can see the full list of changes between each Inflection release.
0.3.1 (May 3, 2015)
^^^^^^^^^^^^^^^^^^^
- Fixed trove classifiers not showing up on PyPI.
- Fixed "human" pluralized as "humen" and not "humans".
- Fixed "potato" pluralized as "potatos" and not "potatoes".
0.3.0 (March 1, 2015)
+++++++++++++++++++++
- Added `tableize()` function.
0.2.1 (September 3, 2014)
+++++++++++++++++++++++++
- Added Python 2, Python 3 and Python 3.4 trove classifiers.
0.2.0 (June 15, 2013)
+++++++++++++++++++++
- Added initial support for Python 3.
- Dropped Python 2.5 support.
0.1.2 (March 13, 2012)
++++++++++++++++++++++
- Added Python 2.5 support.
0.1.1 (February 24, 2012)
+++++++++++++++++++++++++
- Fixed some files not included in the distribution package.
0.1.0 (February 24, 2012)
+++++++++++++++++++++++++
- Initial public release
inflection-0.3.1/inflection.egg-info/ 0000755 0000765 0000024 00000000000 12521353554 017714 5 ustar janne staff 0000000 0000000 inflection-0.3.1/inflection.egg-info/dependency_links.txt 0000644 0000765 0000024 00000000001 12521353553 023761 0 ustar janne staff 0000000 0000000
inflection-0.3.1/inflection.egg-info/not-zip-safe 0000644 0000765 0000024 00000000001 11721754765 022154 0 ustar janne staff 0000000 0000000
inflection-0.3.1/inflection.egg-info/PKG-INFO 0000644 0000765 0000024 00000006067 12521353553 021021 0 ustar janne staff 0000000 0000000 Metadata-Version: 1.1
Name: inflection
Version: 0.3.1
Summary: A port of Ruby on Rails inflector to Python
Home-page: http://github.com/jpvanhal/inflection
Author: Janne Vanhala
Author-email: janne.vanhala@gmail.com
License: MIT
Description: Inflection
==========
|build status|_
.. |build status| image:: https://secure.travis-ci.org/jpvanhal/inflection.png?branch=master
:alt: Build Status
.. _build status: http://travis-ci.org/jpvanhal/inflection
Inflection is a string transformation library. It singularizes and pluralizes
English words, and transforms strings from CamelCase to underscored string.
Inflection is a port of `Ruby on Rails`_' `inflector`_ to Python.
.. _Ruby on Rails: http://rubyonrails.org
.. _inflector: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
Resources
---------
- `Documentation `_
- `Issue Tracker `_
- `Code `_
- `Development Version
`_
Changelog
---------
Here you can see the full list of changes between each Inflection release.
0.3.1 (May 3, 2015)
^^^^^^^^^^^^^^^^^^^
- Fixed trove classifiers not showing up on PyPI.
- Fixed "human" pluralized as "humen" and not "humans".
- Fixed "potato" pluralized as "potatos" and not "potatoes".
0.3.0 (March 1, 2015)
+++++++++++++++++++++
- Added `tableize()` function.
0.2.1 (September 3, 2014)
+++++++++++++++++++++++++
- Added Python 2, Python 3 and Python 3.4 trove classifiers.
0.2.0 (June 15, 2013)
+++++++++++++++++++++
- Added initial support for Python 3.
- Dropped Python 2.5 support.
0.1.2 (March 13, 2012)
++++++++++++++++++++++
- Added Python 2.5 support.
0.1.1 (February 24, 2012)
+++++++++++++++++++++++++
- Fixed some files not included in the distribution package.
0.1.0 (February 24, 2012)
+++++++++++++++++++++++++
- Initial public release
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: Implementation :: PyPy
inflection-0.3.1/inflection.egg-info/SOURCES.txt 0000644 0000765 0000024 00000000407 12521353554 021601 0 ustar janne staff 0000000 0000000 CHANGES.rst
LICENSE
MANIFEST.in
README.rst
inflection.py
setup.cfg
setup.py
test_inflection.py
inflection.egg-info/PKG-INFO
inflection.egg-info/SOURCES.txt
inflection.egg-info/dependency_links.txt
inflection.egg-info/not-zip-safe
inflection.egg-info/top_level.txt inflection-0.3.1/inflection.egg-info/top_level.txt 0000644 0000765 0000024 00000000013 12521353553 022437 0 ustar janne staff 0000000 0000000 inflection
inflection-0.3.1/inflection.py 0000644 0000765 0000024 00000025512 12521353372 016577 0 ustar janne staff 0000000 0000000 # -*- coding: utf-8 -*-
"""
inflection
~~~~~~~~~~~~
A port of Ruby on Rails' inflector to Python.
:copyright: (c) 2012-2015 by Janne Vanhala
:license: MIT, see LICENSE for more details.
"""
import re
import unicodedata
__version__ = '0.3.1'
PLURALS = [
(r"(?i)(quiz)$", r'\1zes'),
(r"(?i)^(oxen)$", r'\1'),
(r"(?i)^(ox)$", r'\1en'),
(r"(?i)(m|l)ice$", r'\1ice'),
(r"(?i)(m|l)ouse$", r'\1ice'),
(r"(?i)(matr|vert|ind)(?:ix|ex)$", r'\1ices'),
(r"(?i)(x|ch|ss|sh)$", r'\1es'),
(r"(?i)([^aeiouy]|qu)y$", r'\1ies'),
(r"(?i)(hive)$", r'\1s'),
(r"(?i)([lr])f$", r'\1ves'),
(r"(?i)([^f])fe$", r'\1ves'),
(r"(?i)sis$", 'ses'),
(r"(?i)([ti])a$", r'\1a'),
(r"(?i)([ti])um$", r'\1a'),
(r"(?i)(buffal|potat|tomat)o$", r'\1oes'),
(r"(?i)(bu)s$", r'\1ses'),
(r"(?i)(alias|status)$", r'\1es'),
(r"(?i)(octop|vir)i$", r'\1i'),
(r"(?i)(octop|vir)us$", r'\1i'),
(r"(?i)^(ax|test)is$", r'\1es'),
(r"(?i)s$", 's'),
(r"$", 's'),
]
SINGULARS = [
(r"(?i)(database)s$", r'\1'),
(r"(?i)(quiz)zes$", r'\1'),
(r"(?i)(matr)ices$", r'\1ix'),
(r"(?i)(vert|ind)ices$", r'\1ex'),
(r"(?i)^(ox)en", r'\1'),
(r"(?i)(alias|status)(es)?$", r'\1'),
(r"(?i)(octop|vir)(us|i)$", r'\1us'),
(r"(?i)^(a)x[ie]s$", r'\1xis'),
(r"(?i)(cris|test)(is|es)$", r'\1is'),
(r"(?i)(shoe)s$", r'\1'),
(r"(?i)(o)es$", r'\1'),
(r"(?i)(bus)(es)?$", r'\1'),
(r"(?i)(m|l)ice$", r'\1ouse'),
(r"(?i)(x|ch|ss|sh)es$", r'\1'),
(r"(?i)(m)ovies$", r'\1ovie'),
(r"(?i)(s)eries$", r'\1eries'),
(r"(?i)([^aeiouy]|qu)ies$", r'\1y'),
(r"(?i)([lr])ves$", r'\1f'),
(r"(?i)(tive)s$", r'\1'),
(r"(?i)(hive)s$", r'\1'),
(r"(?i)([^f])ves$", r'\1fe'),
(r"(?i)(t)he(sis|ses)$", r"\1hesis"),
(r"(?i)(s)ynop(sis|ses)$", r"\1ynopsis"),
(r"(?i)(p)rogno(sis|ses)$", r"\1rognosis"),
(r"(?i)(p)arenthe(sis|ses)$", r"\1arenthesis"),
(r"(?i)(d)iagno(sis|ses)$", r"\1iagnosis"),
(r"(?i)(b)a(sis|ses)$", r"\1asis"),
(r"(?i)(a)naly(sis|ses)$", r"\1nalysis"),
(r"(?i)([ti])a$", r'\1um'),
(r"(?i)(n)ews$", r'\1ews'),
(r"(?i)(ss)$", r'\1'),
(r"(?i)s$", ''),
]
UNCOUNTABLES = set([
'equipment',
'fish',
'information',
'jeans',
'money',
'rice',
'series',
'sheep',
'species',
])
def _irregular(singular, plural):
"""
A convenience function to add appropriate rules to plurals and singular
for irregular words.
:param singular: irregular word in singular form
:param plural: irregular word in plural form
"""
def caseinsensitive(string):
return ''.join('[' + char + char.upper() + ']' for char in string)
if singular[0].upper() == plural[0].upper():
PLURALS.insert(0, (
r"(?i)(%s)%s$" % (singular[0], singular[1:]),
r'\1' + plural[1:]
))
PLURALS.insert(0, (
r"(?i)(%s)%s$" % (plural[0], plural[1:]),
r'\1' + plural[1:]
))
SINGULARS.insert(0, (
r"(?i)(%s)%s$" % (plural[0], plural[1:]),
r'\1' + singular[1:]
))
else:
PLURALS.insert(0, (
r"%s%s$" % (singular[0].upper(), caseinsensitive(singular[1:])),
plural[0].upper() + plural[1:]
))
PLURALS.insert(0, (
r"%s%s$" % (singular[0].lower(), caseinsensitive(singular[1:])),
plural[0].lower() + plural[1:]
))
PLURALS.insert(0, (
r"%s%s$" % (plural[0].upper(), caseinsensitive(plural[1:])),
plural[0].upper() + plural[1:]
))
PLURALS.insert(0, (
r"%s%s$" % (plural[0].lower(), caseinsensitive(plural[1:])),
plural[0].lower() + plural[1:]
))
SINGULARS.insert(0, (
r"%s%s$" % (plural[0].upper(), caseinsensitive(plural[1:])),
singular[0].upper() + singular[1:]
))
SINGULARS.insert(0, (
r"%s%s$" % (plural[0].lower(), caseinsensitive(plural[1:])),
singular[0].lower() + singular[1:]
))
def camelize(string, uppercase_first_letter=True):
"""
Convert strings to CamelCase.
Examples::
>>> camelize("device_type")
"DeviceType"
>>> camelize("device_type", False)
"deviceType"
:func:`camelize` can be though as a inverse of :func:`underscore`, although
there are some cases where that does not hold::
>>> camelize(underscore("IOError"))
"IoError"
:param uppercase_first_letter: if set to `True` :func:`camelize` converts
strings to UpperCamelCase. If set to `False` :func:`camelize` produces
lowerCamelCase. Defaults to `True`.
"""
if uppercase_first_letter:
return re.sub(r"(?:^|_)(.)", lambda m: m.group(1).upper(), string)
else:
return string[0].lower() + camelize(string)[1:]
def dasherize(word):
"""Replace underscores with dashes in the string.
Example::
>>> dasherize("puni_puni")
"puni-puni"
"""
return word.replace('_', '-')
def humanize(word):
"""
Capitalize the first word and turn underscores into spaces and strip a
trailing ``"_id"``, if any. Like :func:`titleize`, this is meant for
creating pretty output.
Examples::
>>> humanize("employee_salary")
"Employee salary"
>>> humanize("author_id")
"Author"
"""
word = re.sub(r"_id$", "", word)
word = word.replace('_', ' ')
word = re.sub(r"(?i)([a-z\d]*)", lambda m: m.group(1).lower(), word)
word = re.sub(r"^\w", lambda m: m.group(0).upper(), word)
return word
def ordinal(number):
"""
Return the suffix that should be added to a number to denote the position
in an ordered sequence such as 1st, 2nd, 3rd, 4th.
Examples::
>>> ordinal(1)
"st"
>>> ordinal(2)
"nd"
>>> ordinal(1002)
"nd"
>>> ordinal(1003)
"rd"
>>> ordinal(-11)
"th"
>>> ordinal(-1021)
"st"
"""
number = abs(int(number))
if number % 100 in (11, 12, 13):
return "th"
else:
return {
1: "st",
2: "nd",
3: "rd",
}.get(number % 10, "th")
def ordinalize(number):
"""
Turn a number into an ordinal string used to denote the position in an
ordered sequence such as 1st, 2nd, 3rd, 4th.
Examples::
>>> ordinalize(1)
"1st"
>>> ordinalize(2)
"2nd"
>>> ordinalize(1002)
"1002nd"
>>> ordinalize(1003)
"1003rd"
>>> ordinalize(-11)
"-11th"
>>> ordinalize(-1021)
"-1021st"
"""
return "%s%s" % (number, ordinal(number))
def parameterize(string, separator='-'):
"""
Replace special characters in a string so that it may be used as part of a
'pretty' URL.
Example::
>>> parameterize(u"Donald E. Knuth")
'donald-e-knuth'
"""
string = transliterate(string)
# Turn unwanted chars into the separator
string = re.sub(r"(?i)[^a-z0-9\-_]+", separator, string)
if separator:
re_sep = re.escape(separator)
# No more than one of the separator in a row.
string = re.sub(r'%s{2,}' % re_sep, separator, string)
# Remove leading/trailing separator.
string = re.sub(r"(?i)^%(sep)s|%(sep)s$" % {'sep': re_sep}, '', string)
return string.lower()
def pluralize(word):
"""
Return the plural form of a word.
Examples::
>>> pluralize("post")
"posts"
>>> pluralize("octopus")
"octopi"
>>> pluralize("sheep")
"sheep"
>>> pluralize("CamelOctopus")
"CamelOctopi"
"""
if not word or word.lower() in UNCOUNTABLES:
return word
else:
for rule, replacement in PLURALS:
if re.search(rule, word):
return re.sub(rule, replacement, word)
return word
def singularize(word):
"""
Return the singular form of a word, the reverse of :func:`pluralize`.
Examples::
>>> singularize("posts")
"post"
>>> singularize("octopi")
"octopus"
>>> singularize("sheep")
"sheep"
>>> singularize("word")
"word"
>>> singularize("CamelOctopi")
"CamelOctopus"
"""
for inflection in UNCOUNTABLES:
if re.search(r'(?i)\b(%s)\Z' % inflection, word):
return word
for rule, replacement in SINGULARS:
if re.search(rule, word):
return re.sub(rule, replacement, word)
return word
def tableize(word):
"""
Create the name of a table like Rails does for models to table names. This
method uses the :func:`pluralize` method on the last word in the string.
Examples::
>>> tableize('RawScaledScorer')
"raw_scaled_scorers"
>>> tableize('egg_and_ham')
"egg_and_hams"
>>> tableize('fancyCategory')
"fancy_categories"
"""
return pluralize(underscore(word))
def titleize(word):
"""
Capitalize all the words and replace some characters in the string to
create a nicer looking title. :func:`titleize` is meant for creating pretty
output.
Examples::
>>> titleize("man from the boondocks")
"Man From The Boondocks"
>>> titleize("x-men: the last stand")
"X Men: The Last Stand"
>>> titleize("TheManWithoutAPast")
"The Man Without A Past"
>>> titleize("raiders_of_the_lost_ark")
"Raiders Of The Lost Ark"
"""
return re.sub(
r"\b('?[a-z])",
lambda match: match.group(1).capitalize(),
humanize(underscore(word))
)
def transliterate(string):
"""
Replace non-ASCII characters with an ASCII approximation. If no
approximation exists, the non-ASCII character is ignored. The string must
be ``unicode``.
Examples::
>>> transliterate(u'älämölö')
u'alamolo'
>>> transliterate(u'Ærøskøbing')
u'rskbing'
"""
normalized = unicodedata.normalize('NFKD', string)
return normalized.encode('ascii', 'ignore').decode('ascii')
def underscore(word):
"""
Make an underscored, lowercase form from the expression in the string.
Example::
>>> underscore("DeviceType")
"device_type"
As a rule of thumb you can think of :func:`underscore` as the inverse of
:func:`camelize`, though there are cases where that does not hold::
>>> camelize(underscore("IOError"))
"IoError"
"""
word = re.sub(r"([A-Z]+)([A-Z][a-z])", r'\1_\2', word)
word = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', word)
word = word.replace("-", "_")
return word.lower()
_irregular('person', 'people')
_irregular('man', 'men')
_irregular('human', 'humans')
_irregular('child', 'children')
_irregular('sex', 'sexes')
_irregular('move', 'moves')
_irregular('cow', 'kine')
_irregular('zombie', 'zombies')
inflection-0.3.1/LICENSE 0000644 0000765 0000024 00000002046 12474646136 015107 0 ustar janne staff 0000000 0000000 Copyright (C) 2012-2015 Janne Vanhala
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
inflection-0.3.1/MANIFEST.in 0000644 0000765 0000024 00000000073 12157076431 015627 0 ustar janne staff 0000000 0000000 include README.rst LICENSE CHANGES.rst test_inflection.py
inflection-0.3.1/PKG-INFO 0000644 0000765 0000024 00000006067 12521353554 015176 0 ustar janne staff 0000000 0000000 Metadata-Version: 1.1
Name: inflection
Version: 0.3.1
Summary: A port of Ruby on Rails inflector to Python
Home-page: http://github.com/jpvanhal/inflection
Author: Janne Vanhala
Author-email: janne.vanhala@gmail.com
License: MIT
Description: Inflection
==========
|build status|_
.. |build status| image:: https://secure.travis-ci.org/jpvanhal/inflection.png?branch=master
:alt: Build Status
.. _build status: http://travis-ci.org/jpvanhal/inflection
Inflection is a string transformation library. It singularizes and pluralizes
English words, and transforms strings from CamelCase to underscored string.
Inflection is a port of `Ruby on Rails`_' `inflector`_ to Python.
.. _Ruby on Rails: http://rubyonrails.org
.. _inflector: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
Resources
---------
- `Documentation `_
- `Issue Tracker `_
- `Code `_
- `Development Version
`_
Changelog
---------
Here you can see the full list of changes between each Inflection release.
0.3.1 (May 3, 2015)
^^^^^^^^^^^^^^^^^^^
- Fixed trove classifiers not showing up on PyPI.
- Fixed "human" pluralized as "humen" and not "humans".
- Fixed "potato" pluralized as "potatos" and not "potatoes".
0.3.0 (March 1, 2015)
+++++++++++++++++++++
- Added `tableize()` function.
0.2.1 (September 3, 2014)
+++++++++++++++++++++++++
- Added Python 2, Python 3 and Python 3.4 trove classifiers.
0.2.0 (June 15, 2013)
+++++++++++++++++++++
- Added initial support for Python 3.
- Dropped Python 2.5 support.
0.1.2 (March 13, 2012)
++++++++++++++++++++++
- Added Python 2.5 support.
0.1.1 (February 24, 2012)
+++++++++++++++++++++++++
- Fixed some files not included in the distribution package.
0.1.0 (February 24, 2012)
+++++++++++++++++++++++++
- Initial public release
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: Implementation :: PyPy
inflection-0.3.1/README.rst 0000644 0000765 0000024 00000001525 12157076431 015563 0 ustar janne staff 0000000 0000000 Inflection
==========
|build status|_
.. |build status| image:: https://secure.travis-ci.org/jpvanhal/inflection.png?branch=master
:alt: Build Status
.. _build status: http://travis-ci.org/jpvanhal/inflection
Inflection is a string transformation library. It singularizes and pluralizes
English words, and transforms strings from CamelCase to underscored string.
Inflection is a port of `Ruby on Rails`_' `inflector`_ to Python.
.. _Ruby on Rails: http://rubyonrails.org
.. _inflector: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
Resources
---------
- `Documentation `_
- `Issue Tracker `_
- `Code `_
- `Development Version
`_
inflection-0.3.1/setup.cfg 0000644 0000765 0000024 00000000160 12521353554 015706 0 ustar janne staff 0000000 0000000 [flake8]
exclude = docs/*
[isort]
skip = .tox,docs
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
inflection-0.3.1/setup.py 0000644 0000765 0000024 00000002147 12521352410 015574 0 ustar janne staff 0000000 0000000 #!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup
import inflection
setup(
name='inflection',
version=inflection.__version__,
description="A port of Ruby on Rails inflector to Python",
long_description=(
open('README.rst').read() + '\n\n' +
open('CHANGES.rst').read()
),
author='Janne Vanhala',
author_email='janne.vanhala@gmail.com',
url='http://github.com/jpvanhal/inflection',
license='MIT',
py_modules=['inflection'],
zip_safe=False,
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: PyPy',
],
)
inflection-0.3.1/test_inflection.py 0000644 0000765 0000024 00000027221 12521352501 017626 0 ustar janne staff 0000000 0000000 # -*- coding: utf-8 -*-
import pytest
import inflection
SINGULAR_TO_PLURAL = (
("search", "searches"),
("switch", "switches"),
("fix", "fixes"),
("box", "boxes"),
("process", "processes"),
("address", "addresses"),
("case", "cases"),
("stack", "stacks"),
("wish", "wishes"),
("fish", "fish"),
("jeans", "jeans"),
("funky jeans", "funky jeans"),
("category", "categories"),
("query", "queries"),
("ability", "abilities"),
("agency", "agencies"),
("movie", "movies"),
("archive", "archives"),
("index", "indices"),
("wife", "wives"),
("safe", "saves"),
("half", "halves"),
("move", "moves"),
("salesperson", "salespeople"),
("person", "people"),
("spokesman", "spokesmen"),
("man", "men"),
("woman", "women"),
("basis", "bases"),
("diagnosis", "diagnoses"),
("diagnosis_a", "diagnosis_as"),
("datum", "data"),
("medium", "media"),
("stadium", "stadia"),
("analysis", "analyses"),
("node_child", "node_children"),
("child", "children"),
("experience", "experiences"),
("day", "days"),
("comment", "comments"),
("foobar", "foobars"),
("newsletter", "newsletters"),
("old_news", "old_news"),
("news", "news"),
("series", "series"),
("species", "species"),
("quiz", "quizzes"),
("perspective", "perspectives"),
("ox", "oxen"),
("photo", "photos"),
("buffalo", "buffaloes"),
("tomato", "tomatoes"),
("potato", "potatoes"),
("dwarf", "dwarves"),
("elf", "elves"),
("information", "information"),
("equipment", "equipment"),
("bus", "buses"),
("status", "statuses"),
("status_code", "status_codes"),
("mouse", "mice"),
("louse", "lice"),
("house", "houses"),
("octopus", "octopi"),
("virus", "viri"),
("alias", "aliases"),
("portfolio", "portfolios"),
("vertex", "vertices"),
("matrix", "matrices"),
("matrix_fu", "matrix_fus"),
("axis", "axes"),
("testis", "testes"),
("crisis", "crises"),
("rice", "rice"),
("shoe", "shoes"),
("horse", "horses"),
("prize", "prizes"),
("edge", "edges"),
("cow", "kine"),
("database", "databases"),
("human", "humans")
)
CAMEL_TO_UNDERSCORE = (
("Product", "product"),
("SpecialGuest", "special_guest"),
("ApplicationController", "application_controller"),
("Area51Controller", "area51_controller"),
)
CAMEL_TO_UNDERSCORE_WITHOUT_REVERSE = (
("HTMLTidy", "html_tidy"),
("HTMLTidyGenerator", "html_tidy_generator"),
("FreeBSD", "free_bsd"),
("HTML", "html"),
)
STRING_TO_PARAMETERIZED = (
(u"Donald E. Knuth", "donald-e-knuth"),
(
u"Random text with *(bad)* characters",
"random-text-with-bad-characters"
),
(u"Allow_Under_Scores", "allow_under_scores"),
(u"Trailing bad characters!@#", "trailing-bad-characters"),
(u"!@#Leading bad characters", "leading-bad-characters"),
(u"Squeeze separators", "squeeze-separators"),
(u"Test with + sign", "test-with-sign"),
(u"Test with malformed utf8 \251", "test-with-malformed-utf8"),
)
STRING_TO_PARAMETERIZE_WITH_NO_SEPARATOR = (
(u"Donald E. Knuth", "donaldeknuth"),
(u"With-some-dashes", "with-some-dashes"),
(u"Random text with *(bad)* characters", "randomtextwithbadcharacters"),
(u"Trailing bad characters!@#", "trailingbadcharacters"),
(u"!@#Leading bad characters", "leadingbadcharacters"),
(u"Squeeze separators", "squeezeseparators"),
(u"Test with + sign", "testwithsign"),
(u"Test with malformed utf8 \251", "testwithmalformedutf8"),
)
STRING_TO_PARAMETERIZE_WITH_UNDERSCORE = (
(u"Donald E. Knuth", "donald_e_knuth"),
(
u"Random text with *(bad)* characters",
"random_text_with_bad_characters"
),
(u"With-some-dashes", "with-some-dashes"),
(u"Retain_underscore", "retain_underscore"),
(u"Trailing bad characters!@#", "trailing_bad_characters"),
(u"!@#Leading bad characters", "leading_bad_characters"),
(u"Squeeze separators", "squeeze_separators"),
(u"Test with + sign", "test_with_sign"),
(u"Test with malformed utf8 \251", "test_with_malformed_utf8"),
)
STRING_TO_PARAMETERIZED_AND_NORMALIZED = (
(u"Malmö", "malmo"),
(u"Garçons", "garcons"),
(u"Ops\331", "opsu"),
(u"Ærøskøbing", "rskbing"),
(u"Aßlar", "alar"),
(u"Japanese: 日本語", "japanese"),
)
UNDERSCORE_TO_HUMAN = (
("employee_salary", "Employee salary"),
("employee_id", "Employee"),
("underground", "Underground"),
)
MIXTURE_TO_TITLEIZED = (
('active_record', 'Active Record'),
('ActiveRecord', 'Active Record'),
('action web service', 'Action Web Service'),
('Action Web Service', 'Action Web Service'),
('Action web service', 'Action Web Service'),
('actionwebservice', 'Actionwebservice'),
('Actionwebservice', 'Actionwebservice'),
("david's code", "David's Code"),
("David's code", "David's Code"),
("david's Code", "David's Code"),
)
ORDINAL_NUMBERS = (
("-1", "-1st"),
("-2", "-2nd"),
("-3", "-3rd"),
("-4", "-4th"),
("-5", "-5th"),
("-6", "-6th"),
("-7", "-7th"),
("-8", "-8th"),
("-9", "-9th"),
("-10", "-10th"),
("-11", "-11th"),
("-12", "-12th"),
("-13", "-13th"),
("-14", "-14th"),
("-20", "-20th"),
("-21", "-21st"),
("-22", "-22nd"),
("-23", "-23rd"),
("-24", "-24th"),
("-100", "-100th"),
("-101", "-101st"),
("-102", "-102nd"),
("-103", "-103rd"),
("-104", "-104th"),
("-110", "-110th"),
("-111", "-111th"),
("-112", "-112th"),
("-113", "-113th"),
("-1000", "-1000th"),
("-1001", "-1001st"),
("0", "0th"),
("1", "1st"),
("2", "2nd"),
("3", "3rd"),
("4", "4th"),
("5", "5th"),
("6", "6th"),
("7", "7th"),
("8", "8th"),
("9", "9th"),
("10", "10th"),
("11", "11th"),
("12", "12th"),
("13", "13th"),
("14", "14th"),
("20", "20th"),
("21", "21st"),
("22", "22nd"),
("23", "23rd"),
("24", "24th"),
("100", "100th"),
("101", "101st"),
("102", "102nd"),
("103", "103rd"),
("104", "104th"),
("110", "110th"),
("111", "111th"),
("112", "112th"),
("113", "113th"),
("1000", "1000th"),
("1001", "1001st"),
)
UNDERSCORES_TO_DASHES = (
("street", "street"),
("street_address", "street-address"),
("person_street_address", "person-street-address"),
)
STRING_TO_TABLEIZE = (
("person", "people"),
("Country", "countries"),
("ChildToy", "child_toys"),
("_RecipeIngredient", "_recipe_ingredients"),
)
def test_pluralize_plurals():
assert "plurals" == inflection.pluralize("plurals")
assert "Plurals" == inflection.pluralize("Plurals")
def test_pluralize_empty_string():
assert "" == inflection.pluralize("")
@pytest.mark.parametrize(
("word", ),
[(word,) for word in inflection.UNCOUNTABLES]
)
def test_uncountability(word):
assert word == inflection.singularize(word)
assert word == inflection.pluralize(word)
assert inflection.pluralize(word) == inflection.singularize(word)
def test_uncountable_word_is_not_greedy():
uncountable_word = "ors"
countable_word = "sponsor"
inflection.UNCOUNTABLES.add(uncountable_word)
try:
assert uncountable_word == inflection.singularize(uncountable_word)
assert uncountable_word == inflection.pluralize(uncountable_word)
assert(
inflection.pluralize(uncountable_word) ==
inflection.singularize(uncountable_word)
)
assert "sponsor" == inflection.singularize(countable_word)
assert "sponsors" == inflection.pluralize(countable_word)
assert (
"sponsor" ==
inflection.singularize(inflection.pluralize(countable_word))
)
finally:
inflection.UNCOUNTABLES.remove(uncountable_word)
@pytest.mark.parametrize(("singular", "plural"), SINGULAR_TO_PLURAL)
def test_pluralize_singular(singular, plural):
assert plural == inflection.pluralize(singular)
assert plural.capitalize() == inflection.pluralize(singular.capitalize())
@pytest.mark.parametrize(("singular", "plural"), SINGULAR_TO_PLURAL)
def test_singularize_plural(singular, plural):
assert singular == inflection.singularize(plural)
assert singular.capitalize() == inflection.singularize(plural.capitalize())
@pytest.mark.parametrize(("singular", "plural"), SINGULAR_TO_PLURAL)
def test_pluralize_plural(singular, plural):
assert plural == inflection.pluralize(plural)
assert plural.capitalize() == inflection.pluralize(plural.capitalize())
@pytest.mark.parametrize(("before", "titleized"), MIXTURE_TO_TITLEIZED)
def test_titleize(before, titleized):
assert titleized == inflection.titleize(before)
@pytest.mark.parametrize(("camel", "underscore"), CAMEL_TO_UNDERSCORE)
def test_camelize(camel, underscore):
assert camel == inflection.camelize(underscore)
def test_camelize_with_lower_downcases_the_first_letter():
assert 'capital' == inflection.camelize('Capital', False)
def test_camelize_with_underscores():
assert "CamelCase" == inflection.camelize('Camel_Case')
@pytest.mark.parametrize(
("camel", "underscore"),
CAMEL_TO_UNDERSCORE + CAMEL_TO_UNDERSCORE_WITHOUT_REVERSE
)
def test_underscore(camel, underscore):
assert underscore == inflection.underscore(camel)
@pytest.mark.parametrize(
("some_string", "parameterized_string"),
STRING_TO_PARAMETERIZED
)
def test_parameterize(some_string, parameterized_string):
assert parameterized_string == inflection.parameterize(some_string)
@pytest.mark.parametrize(
("some_string", "parameterized_string"),
STRING_TO_PARAMETERIZED_AND_NORMALIZED
)
def test_parameterize_and_normalize(some_string, parameterized_string):
assert parameterized_string == inflection.parameterize(some_string)
@pytest.mark.parametrize(
("some_string", "parameterized_string"),
STRING_TO_PARAMETERIZE_WITH_UNDERSCORE
)
def test_parameterize_with_custom_separator(some_string, parameterized_string):
assert parameterized_string == inflection.parameterize(some_string, '_')
@pytest.mark.parametrize(
("some_string", "parameterized_string"),
STRING_TO_PARAMETERIZED
)
def test_parameterize_with_multi_character_separator(
some_string,
parameterized_string
):
assert (
parameterized_string.replace('-', '__sep__') ==
inflection.parameterize(some_string, '__sep__')
)
@pytest.mark.parametrize(
("some_string", "parameterized_string"),
STRING_TO_PARAMETERIZE_WITH_NO_SEPARATOR
)
def test_parameterize_with_no_separator(some_string, parameterized_string):
assert parameterized_string == inflection.parameterize(some_string, '')
@pytest.mark.parametrize(("underscore", "human"), UNDERSCORE_TO_HUMAN)
def test_humanize(underscore, human):
assert human == inflection.humanize(underscore)
@pytest.mark.parametrize(("number", "ordinalized"), ORDINAL_NUMBERS)
def test_ordinal(number, ordinalized):
assert ordinalized == number + inflection.ordinal(number)
@pytest.mark.parametrize(("number", "ordinalized"), ORDINAL_NUMBERS)
def test_ordinalize(number, ordinalized):
assert ordinalized == inflection.ordinalize(number)
@pytest.mark.parametrize(("input", "expected"), UNDERSCORES_TO_DASHES)
def test_dasherize(input, expected):
assert inflection.dasherize(input) == expected
@pytest.mark.parametrize(("string", "tableized"), STRING_TO_TABLEIZE)
def test_tableize(string, tableized):
assert inflection.tableize(string) == tableized