Skip to content

Commit

Permalink
Test small image fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter92 authored Oct 20, 2017
1 parent 7fb1325 commit a0098c4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions test/test_wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ def test_unicode_stopwords():

assert_true(words_unicode == words_str)


def test_recolor_too_small():
# check exception is raised when image is too small
def _test():
colouring = np.array(Image.new('RGB', size=(20, 20)))
wc = WordCloud(width=30, height=30).generate(THIS)
image_colors = ImageColorGenerator(colouring)
wc.recolor(color_func=image_colors)
assert_raises_regex(ValueError, 'ImageColorGenerator is smaller than the canvas', _test)
colouring = np.array(Image.new('RGB', size=(20, 20)))
wc = WordCloud(width=30, height=30).generate(THIS)
image_colors = ImageColorGenerator(colouring)
assert_raises_regex(ValueError, 'ImageColorGenerator is smaller than the canvas',
wc.recolor, color_func=image_colors)


def test_recolor_too_small_set_default():
Expand All @@ -287,3 +287,15 @@ def test_recolor_too_small_set_default():
wc = WordCloud(max_words=50, width=30, height=30).generate(THIS)
image_colors = ImageColorGenerator(colouring, default_color=(0, 0, 0))
wc.recolor(color_func=image_colors)


def test_small_canvas():
# check font size fallback works on small canvas
WordCloud(max_words=50, width=20, height=20).generate(THIS)


def test_tiny_canvas():
# check exception if canvas too small for fallback
w = WordCloud(max_words=50, width=1, height=1)
assert_raises_regex(ValueError, 'canvas size is too small',
w.generate, THIS)

0 comments on commit a0098c4

Please sign in to comment.