From 431465befc2a208e420474fed27303cc3940f846 Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Fri, 27 Jan 2023 11:02:31 +0100 Subject: [PATCH] Move to test util method --- spacy/tests/test_cli_app.py | 8 +++----- spacy/tests/util.py | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spacy/tests/test_cli_app.py b/spacy/tests/test_cli_app.py index 5f1ce81f0..b3527d60d 100644 --- a/spacy/tests/test_cli_app.py +++ b/spacy/tests/test_cli_app.py @@ -1,10 +1,9 @@ import os -import re from pathlib import Path from typer.testing import CliRunner from spacy.cli._util import app -from .util import make_tempdir +from .util import make_tempdir, assert_strings_equal_except_ws def test_convert_auto(): @@ -38,8 +37,7 @@ def test_benchmark_accuracy_alias(): # Verify that the `evaluate` alias works correctly. result_benchmark = CliRunner().invoke(app, ["benchmark", "accuracy", "--help"]) result_evaluate = CliRunner().invoke(app, ["evaluate", "--help"]) - assert re.sub(r"\s+", " ", result_benchmark.stdout) == re.sub( - r"\s+", - " ", + assert_strings_equal_except_ws( + result_benchmark.stdout, result_evaluate.stdout.replace("spacy evaluate", "spacy benchmark accuracy"), ) diff --git a/spacy/tests/util.py b/spacy/tests/util.py index d5f3c39ff..aac8579eb 100644 --- a/spacy/tests/util.py +++ b/spacy/tests/util.py @@ -1,6 +1,7 @@ import numpy import tempfile import contextlib +import re import srsly from spacy.tokens import Doc from spacy.vocab import Vocab @@ -95,3 +96,8 @@ def assert_packed_msg_equal(b1, b2): for (k1, v1), (k2, v2) in zip(sorted(msg1.items()), sorted(msg2.items())): assert k1 == k2 assert v1 == v2 + + +def assert_strings_equal_except_ws(s1, s2): + """Assert that two strings are identical except for whitespace.""" + assert re.sub(r"\s+", " ", s1) == re.sub(r"\s+", " ", s2)