Skip to content

Commit

Permalink
Fixed python3 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeython committed Sep 15, 2014
1 parent 28de7e9 commit d2ee34b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 6 additions & 3 deletions loremipsum/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
sentences, or just random words.
"""

from __future__ import unicode_literals
from random import normalvariate, choice
from pkg_resources import resource_string
import math
import re
import sys


if sys.version_info[0] == 3:
from functools import partial
unicode = partial(str, encoding='utf-8')
unicode = str


# Delimiters that mark ends of sentences
_SENTENCE_DELIMITERS = ['.', '?', '!']
Expand All @@ -22,7 +25,7 @@
_SAMPLE = resource_string(__name__, 'default/sample.txt')
_DICTIONARY = resource_string(__name__, 'default/dictionary.txt').split()

_LOREM_IPSUM = "lorem ipsum dolor sit amet, consecteteur adipiscing elit"
_LOREM_IPSUM = 'lorem ipsum dolor sit amet, consecteteur adipiscing elit'


def _paragraphs(text):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import loremipsum
import unittest
import sys
# if sys.version_info[:2] == (3,2):
# unicode = str

if sys.version_info[0] == 3:
unicode = str


class TestLoremIpsum(unittest.TestCase):

def _test_text(self, text, start_with_lorem=False):
# self.assertTrue(isinstance(text, unicode))
self.assertTrue(isinstance(text, unicode))
self.assertEqual(text.startswith('Lorem ipsum'), start_with_lorem)

def _test_get_function(self, function):
Expand Down
9 changes: 6 additions & 3 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import with_statement
import loremipsum
import unittest
from types import GeneratorType
from contextlib import contextmanager
import sys

if sys.version_info[0] == 3:
unicode = str


@contextmanager
Expand All @@ -24,7 +27,7 @@ def test_sample(self):
with _assertRaises(self, loremipsum.SampleError):
self.generator.sample = ''
sample = self.generator.sample
# self.assertTrue(isinstance(sample, str))
self.assertTrue(isinstance(sample, unicode))

def test_dictionary(self):
with _assertRaises(self, loremipsum.DictionaryError):
Expand Down Expand Up @@ -55,7 +58,7 @@ def _test_generated(self, generated, start_with_lorem=False):
sentences, words, text = generated
self.assertTrue(isinstance(sentences, int))
self.assertTrue(isinstance(words, int))
# self.assertTrue(isinstance(text, str))
self.assertTrue(isinstance(text, unicode))
self.assertEqual(text.startswith('Lorem ipsum'), start_with_lorem)

def _test_generators(self, method, start_with_lorem=False):
Expand Down

0 comments on commit d2ee34b

Please sign in to comment.