Add minimal test

This commit is contained in:
Paul O'Leary McCann 2022-08-25 17:14:06 +09:00
parent 5afa98aabf
commit eb697d8371
2 changed files with 11 additions and 3 deletions

View File

@ -36,6 +36,7 @@ from spacy.training import Example, docs_to_json, offsets_to_biluo_tags
from spacy.training.converters import conll_ner_to_docs, conllu_to_docs from spacy.training.converters import conll_ner_to_docs, conllu_to_docs
from spacy.training.converters import iob_to_docs from spacy.training.converters import iob_to_docs
from spacy.util import ENV_VARS, get_minor_version, load_model_from_config, load_config from spacy.util import ENV_VARS, get_minor_version, load_model_from_config, load_config
from spacy.util import run_command
from ..cli.init_pipeline import _init_labels from ..cli.init_pipeline import _init_labels
from .util import make_tempdir from .util import make_tempdir
@ -855,3 +856,9 @@ def test_span_length_freq_dist_output_must_be_correct():
span_freqs = _get_spans_length_freq_dist(sample_span_lengths, threshold) span_freqs = _get_spans_length_freq_dist(sample_span_lengths, threshold)
assert sum(span_freqs.values()) >= threshold assert sum(span_freqs.values()) >= threshold
assert list(span_freqs.keys()) == [3, 1, 4, 5, 2] assert list(span_freqs.keys()) == [3, 1, 4, 5, 2]
def test_shell_quoting():
# simple quoted shell commands should run on any platform
ret = run_command('bash -c "echo ok"')
assert ret.returncode == 0

View File

@ -937,12 +937,12 @@ def replace_model_node(model: Model, target: Model, replacement: Model) -> None:
def split_command(command: str) -> List[str]: def split_command(command: str) -> List[str]:
"""Split a string command using shlex. Handles platform compatibility. """Split a string command using shlex.
command (str) : The command to split command (str) : The command to split
RETURNS (List[str]): The split command. RETURNS (List[str]): The split command.
""" """
return shlex.split(command, posix=not is_windows) return shlex.split(command, posix=True)
def join_command(command: List[str]) -> str: def join_command(command: List[str]) -> str:
@ -981,8 +981,9 @@ def run_command(
cmd_list = command cmd_list = command
cmd_str = " ".join(command) cmd_str = " ".join(command)
try: try:
cmd_to_run = cmd_str if is_windows else cmd_list
ret = subprocess.run( ret = subprocess.run(
cmd_list, cmd_to_run,
env=os.environ.copy(), env=os.environ.copy(),
input=stdin, input=stdin,
encoding="utf8", encoding="utf8",