Commit 520f0fd8 authored by Raphael Boidol's avatar Raphael Boidol

adapt tests for cli to run with travis

parent cc36d8b5
......@@ -37,7 +37,7 @@ elif [[ "$DISTRIB" == "ubuntu" ]]; then
# Use standard ubuntu packages in their default version
virtualenv --system-site-packages testvenv
source testvenv/bin/activate
pip install nose
pip install nose mock
pip install -r requirements.txt
import argparse
import inspect
import wordcloud_cli
from wordcloud import wordcloud_cli as cli
import wordcloud as wc
import sys
from collections import namedtuple
from mock import patch, MagicMock
from import assert_equal, assert_true, assert_in
......@@ -50,10 +49,10 @@ def test_main_passes_arguments_through():
args.imagefile = NamedTemporaryFile()
args.text = 'some long text'
with patch('wordcloud_cli.wc.WordCloud', autospec=True) as mock_word_cloud:
with patch('wordcloud.wordcloud_cli.wc.WordCloud', autospec=True) as mock_word_cloud:
instance = mock_word_cloud.return_value
instance.to_image.return_value = MagicMock()
posargs, kwargs = mock_word_cloud.call_args
for option in all_arguments():
......@@ -63,7 +62,7 @@ def test_main_passes_arguments_through():
def check_argument(name, result_name, value):
text = NamedTemporaryFile()
args = wordcloud_cli.parse_args(['--text',, '--' + name, str(value)])
args = cli.parse_args(['--text',, '--' + name, str(value)])
assert_in(result_name, vars(args))
......@@ -71,8 +70,8 @@ def check_argument_type(name, value):
text = NamedTemporaryFile()
with patch('wordcloud_cli.sys.stderr') as mock_stdout:
args = wordcloud_cli.parse_args(['--text',, '--' + name, str(value)])
with patch('sys.stderr') as mock_stderr:
args = cli.parse_args(['--text',, '--' + name, str(value)])
raise AssertionError('argument "{}" was accepted even though the type did not match'.format(name))
except SystemExit:
......@@ -96,7 +95,7 @@ def test_check_duplicate_color_error():
text_file = NamedTemporaryFile()
wordcloud_cli.parse_args(['--color', 'red', '--colormask',, '--text',])
cli.parse_args(['--color', 'red', '--colormask',, '--text',])
raise AssertionError('parse_args(...) didn\'t raise')
except ValueError as e:
assert_true('specify either' in str(e), msg='expecting the correct error message, instead got: ' + str(e))
......@@ -105,5 +104,5 @@ def test_check_duplicate_color_error():
def test_parse_args_defaults_to_random_color():
text = NamedTemporaryFile()
args = wordcloud_cli.parse_args(['--text',])
args = cli.parse_args(['--text',])
assert_equal(args.color_func, wc.random_color_func)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment