Skip to content

Commit

Permalink
Add cation support
Browse files Browse the repository at this point in the history
  • Loading branch information
funtion committed Feb 3, 2017
1 parent c1656a3 commit 4951eb4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
5 changes: 2 additions & 3 deletions praise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import string
from .words import get_one_word_dict
from .words import Words


def praise(template="You are ${adjective}!"):
if template == None:
template = "None"
template = string.Template(template)
words = get_one_word_dict()
result = template.substitute(words)
result = template.substitute(Words())
return result
10 changes: 10 additions & 0 deletions praise/tests/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def caption_check(word, word_list):
if not word.isalpha():
return True
return word.isupper() and word.lower() in word_list


def first_letter_caption_check(word, word_list):
if not word.isalpha():
return True
return word[0].isupper and word[1:].islower() and word.lower() in word_list
19 changes: 18 additions & 1 deletion praise/tests/test_praise.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest import TestCase

from .helper import *
import praise


Expand All @@ -9,6 +9,7 @@ def test_corner_case(self):
self.assertEqual("", praise.praise(""))
self.assertEqual("None", praise.praise(None))
self.assertEqual("foo", praise.praise("foo"))
self.assertEqual("${foo}", praise.praise("${foo}"))

def test_word(self):
self.assertTrue(
Expand All @@ -31,3 +32,19 @@ def test_milti_words(self):
self.assertTrue(result[3] in praise.smiley.smiley)
self.assertTrue(result[4] in praise.verb.created)
self.assertTrue(result[5] in praise.verb.creating)

def test_caption_words(self):
self.assertTrue(caption_check(praise.praise("${ADJECTIVE}"), praise.adjective.adjective))
self.assertTrue(caption_check(praise.praise("${ADVERB}"), praise.adverb.adverb))
self.assertTrue(caption_check(praise.praise("${EXCLAMATION}"), praise.exclamation.exclamation))
self.assertTrue(caption_check(praise.praise("${SMILEY}"), praise.smiley.smiley))
self.assertTrue(caption_check(praise.praise("${CREATED}"), praise.verb.created))
self.assertTrue(caption_check(praise.praise("${CREATING}"), praise.verb.creating))

def test_first_caption_words(self):
self.assertTrue(first_letter_caption_check(praise.praise("${Adjective}"), praise.adjective.adjective))
self.assertTrue(first_letter_caption_check(praise.praise("${Adverb}"), praise.adverb.adverb))
self.assertTrue(first_letter_caption_check(praise.praise("${Exclamation}"), praise.exclamation.exclamation))
self.assertTrue(first_letter_caption_check(praise.praise("${Smiley}"), praise.smiley.smiley))
self.assertTrue(first_letter_caption_check(praise.praise("${Created}"), praise.verb.created))
self.assertTrue(first_letter_caption_check(praise.praise("${Creating}"), praise.verb.creating))
30 changes: 21 additions & 9 deletions praise/words.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@
from .verb import created, creating


def get_one_word_dict():
return {
'adjective': random.choice(adjective),
'adverb': random.choice(adverb),
'exclamation': random.choice(exclamation),
'smiley': random.choice(smiley),
'created': random.choice(created),
'creating': random.choice(creating)
}
class Words(dict):

def __getitem__(self, key):
word_dict = {
'adjective': random.choice(adjective),
'adverb': random.choice(adverb),
'exclamation': random.choice(exclamation),
'smiley': random.choice(smiley),
'created': random.choice(created),
'creating': random.choice(creating)
}
if key.lower() in word_dict.keys():
result = word_dict[key.lower()]
else:
result = "${%s}" % key

if key.isupper():
result = result.upper()
elif key[0].isupper() and key[1:].islower():
result = result[0].upper() + result[1:]
return result

0 comments on commit 4951eb4

Please sign in to comment.