diff --git a/markovify/chain.py b/markovify/chain.py index 62a9a02..b986954 100644 --- a/markovify/chain.py +++ b/markovify/chain.py @@ -3,6 +3,12 @@ import bisect import json +# Python3 compatibility +try: + basestring +except NameError: + basestring = str + BEGIN = "___BEGIN__" END = "___END__" @@ -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) diff --git a/test/test_basic.py b/test/test_basic.py index c142974..c621551 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -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)