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
00704e0a
Commit
00704e0a
authored
Jan 26, 2016
by
Raphael Boidol
Browse files
cli should be able to write bytes to the output in python 3, too
parent
0b0e8809
Changes
2
Show whitespace changes
Inline
Side-by-side
test/test_wordcloud_cli.py
View file @
00704e0a
import
argparse
import
inspect
from
wordcloud
import
wordcloud_cli
as
cli
import
wordcloud
as
wc
from
collections
import
namedtuple
...
...
@@ -31,22 +30,12 @@ def all_arguments():
return
arguments
def
test_argument_spec_matches_to_constructor_args
():
args
=
argparse
.
Namespace
()
for
option
in
all_arguments
():
setattr
(
args
,
option
.
init_name
,
option
.
pass_value
)
supported_args
=
inspect
.
getargspec
(
wc
.
WordCloud
.
__init__
).
args
supported_args
.
remove
(
'self'
)
for
arg_name
in
vars
(
args
).
keys
():
assert_in
(
arg_name
,
supported_args
)
def
test_main_passes_arguments_through
():
args
=
argparse
.
Namespace
()
for
option
in
all_arguments
():
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
:
...
...
wordcloud/wordcloud_cli.py
View file @
00704e0a
...
...
@@ -10,7 +10,6 @@ import argparse
import
wordcloud
as
wc
import
numpy
as
np
import
sys
import
io
from
PIL
import
Image
def
main
(
args
):
...
...
@@ -20,10 +19,9 @@ def main(args):
color_func
=
args
.
color_func
,
background_color
=
args
.
background_color
).
generate
(
args
.
text
)
image
=
wordcloud
.
to_image
()
b
=
io
.
BytesIO
()
image
.
save
(
b
,
format
=
'png'
)
with
args
.
imagefile
:
args
.
imagefile
.
write
(
b
.
getvalue
())
out
=
args
.
imagefile
if
sys
.
version
<
'3'
else
args
.
imagefile
.
buffer
image
.
save
(
out
,
format
=
'png'
)
def
parse_args
(
arguments
):
prog
=
'python wordcloud_cli.py'
...
...
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