Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
keeleliin
word_cloud_est
Commits
714f0a79
Commit
714f0a79
authored
Jan 28, 2016
by
Raphael Boidol
Browse files
extend test for cli with some output to check for str/byte problems
parent
00704e0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/test_wordcloud_cli.py
View file @
714f0a79
import
argparse
import
argparse
from
wordcloud
import
wordcloud_cli
as
cli
import
os
import
wordcloud
as
wc
from
collections
import
namedtuple
from
collections
import
namedtuple
from
mock
import
patch
,
MagicMock
from
nose.tools
import
assert_equal
,
assert_true
,
assert_in
from
tempfile
import
NamedTemporaryFile
from
tempfile
import
NamedTemporaryFile
import
wordcloud
as
wc
from
wordcloud
import
wordcloud_cli
as
cli
from
mock
import
patch
from
nose.tools
import
assert_equal
,
assert_greater
,
assert_true
,
assert_in
,
assert_not_in
temp
=
NamedTemporaryFile
()
temp
=
NamedTemporaryFile
()
ArgOption
=
namedtuple
(
'ArgOption'
,
[
'cli_name'
,
'init_name'
,
'pass_value'
,
'fail_value'
])
ArgOption
=
namedtuple
(
'ArgOption'
,
[
'cli_name'
,
'init_name'
,
'pass_value'
,
'fail_value'
])
ARGUMENT_SPEC_TYPED
=
[
ARGUMENT_SPEC_TYPED
=
[
...
@@ -31,16 +33,13 @@ def all_arguments():
...
@@ -31,16 +33,13 @@ def all_arguments():
def
test_main_passes_arguments_through
():
def
test_main_passes_arguments_through
():
args
=
argparse
.
Namespace
()
temp_imagefile
=
NamedTemporaryFile
()
args
=
argparse
.
Namespace
(
text
=
'some long text'
,
imagefile
=
open
(
temp_imagefile
.
name
,
'w'
))
for
option
in
all_arguments
():
for
option
in
all_arguments
():
setattr
(
args
,
option
.
init_name
,
option
.
pass_value
)
setattr
(
args
,
option
.
init_name
,
option
.
pass_value
)
args
.
imagefile
=
NamedTemporaryFile
()
args
.
imagefile
.
buffer
=
MagicMock
()
args
.
text
=
'some long text'
with
patch
(
'wordcloud.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
()
cli
.
main
(
args
)
cli
.
main
(
args
)
posargs
,
kwargs
=
mock_word_cloud
.
call_args
posargs
,
kwargs
=
mock_word_cloud
.
call_args
...
@@ -95,3 +94,16 @@ def test_parse_args_defaults_to_random_color():
...
@@ -95,3 +94,16 @@ def test_parse_args_defaults_to_random_color():
args
=
cli
.
parse_args
([
'--text'
,
text
.
name
])
args
=
cli
.
parse_args
([
'--text'
,
text
.
name
])
assert_equal
(
args
.
color_func
,
wc
.
random_color_func
)
assert_equal
(
args
.
color_func
,
wc
.
random_color_func
)
def
test_cli_writes_image
():
# ensure writting works with all python versions
temp_imagefile
=
NamedTemporaryFile
()
temp_textfile
=
NamedTemporaryFile
()
temp_textfile
.
write
(
b
'some text'
)
temp_textfile
.
flush
()
args
=
cli
.
parse_args
([
'--text'
,
temp_textfile
.
name
,
'--imagefile'
,
temp_imagefile
.
name
])
cli
.
main
(
args
)
assert_greater
(
os
.
path
.
getsize
(
temp_imagefile
.
name
),
0
,
msg
=
'expecting image to be written'
)
Write
Preview
Supports
Markdown
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