Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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)
        ])
Exemplo n.º 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']
Exemplo n.º 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)
Exemplo n.º 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)])
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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')
Exemplo n.º 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')
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 13
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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)])
Exemplo n.º 22
0
def test_cli_regexp(tmp_text_file):
    cli.parse_args(['--regexp', r"\w[\w']+", '--text', str(tmp_text_file)])
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 26
0
def test_cli_regexp(tmp_text_file):
    cli.parse_args(['--regexp', r"\w[\w']+", '--text', str(tmp_text_file)])
Exemplo n.º 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)])
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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)])
Exemplo n.º 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
Exemplo n.º 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))
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)
Exemplo n.º 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