def test_cli_writes_image(tmpdir, tmp_text_file):
    # ensure writing works with all python versions
    tmp_image_file = tmpdir.join("word_cloud.png")

    tmp_text_file.write(b'some text')

    args, text, image_file = cli.parse_args(['--text', str(tmp_text_file), '--imagefile', str(tmp_image_file)])
    cli.main(args, text, image_file)

    # expecting image to be written
    assert tmp_image_file.size() > 0
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')
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, text, imagefile = cli.parse_args(['--text', temp_textfile.name, '--imagefile', temp_imagefile.name])
    cli.main(args, text, imagefile)

    assert_greater(os.path.getsize(temp_imagefile.name), 0, msg='expecting image to be written')
Exemple #4
0
def test_cli_writes_to_stdout(tmpdir, tmp_text_file):
    # ensure writing works with all python versions
    tmp_image_file = tmpdir.join("word_cloud.png")

    tmp_text_file.write(b'some text')

    with contextlib.redirect_stdout(tmp_image_file.open('w+')):
        args, text, image_file = cli.parse_args(['--text', str(tmp_text_file)])
        cli.main(args, text, image_file)

    # expecting image to be written to stdout
    assert tmp_image_file.size() > 0
def test_main_passes_arguments_through():
    temp_imagefile = NamedTemporaryFile()

    args = argparse.Namespace(text='some long text', imagefile=open(temp_imagefile.name, 'w'))
    for option in all_arguments():
        setattr(args, option.init_name, option.pass_value)

    with patch('wordcloud.wordcloud_cli.wc.WordCloud', autospec=True) as mock_word_cloud:
        cli.main(args)

    posargs, kwargs = mock_word_cloud.call_args
    for option in all_arguments():
        assert_in(option.init_name, kwargs)
def test_main_passes_arguments_through():
    temp_imagefile = NamedTemporaryFile()

    args = argparse.Namespace(text='some long text',
                              imagefile=open(temp_imagefile.name, 'w'))
    for option in all_arguments():
        setattr(args, option.init_name, option.pass_value)

    with patch('wordcloud.wordcloud_cli.wc.WordCloud',
               autospec=True) as mock_word_cloud:
        cli.main(args)

    posargs, kwargs = mock_word_cloud.call_args
    for option in all_arguments():
        assert_in(option.init_name, kwargs)
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.text = 'some long text'

    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)

    posargs, kwargs = mock_word_cloud.call_args
    for option in all_arguments():
        assert_in(option.init_name, kwargs)
def test_main_passes_arguments_through(tmpdir):

    image_filepath = str(tmpdir.join('word_cloud.png'))

    args = argparse.Namespace()
    for option in all_arguments():
        setattr(args, option.init_name, option.pass_value)

    text = 'some long text'
    image_file = open(image_filepath, 'w')
    with patch('wordcloud.wordcloud_cli.wc.WordCloud', autospec=True) as mock_word_cloud:
        cli.main(vars(args), text, image_file)

    posargs, kwargs = mock_word_cloud.call_args
    for option in all_arguments():
        assert option.init_name in kwargs
Exemple #9
0
def test_cli_writes_to_stdout(tmpdir, tmp_text_file):
    # ensure writing works with all python versions
    tmp_image_file = tmpdir.join("word_cloud.png")

    tmp_text_file.write(b'some text')

    originalBuffer = sys.stdout.buffer
    sys.stdout.buffer = tmp_image_file.open('wb+')

    args, text, image_file = cli.parse_args(['--text', str(tmp_text_file)])
    cli.main(args, text, image_file)

    sys.stdout.buffer = originalBuffer

    # expecting image to be written to stdout
    assert tmp_image_file.size() > 0