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']
def test_cli_writes_to_imagefile(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 to imagefile assert tmp_image_file.size() > 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
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)])
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
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
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 test_cli_regexp(tmp_text_file): cli.parse_args(['--regexp', r"\w[\w']+", '--text', str(tmp_text_file)])
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
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
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)])