Skip to content

Commit

Permalink
Fix python3 compatibility code in chain.from_json(); add test for it …
Browse files Browse the repository at this point in the history
…in test_basic.py
  • Loading branch information
erichalldev committed Dec 18, 2016
1 parent 7d888c3 commit 9619238
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions markovify/chain.py
Expand Up @@ -3,6 +3,12 @@
import bisect
import json

# Python3 compatibility
try:
basestring
except NameError:
basestring = str

BEGIN = "___BEGIN__"
END = "___END__"

Expand Down Expand Up @@ -125,11 +131,6 @@ def from_json(cls, json_thing):
Given a JSON object or JSON string that was created by `self.to_json`,
return the corresponding markovify.Chain.
"""
# Python3 compatibility
try:
basestring
except NameError:
basestring = str

if isinstance(json_thing, basestring):
obj = json.loads(json_thing)
Expand Down
3 changes: 2 additions & 1 deletion test/test_basic.py
Expand Up @@ -24,7 +24,8 @@ def test_sherlock(self):

def test_json(self):
text_model = markovify.Text(self.sherlock)

json_model = text_model.to_json()
new_text_model = markovify.Text.from_json(json_model)
sent = text_model.make_sentence()
assert(len(sent) != 0)

Expand Down

0 comments on commit 9619238

Please sign in to comment.