Loading fixtures/quote_db.json +3 −3 Original line number Diff line number Diff line { "intros": ["Hello darkness, my old friend"], "bodies": [], "closings": [] "intros": ["Hello darkness, my old friend."], "bodies": ["I've come to talk with you again."], "closings": ["Because a vision softly creeping"] } quote_gen/quote_db.py +8 −0 Original line number Diff line number Diff line import json import random def new(path): Loading @@ -12,3 +13,10 @@ class QuoteDB(object): self.intros = intros self.bodies = bodies self.closings = closings def random_quote(self): return "\n".join([ random.choice(self.intros), random.choice(self.bodies), random.choice(self.closings) ]) tests/test_quote_database.py +5 −1 Original line number Diff line number Diff line Loading @@ -7,4 +7,8 @@ class TestDatabase(unittest.TestCase): self.db = quote_db.new("fixtures/quote_db.json") def test_quote_database(self): self.assertEqual(self.db.intros[0], "Hello darkness, my old friend") self.assertEqual(self.db.intros[0], "Hello darkness, my old friend.") def test_assemble_quote(self): quote = self.db.random_quote() self.assertEqual(quote, "Hello darkness, my old friend.\nI've come to talk with you again.\nBecause a vision softly creeping") Loading
fixtures/quote_db.json +3 −3 Original line number Diff line number Diff line { "intros": ["Hello darkness, my old friend"], "bodies": [], "closings": [] "intros": ["Hello darkness, my old friend."], "bodies": ["I've come to talk with you again."], "closings": ["Because a vision softly creeping"] }
quote_gen/quote_db.py +8 −0 Original line number Diff line number Diff line import json import random def new(path): Loading @@ -12,3 +13,10 @@ class QuoteDB(object): self.intros = intros self.bodies = bodies self.closings = closings def random_quote(self): return "\n".join([ random.choice(self.intros), random.choice(self.bodies), random.choice(self.closings) ])
tests/test_quote_database.py +5 −1 Original line number Diff line number Diff line Loading @@ -7,4 +7,8 @@ class TestDatabase(unittest.TestCase): self.db = quote_db.new("fixtures/quote_db.json") def test_quote_database(self): self.assertEqual(self.db.intros[0], "Hello darkness, my old friend") self.assertEqual(self.db.intros[0], "Hello darkness, my old friend.") def test_assemble_quote(self): quote = self.db.random_quote() self.assertEqual(quote, "Hello darkness, my old friend.\nI've come to talk with you again.\nBecause a vision softly creeping")