Esempio n. 1
0
def test_word_parse():
    """test function to parse keys to user from rax text file
    """
    keys, stripped = madlib.parse(
        "This is an {adjective} and also {adjective} {noun} of a test.")
    assert keys == ['adjective', 'adjective', 'noun']
    assert stripped == 'This is an {} and also {} {} of a test.'
def test_parse():

    prompts, stripped = madlib.parse(
        'It was a {Adjective} and {Adjective} {Noun}')

    assert prompts == ['Adjective', 'Adjective', 'Noun']

    assert stripped == 'It was a {} and {} {}'
Esempio n. 3
0
 def testAlternateLeftOpen(self):
     """TODO: this should fail to parse"""
     seq = madlib.parse("x{y|")
     chooser = lambda p: p[-1]
     self.assertEquals(madlib.expand(seq, chooser=chooser), "xy")
Esempio n. 4
0
 def testAlternateMarkerOutsideOfAlternate(self):
     seq = madlib.parse("foo|bar")
     self.assertEquals(madlib.expand(seq), "foo|bar")
Esempio n. 5
0
 def testCrazyScenario2(self):
     seq = madlib.parse("{{a|{|{x|}b}}foo")
     chooser = lambda p: p[-1]
     self.assertEquals(madlib.expand(seq, chooser=chooser), "bfoo")
Esempio n. 6
0
 def testEmptyString(self):
     seq = madlib.parse("")
     self.assertEquals(madlib.expand(seq), "")
Esempio n. 7
0
 def testNestedAlternates(self):
     seq = madlib.parse("a{x{y|y}z{q}")
     self.assertEquals(madlib.expand(seq), "axyzq")
Esempio n. 8
0
 def testCrazyScenario1(self):
     seq = madlib.parse("{{a|b}|{|grot}}foo")
     chooser = lambda p: p[0]
     self.assertEquals(madlib.expand(seq, chooser=chooser), "afoo")
Esempio n. 9
0
 def testAlternate(self):
     seq = madlib.parse("a{x|x}b")
     self.assertEquals(madlib.expand(seq), "axb")
Esempio n. 10
0
 def testNestedSimpleAlternate(self):
     seq = madlib.parse("a{x{y}z}b")
     self.assertEquals(madlib.expand(seq), "axyzb")
Esempio n. 11
0
 def testAlternateOfEmpty(self):
     seq = madlib.parse("foo{|}bar")
     self.assertEquals(madlib.expand(seq), "foobar")
Esempio n. 12
0
import re
import os
from madlib import read_template, parse, newWords, merge

fillPattern = re.compile(r'{.*?}')
dirname = os.path.dirname(__file__)
writeFile = os.path.join(dirname, '../assets/madlib_complete.txt')
readFile = os.path.join(dirname, '../assets/madlib_template.txt')

print('Greetings! Let\'s have some fun with MadLibs. I will ask you for some words by grammatical family and then place them into a prebuilt story to find some funny results.')

template = read_template(readFile)
fillIns = parse(template)
userInput = newWords(fillIns)
finished = open(writeFile, 'wt')
finished.write(merge(template, userInput))
finished.close()
print(template)
Esempio n. 13
0
 def testSimpleStringWithEmptyAlternate(self):
     seq = madlib.parse("ab{}cd")
     self.assertEquals(madlib.expand(seq), "abcd")
Esempio n. 14
0
 def testSimpleAlternate(self):
     seq = madlib.parse("{x}")
     self.assertEquals(madlib.expand(seq), "x")
Esempio n. 15
0
 def testEmptyAlternative(self):
     seq = madlib.parse("{}")
     self.assertEquals(madlib.expand(seq), "")
Esempio n. 16
0
 def testSimpleString(self):
     seq = madlib.parse("hello")
     self.assertEquals(madlib.expand(seq), "hello")
Esempio n. 17
0
def test_parse():
    """Test whether parse works with simple input."""
    prompts, stripped = madlib.parse(
        'It was a {Adjective} and {Adjective} {Noun}')
    assert prompts == ['Adjective', 'Adjective', 'Noun']
    assert stripped == 'It was a {} and {} {}'