From 6da7452b226e5be630e14a899ca7520ed2a5d983 Mon Sep 17 00:00:00 2001 From: Raphael Boidol Date: Mon, 1 Jan 2024 14:02:30 +0100 Subject: [PATCH] Add `svg` export to CLI --- test/test_wordcloud_cli.py | 17 +++++++++++++++++ wordcloud/wordcloud_cli.py | 10 +++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/test/test_wordcloud_cli.py b/test/test_wordcloud_cli.py index 5b50bce9a..c8fb3f6be 100644 --- a/test/test_wordcloud_cli.py +++ b/test/test_wordcloud_cli.py @@ -153,6 +153,23 @@ def test_cli_writes_to_imagefile(tmpdir, tmp_text_file): # expecting image to be written to imagefile assert tmp_image_file.size() > 0 + # assert png header + assert tmp_image_file.read('rb').startswith(b'\x89PNG') + + +def test_cli_writes_to_svg_imagefile(tmpdir, tmp_text_file): + # ensure writing works with all python versions + tmp_image_file = tmpdir.join('word_cloud.svg') + + 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 + # assert svg header + assert tmp_image_file.read().startswith('