Move to test util method

This commit is contained in:
Adriane Boyd 2023-01-27 11:02:31 +01:00
parent f4e98812fe
commit 431465befc
2 changed files with 9 additions and 5 deletions

View File

@ -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"),
)

View File

@ -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)