def test_update_version(self, registered_model, in_tempdir, requirements_file): LogisticRegression = pytest.importorskip('sklearn.linear_model').LogisticRegression model_name = registered_model.name version_name = "my version" registered_model.get_or_create_version(version_name) filename = "tiny1.bin" FILE_CONTENTS = os.urandom(2**16) with open(filename, 'wb') as f: f.write(FILE_CONTENTS) classifier_name = "tiny2.pth" classifier = LogisticRegression() with open(classifier_name, 'wb') as f: pickle.dump(classifier, f) runner = CliRunner() result = runner.invoke( cli, ['registry', 'update', 'registeredmodelversion', model_name, version_name, '-l', 'label1', '-l', 'label2', "--artifact", "file={}".format(filename), "--model", classifier_name, "--requirements", requirements_file.name], ) assert not result.exception model_version = registered_model.get_version(name=version_name) assert model_version.get_artifact("file").read() == FILE_CONTENTS assert model_version.get_labels() == ["label1", "label2"] assert model_version.get_model().get_params() == classifier.get_params() # Check environment: reqs = Python.read_pip_file(requirements_file.name) env = Python(requirements=reqs) assert repr(env) == str(model_version.get_environment())
def test_from_file(self, requirements_file): reqs = Python.read_pip_file(requirements_file.name) env = Python(requirements=[], constraints=reqs) assert env._msg.python.constraints assert not env._msg.python.raw_constraints assert_parsed_reqs_match(env.constraints, reqs)
def test_from_file_no_versions(self, requirements_file_without_versions): reqs = Python.read_pip_file(requirements_file_without_versions.name) env = Python(requirements=reqs) assert env._msg.python.requirements assert not env._msg.python.raw_requirements parsed_libraries = set(req.split("==")[0] for req in env.requirements) assert parsed_libraries == set(reqs) | {"verta", "cloudpickle"}
def test_from_files(self, requirements_file): reqs = Python.read_pip_file(requirements_file.name) env = Python(requirements=reqs) assert env._msg.python.requirements assert not env._msg.python.raw_requirements reqs = pin_verta_and_cloudpickle(reqs) assert_parsed_reqs_match(env.requirements, reqs)
def test_reqs_no_unsupported_lines( self, requirements_file_with_unsupported_lines): reqs = Python.read_pip_file( requirements_file_with_unsupported_lines.name) env = Python(requirements=reqs) requirements = {req.library for req in env._msg.python.requirements} # only has injected requirements assert requirements == {"verta", "cloudpickle"}
def test_legacy_no_unsupported_lines(self, requirements_file_with_unsupported_lines): """Unsupported lines are filtered out with legacy `skip_options=True`""" reqs = Python.read_pip_file( requirements_file_with_unsupported_lines.name, skip_options=True, ) env = Python(requirements=reqs) requirements = {req.library for req in env._msg.python.requirements} # only has injected requirements assert requirements == {"verta", "cloudpickle"}
def test_from_file_no_versions( self, requirements_file_without_versions, caplog ): constraints = Python.read_pip_file(requirements_file_without_versions.name) with caplog.at_level(logging.INFO, logger="verta"): env = Python(requirements=[], constraints=constraints) assert "failed to manually parse constraints; falling back to capturing raw contents" in caplog.text assert "missing its version specifier" in caplog.text assert not env._msg.python.constraints assert env._msg.python.raw_constraints assert env._msg.python.raw_constraints == requirements_file_without_versions.read() assert set(env.constraints) == set(constraints)
def test_unsupported_lines( self, requirements_file_with_unsupported_lines, caplog ): """Constraints with unsupported lines get logged raw.""" constraints = Python.read_pip_file(requirements_file_with_unsupported_lines.name) # each line gets logged raw for constraint in constraints: with caplog.at_level(logging.INFO, logger="verta"): env = Python(requirements=[], constraints=[constraint]) assert "failed to manually parse constraints; falling back to capturing raw contents" in caplog.text caplog.clear() assert not env._msg.python.constraints assert env._msg.python.raw_constraints expected_constraints = [constraint] assert env.constraints == expected_constraints
def test_unsupported_lines( self, requirements_file_with_unsupported_lines, caplog ): """Requirements with unsupported lines get logged raw.""" reqs = Python.read_pip_file(requirements_file_with_unsupported_lines.name) # each line gets logged raw for req in reqs: with caplog.at_level(logging.INFO, logger="verta"): env = Python(requirements=[req]) assert "failed to manually parse requirements; falling back to capturing raw contents" in caplog.text caplog.clear() assert not env._msg.python.requirements assert env._msg.python.raw_requirements expected_reqs = pin_verta_and_cloudpickle([req]) assert env.requirements == expected_reqs
def test_constraints_from_file_no_versions_error( self, requirements_file_without_versions): reqs = Python.read_pip_file(requirements_file_without_versions.name) with pytest.raises(ValueError): Python(requirements=[], constraints=reqs)
def test_constraints_from_file(self, requirements_file): reqs = Python.read_pip_file(requirements_file.name) env = Python(requirements=[], constraints=reqs) assert env._msg.python.constraints
def test_reqs_without_versions(self, requirements_file_without_versions): reqs = Python.read_pip_file(requirements_file_without_versions.name) env = Python(requirements=reqs) assert env._msg.python.requirements
def test_reqs(self, requirements_file): reqs = Python.read_pip_file(requirements_file.name) env = Python(requirements=reqs) assert env._msg.python.requirements