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))
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) ])
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 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)
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)])
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
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
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')
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(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_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_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 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_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)
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(name, result_name, value): text = NamedTemporaryFile() args, text, imagefile = cli.parse_args(['--text', text.name, '--' + name, str(value)]) assert_in(result_name, args)
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_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_type(text_filepath, name, value): with pytest.raises((SystemExit, ValueError), ): args, text, image_file = cli.parse_args( ['--text', text_filepath, '--' + name, str(value)])
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_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)])
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)
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_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)])
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 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