Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
keeleliin
word_cloud_est
Commits
520f0fd8
Commit
520f0fd8
authored
Jan 23, 2016
by
Raphael Boidol
Browse files
adapt tests for cli to run with travis
parent
cc36d8b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
continuous_integration/install.sh
View file @
520f0fd8
...
...
@@ -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
fi
pip
install
-r
requirements.txt
...
...
test/test_wordcloud_cli.py
View file @
520f0fd8
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
nose.tools
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
()
wordcloud_
cli
.
main
(
args
)
cli
.
main
(
args
)
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'
,
text
.
name
,
'--'
+
name
,
str
(
value
)])
args
=
cli
.
parse_args
([
'--text'
,
text
.
name
,
'--'
+
name
,
str
(
value
)])
assert_in
(
result_name
,
vars
(
args
))
...
...
@@ -71,8 +70,8 @@ def check_argument_type(name, value):
text
=
NamedTemporaryFile
()
try
:
with
patch
(
'
wordcloud_cli.
sys.stderr'
)
as
mock_std
out
:
args
=
wordcloud_
cli
.
parse_args
([
'--text'
,
text
.
name
,
'--'
+
name
,
str
(
value
)])
with
patch
(
'sys.stderr'
)
as
mock_std
err
:
args
=
cli
.
parse_args
([
'--text'
,
text
.
name
,
'--'
+
name
,
str
(
value
)])
raise
AssertionError
(
'argument "{}" was accepted even though the type did not match'
.
format
(
name
))
except
SystemExit
:
pass
...
...
@@ -96,7 +95,7 @@ def test_check_duplicate_color_error():
text_file
=
NamedTemporaryFile
()
try
:
wordcloud_
cli
.
parse_args
([
'--color'
,
'red'
,
'--colormask'
,
color_mask_file
.
name
,
'--text'
,
text_file
.
name
])
cli
.
parse_args
([
'--color'
,
'red'
,
'--colormask'
,
color_mask_file
.
name
,
'--text'
,
text_file
.
name
])
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'
,
text
.
name
])
args
=
cli
.
parse_args
([
'--text'
,
text
.
name
])
assert_equal
(
args
.
color_func
,
wc
.
random_color_func
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment