class TestReadPipEnvironment: @pytest.mark.skipif( not any(re.match(SPACY_MODEL_PATTERN + "==", req) for req in get_pip_freeze()), reason="requires spaCy model pinned in environment (`python -m spacy download en_core_web_sm` with pip<20)", ) def test_skip_spacy_models(self): pattern = SPACY_MODEL_PATTERN + "==" requirements = Python.read_pip_environment() assert not any(re.match(pattern, req) for req in requirements)
def requirements_file(): """Create requirements file from pip freeze.""" pip_freeze = _pip_requirements_utils.get_pip_freeze() pip_freeze = _pip_requirements_utils.clean_reqs_file_lines(pip_freeze) with tempfile.NamedTemporaryFile("w+") as tempf: tempf.write("\n".join(pip_freeze)) tempf.flush() # flush object buffer os.fsync(tempf.fileno()) # flush OS buffer tempf.seek(0) yield tempf
def test_parse_pip_freeze(self): req_specs = _pip_requirements_utils.get_pip_freeze() parsed_req_specs = ( (library, constraint, _pip_requirements_utils.parse_version(version)) for library, constraint, version in map(_pip_requirements_utils.parse_req_spec, req_specs) ) for library, constraint, parsed_version in parsed_req_specs: assert library != "" assert ' ' not in library assert constraint in _pip_requirements_utils.VER_SPEC_PATTERN.strip('()').split('|') assert parsed_version[0] >= 0 # major assert parsed_version[1] >= 0 # minor assert parsed_version[2] >= 0 # patch assert isinstance(parsed_version[3], six.string_types) # suffix
def test_no_spacy_models_in_pip_freeze(self): spacy = pytest.importorskip("spacy") try: spacy.load("en_core_web_sm") except OSError: pytest.skip("SpaCy en_core_web_sm model not installed") # baseline: en_core_web_sm in pip freeze assert list(filter( _pip_requirements_utils.SPACY_MODEL_REGEX.match, six.ensure_str( subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']), ).splitlines(), )) # en_core_web_sm not in our pip freeze util assert not list(filter( _pip_requirements_utils.SPACY_MODEL_REGEX.match, _pip_requirements_utils.get_pip_freeze(), ))