def test_load_disable_enable():
    """Tests spacy.load() with dis-/enabling components."""

    base_nlp = English()
    for pipe in ("sentencizer", "tagger", "parser"):
        base_nlp.add_pipe(pipe)

    with make_tempdir() as tmp_dir:
        base_nlp.to_disk(tmp_dir)
        to_disable = ["parser", "tagger"]
        to_enable = ["tagger", "parser"]
        single_str = "tagger"

        # Setting only `disable`.
        nlp = spacy.load(tmp_dir, disable=to_disable)
        assert all([comp_name in nlp.disabled for comp_name in to_disable])

        # Setting only `enable`.
        nlp = spacy.load(tmp_dir, enable=to_enable)
        assert all(
            [
                (comp_name in nlp.disabled) is (comp_name not in to_enable)
                for comp_name in nlp.component_names
            ]
        )

        # Loading with a string representing one component
        nlp = spacy.load(tmp_dir, exclude=single_str)
        assert single_str not in nlp.component_names

        nlp = spacy.load(tmp_dir, disable=single_str)
        assert single_str in nlp.component_names
        assert single_str not in nlp.pipe_names
        assert nlp._disabled == {single_str}
        assert nlp.disabled == [single_str]

        # Testing consistent enable/disable combination.
        nlp = spacy.load(
            tmp_dir,
            enable=to_enable,
            disable=[
                comp_name
                for comp_name in nlp.component_names
                if comp_name not in to_enable
            ],
        )
        assert all(
            [
                (comp_name in nlp.disabled) is (comp_name not in to_enable)
                for comp_name in nlp.component_names
            ]
        )

        # Inconsistent enable/disable combination.
        with pytest.raises(ValueError):
            spacy.load(tmp_dir, enable=to_enable, disable=["parser"])
Tests spacy.load() with dis-/enabling components.
spacy/tests/pipeline/test_pipe_methods.py