mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 00:12:08 +08:00
Add missing test; refactor last bit
This commit is contained in:
@@ -83,17 +83,11 @@ class Inflector(object):
|
||||
|
||||
def pluralize(self, word):
|
||||
'''Pluralizes nouns.'''
|
||||
return self._handle_nonchanging(word) or \
|
||||
self._handle_irregular(word) or \
|
||||
self._apply_rule(self.PLURALIZE_RULES, word) or \
|
||||
word
|
||||
return self._transform(self.PLURALIZE_RULES, word)
|
||||
|
||||
def singularize(self, word):
|
||||
'''Singularizes nouns.'''
|
||||
return self._handle_nonchanging(word) or \
|
||||
self._handle_irregular(word, pluralize=False) or \
|
||||
self._apply_rule(self.SINGULARIZE_RULES, word) or \
|
||||
word
|
||||
return self._transform(self.SINGULARIZE_RULES, word, pluralize=False)
|
||||
|
||||
def cond_plural(self, number_of_records, word):
|
||||
'''Returns the plural form of a word if first parameter is greater than 1'''
|
||||
@@ -101,6 +95,9 @@ class Inflector(object):
|
||||
return self.pluralize(word)
|
||||
return word
|
||||
|
||||
def _transform(self, rules, word, pluralize=True):
|
||||
return self._handle_nonchanging(word) or self._handle_irregular(word, pluralize=pluralize) or self._apply_rule(rules, word) or word
|
||||
|
||||
def _handle_nonchanging(self, word):
|
||||
if word.lower() in self.NONCHANGING_WORDS:
|
||||
return word
|
||||
|
||||
@@ -86,3 +86,10 @@ def test_pluralize_rules(test_data, inflector):
|
||||
@pytest.mark.parametrize('test_data', SINGULAR_TO_PLURAL.items())
|
||||
def test_singularize_rules(test_data, inflector):
|
||||
assert test_data[0] == inflector.singularize(test_data[1])
|
||||
|
||||
|
||||
def test_cond_plural(inflector):
|
||||
assert 'edge' == inflector.cond_plural(1, 'edge')
|
||||
assert 'edges' == inflector.cond_plural(-1, 'edge')
|
||||
assert 'edges' == inflector.cond_plural(0, 'edge')
|
||||
assert 'edges' == inflector.cond_plural(2, 'edge')
|
||||
|
||||
Reference in New Issue
Block a user