コード例 #1
0
def test_check_duplicate_color_error():
    color_mask_file = NamedTemporaryFile()
    text_file = NamedTemporaryFile()

    try:
        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))
コード例 #2
0
def test_check_duplicate_color_error():
    color_mask_file = NamedTemporaryFile()
    text_file = NamedTemporaryFile()

    try:
        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))
コード例 #3
0
def test_check_duplicate_color_error(tmpdir, tmp_text_file):
    color_mask_file = tmpdir.join("input_color_mask.png")
    color_mask_file.write(b"")

    with pytest.raises(ValueError, match=r'.*specify either.*'):
        cli.parse_args([
            '--color', 'red', '--colormask',
            str(color_mask_file), '--text',
            str(tmp_text_file)
        ])
コード例 #4
0
def test_unicode_with_stopwords():
    unicode_file = os.path.join(os.path.dirname(__file__), "unicode_text.txt")
    stopwords_file = os.path.join(os.path.dirname(__file__), "unicode_stopwords.txt")
    args, text, image_file = cli.parse_args(['--text', unicode_file, '--stopwords', stopwords_file])

    # expect the unicode character from stopwords file was correctly read in
    assert u'\u304D' in args['stopwords']
コード例 #5
0
def check_argument(name, result_name, value):
    text = NamedTemporaryFile()

    args, text, imagefile = cli.parse_args(
        ['--text', text.name, '--' + name,
         str(value)])
    assert_in(result_name, args)
コード例 #6
0
def check_argument_type(text_filepath, name, value):
    with pytest.raises(
        (SystemExit, ValueError),
            message=
            'argument "{}" was accepted even though the type did not match'.
            format(name)):
        args, text, image_file = cli.parse_args(
            ['--text', text_filepath, '--' + name,
             str(value)])
コード例 #7
0
def check_argument_type(name, value):
    text = NamedTemporaryFile()

    try:
        with patch('sys.stderr') as mock_stderr:
            args, text, imagefile = 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
    except ValueError:
        pass
コード例 #8
0
def check_argument_type(name, value):
    text = NamedTemporaryFile()

    try:
        with patch('sys.stderr') as mock_stderr:
            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
    except ValueError:
        pass
コード例 #9
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, 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')
コード例 #10
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')
コード例 #11
0
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
コード例 #12
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
コード例 #13
0
ファイル: test_wordcloud_cli.py プロジェクト: OrekiYuta/Temp
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
コード例 #14
0
def test_parse_args_defaults_to_random_color(tmp_text_file):
    args, text, image_file = cli.parse_args(['--text', str(tmp_text_file)])
    assert args['color_func'] == wc.random_color_func
コード例 #15
0
def test_unicode_text_file():
    unicode_file = os.path.join(os.path.dirname(__file__), "unicode_text.txt")
    args = cli.parse_args(['--text', unicode_file])
    assert_equal(len(args.text), 16)
コード例 #16
0
def check_argument_unary(text_filepath, name, result_name):
    args, text, image_file = cli.parse_args(
        ['--text', text_filepath, '--' + name])
    assert result_name in args
コード例 #17
0
def check_argument(name, result_name, value):
    text = NamedTemporaryFile()

    args, text, imagefile = cli.parse_args(['--text', text.name, '--' + name, str(value)])
    assert_in(result_name, args)
コード例 #18
0
def check_argument_unary(name, result_name):
    text = NamedTemporaryFile()

    args = cli.parse_args(['--text', text.name, '--' + name])
    assert_in(result_name, vars(args))
コード例 #19
0
def test_parse_args_defaults_to_random_color(tmp_text_file):
    args, text, image_file = cli.parse_args(['--text', str(tmp_text_file)])
    assert args['color_func'] == wc.random_color_func
コード例 #20
0
def test_cli_regexp_invalid(tmp_text_file, capsys):
    with pytest.raises(SystemExit):
        cli.parse_args(['--regexp', r"invalid[", '--text', str(tmp_text_file)])

    _, err = capsys.readouterr()
    assert "Invalid regular expression" in err
コード例 #21
0
def check_argument_type(text_filepath, name, value):
    with pytest.raises((SystemExit, ValueError), ):
        args, text, image_file = cli.parse_args(
            ['--text', text_filepath, '--' + name,
             str(value)])
コード例 #22
0
def test_cli_regexp(tmp_text_file):
    cli.parse_args(['--regexp', r"\w[\w']+", '--text', str(tmp_text_file)])
コード例 #23
0
def test_unicode_text_file():
    unicode_file = os.path.join(os.path.dirname(__file__), "unicode_text.txt")
    args, text, image_file = cli.parse_args(['--text', unicode_file])
    assert len(text) == 16
コード例 #24
0
def test_unicode_text_file():
    unicode_file = os.path.join(os.path.dirname(__file__), "unicode_text.txt")
    args, text, image_file = cli.parse_args(['--text', unicode_file])
    assert len(text) == 16
コード例 #25
0
def test_unicode_text_file():
    unicode_file = os.path.join(os.path.dirname(__file__), "unicode_text.txt")
    args = cli.parse_args(['--text', unicode_file])
    assert_equal(len(args.text), 16)
コード例 #26
0
def test_cli_regexp(tmp_text_file):
    cli.parse_args(['--regexp', r"\w[\w']+", '--text', str(tmp_text_file)])
コード例 #27
0
def test_check_duplicate_color_error(tmpdir, tmp_text_file):
    color_mask_file = tmpdir.join("input_color_mask.png")
    color_mask_file.write(b"")

    with pytest.raises(ValueError, match=r'.*specify either.*'):
        cli.parse_args(['--color', 'red', '--colormask', str(color_mask_file), '--text', str(tmp_text_file)])
コード例 #28
0
def test_parse_args_defaults_to_random_color():
    text = NamedTemporaryFile()

    args = cli.parse_args(['--text', text.name])
    assert_equal(args.color_func, wc.random_color_func)
コード例 #29
0
def check_argument_unary(text_filepath, name, result_name):
    args, text, image_file = cli.parse_args(['--text', text_filepath, '--' + name])
    assert result_name in args
コード例 #30
0
def check_argument_type(text_filepath, name, value):
    with pytest.raises(
            (SystemExit, ValueError),
            message='argument "{}" was accepted even though the type did not match'.format(name)
    ):
        args, text, image_file = cli.parse_args(['--text', text_filepath, '--' + name, str(value)])
コード例 #31
0
def check_argument(text_filepath, name, result_name, value):
    args, text, image_file = cli.parse_args(
        ['--text', text_filepath, '--' + name,
         str(value)])
    assert result_name in args
コード例 #32
0
def test_cli_regexp_invalid(tmp_text_file, capsys):
    with pytest.raises(SystemExit):
        cli.parse_args(['--regexp', r"invalid[", '--text', str(tmp_text_file)])

    _, err = capsys.readouterr()
    assert "Invalid regular expression" in err
def check_argument_unary(name, result_name):
    text = NamedTemporaryFile()

    args = cli.parse_args(['--text', text.name, '--' + name])
    assert_in(result_name, vars(args))
コード例 #34
0
def test_parse_args_defaults_to_random_color():
    text = NamedTemporaryFile()

    args = cli.parse_args(['--text', text.name])
    assert_equal(args.color_func, wc.random_color_func)
コード例 #35
0
def check_argument(text_filepath, name, result_name, value):
    args, text, image_file = cli.parse_args(['--text', text_filepath, '--' + name, str(value)])
    assert result_name in args