Exemple #1
0
    def test_creation_and_hydration(self):
        name = random_str()
        description = random_str()
        rmd_1 = RegisteredModel(name, 1, 2, description, [])
        self._check(rmd_1, name, 1, 2, description, [])

        as_dict = {
            "name": name,
            "creation_timestamp": 1,
            "last_updated_timestamp": 2,
            "description": description,
            "latest_versions": []
        }
        self.assertEqual(dict(rmd_1), as_dict)

        proto = rmd_1.to_proto()
        self.assertEqual(proto.name, name)
        self.assertEqual(proto.creation_timestamp, 1)
        self.assertEqual(proto.last_updated_timestamp, 2)
        self.assertEqual(proto.description, description)
        rmd_2 = RegisteredModel.from_proto(proto)
        self._check(rmd_2, name, 1, 2, description, [])

        rmd_3 = RegisteredModel.from_dictionary(as_dict)
        self._check(rmd_3, name, 1, 2, description, [])
Exemple #2
0
    def test_creation_and_hydration(self):
        name = random_str()
        registered_model = RegisteredModel(name)
        self._check(registered_model, name)

        as_dict = {"name": name}
        self.assertEqual(dict(registered_model), as_dict)

        proto = registered_model.to_proto()
        self.assertEqual(proto.name, name)
        registered_model2 = RegisteredModel.from_proto(proto)
        self._check(registered_model2, name)

        registered_model3 = RegisteredModel.from_dictionary(as_dict)
        self._check(registered_model3, name)
    def test_creation_and_hydration(self):
        name = random_str()
        rm = RegisteredModel(name)
        t1, t2 = 100, 150
        source = "path/to/source"
        run_id = uuid.uuid4().hex
        mvd = ModelVersionDetailed(rm, 5, t1, t2, "version five", "user 1",
                                   "Production", source, run_id, "READY",
                                   "Model version #5 is ready to use.")
        self._check(mvd, name, 5, t1, t2, "version five", "user 1",
                    "Production", source, run_id, "READY",
                    "Model version #5 is ready to use.")

        expected_dict = {
            "version": 5,
            "creation_timestamp": t1,
            "last_updated_timestamp": t2,
            "description": "version five",
            "user_id": "user 1",
            "current_stage": "Production",
            "source": source,
            "run_id": run_id,
            "status": "READY",
            "status_message": "Model version #5 is ready to use."
        }
        model_version_as_dict = dict(mvd)
        self.assertIsInstance(model_version_as_dict["registered_model"],
                              RegisteredModel)
        self.assertEqual(model_version_as_dict["registered_model"].name, name)
        model_version_as_dict.pop("registered_model")
        self.assertEqual(model_version_as_dict, expected_dict)

        proto = mvd.to_proto()
        self.assertEqual(proto.model_version.registered_model.name, name)
        self.assertEqual(proto.model_version.version, 5)
        self.assertEqual(proto.status, ModelVersionStatus.from_string("READY"))
        self.assertEqual(proto.status_message,
                         "Model version #5 is ready to use.")
        mvd_2 = ModelVersionDetailed.from_proto(proto)
        self._check(mvd_2, name, 5, t1, t2, "version five", "user 1",
                    "Production", source, run_id, "READY",
                    "Model version #5 is ready to use.")

        expected_dict.update({"registered_model": RegisteredModel(name)})
        mvd_3 = ModelVersionDetailed.from_dictionary(expected_dict)
        self._check(mvd_3, name, 5, t1, t2, "version five", "user 1",
                    "Production", source, run_id, "READY",
                    "Model version #5 is ready to use.")
Exemple #4
0
 def test_string_repr(self):
     rmd = RegisteredModel(name="myname",
                           creation_timestamp=1000,
                           last_updated_timestamp=2002,
                           description="something about a model",
                           latest_versions=["1", "2", "3"])
     assert str(rmd) == "<RegisteredModel: creation_timestamp=1000, " \
                        "description='something about a model', last_updated_timestamp=2002, " \
                        "latest_versions=['1', '2', '3'], name='myname'>"
Exemple #5
0
    def test_with_latest_model_versions(self):
        name = random_str()
        mvd_1 = ModelVersion(
            name,
            "1",
            1000,
            2000,
            "version 1",
            "user 1",
            "Production",
            "source 1",
            "run ID 1",
            "PENDING_REGISTRATION",
            "Model version is in production!",
        )
        mvd_2 = ModelVersion(
            name,
            "4",
            1300,
            2002,
            "version 4",
            "user 2",
            "Staging",
            "source 4",
            "run ID 12",
            "READY",
            "Model copied over!",
        )
        as_dict = {
            "name": name,
            "creation_timestamp": 1,
            "last_updated_timestamp": 4000,
            "description": random_str(),
            "latest_versions": [mvd_1, mvd_2],
            "tags": [],
        }
        rmd_1 = RegisteredModel.from_dictionary(as_dict)
        as_dict["tags"] = {}
        self.assertEqual(dict(rmd_1), as_dict)

        proto = rmd_1.to_proto()
        self.assertEqual(proto.creation_timestamp, 1)
        self.assertEqual(proto.last_updated_timestamp, 4000)
        self.assertEqual(set([mvd.version for mvd in proto.latest_versions]), set(["1", "4"]))
        self.assertEqual(set([mvd.name for mvd in proto.latest_versions]), set([name]))
        self.assertEqual(
            set([mvd.current_stage for mvd in proto.latest_versions]),
            set(["Production", "Staging"]),
        )
        self.assertEqual(
            set([mvd.last_updated_timestamp for mvd in proto.latest_versions]), set([2000, 2002])
        )
        self.assertEqual(
            set([mvd.creation_timestamp for mvd in proto.latest_versions]), set([1300, 1000])
        )
    def test_with_latest_model_versions(self):
        name = random_str()
        mvd_1 = ModelVersionDetailed(RegisteredModel(name), 1, 1000, 2000,
                                     "version 1", "user 1", "Production",
                                     "source 1", "run ID 1", "FAILED_DELETION",
                                     "Model version is in production!")
        mvd_2 = ModelVersionDetailed(RegisteredModel(name), 4, 1300, 2002,
                                     "version 4", "user 2", "Staging",
                                     "source 4", "run ID 12", "READY",
                                     "Model copied over!")
        as_dict = {
            "name": name,
            "creation_timestamp": 1,
            "last_updated_timestamp": 4000,
            "description": random_str(),
            "latest_versions": [mvd_1, mvd_2]
        }
        rmd_1 = RegisteredModelDetailed.from_dictionary(as_dict)
        self.assertEqual(dict(rmd_1), as_dict)

        proto = rmd_1.to_proto()
        self.assertEqual(proto.creation_timestamp, 1)
        self.assertEqual(proto.last_updated_timestamp, 4000)
        self.assertEqual(
            set([mvd.model_version.version for mvd in proto.latest_versions]),
            set([1, 4]))
        self.assertEqual(
            set([
                mvd.model_version.registered_model.name
                for mvd in proto.latest_versions
            ]), set([
                name,
            ]))
        self.assertEqual(
            set([mvd.current_stage for mvd in proto.latest_versions]),
            set(["Production", "Staging"]))
        self.assertEqual(
            set([mvd.last_updated_timestamp for mvd in proto.latest_versions]),
            set([2000, 2002]))
        self.assertEqual(
            set([mvd.creation_timestamp for mvd in proto.latest_versions]),
            set([1300, 1000]))
Exemple #7
0
    def test_creation_and_hydration(self):
        name = random_str()
        t1, t2 = 100, 150
        source = "path/to/source"
        run_id = uuid.uuid4().hex
        run_link = "http://localhost:5000/path/to/run"
        tags = [ModelVersionTag("key", "value"), ModelVersionTag("randomKey", "not a random value")]
        mvd = ModelVersion(name, "5", t1, t2, "version five", "user 1", "Production",
                           source, run_id, "READY", "Model version #5 is ready to use.", tags,
                           run_link)
        self._check(mvd, name, "5", t1, t2, "version five", "user 1",
                    "Production", source, run_id, "READY",
                    "Model version #5 is ready to use.",
                    {tag.key: tag.value for tag in (tags or [])})

        expected_dict = {
            "name": name,
            "version": "5",
            "creation_timestamp": t1,
            "last_updated_timestamp": t2,
            "description": "version five",
            "user_id": "user 1",
            "current_stage": "Production",
            "source": source,
            "run_id": run_id,
            "run_link": run_link,
            "status": "READY",
            "status_message": "Model version #5 is ready to use.",
            "tags": {tag.key: tag.value for tag in (tags or [])}}
        model_version_as_dict = dict(mvd)
        self.assertEqual(model_version_as_dict, expected_dict)

        proto = mvd.to_proto()
        self.assertEqual(proto.name, name)
        self.assertEqual(proto.version, "5")
        self.assertEqual(proto.status, ModelVersionStatus.from_string("READY"))
        self.assertEqual(proto.status_message, "Model version #5 is ready to use.")
        self.assertEqual(set([tag.key for tag in proto.tags]),
                         set(["key", "randomKey"]))
        self.assertEqual(set([tag.value for tag in proto.tags]),
                         set(["value", "not a random value"]))
        mvd_2 = ModelVersion.from_proto(proto)
        self._check(mvd_2, name, "5", t1, t2, "version five", "user 1",
                    "Production", source, run_id, "READY",
                    "Model version #5 is ready to use.",
                    {tag.key: tag.value for tag in (tags or [])})

        expected_dict.update({"registered_model": RegisteredModel(name)})
        expected_dict["tags"] = tags
        mvd_3 = ModelVersion.from_dictionary(expected_dict)
        self._check(mvd_3, name, "5", t1, t2, "version five", "user 1",
                    "Production", source, run_id, "READY",
                    "Model version #5 is ready to use.",
                    {tag.key: tag.value for tag in (tags or [])})
    def test_creation_and_hydration(self):
        name = random_str()
        rm = RegisteredModel(name)
        model_version = ModelVersion(rm, 100)
        self._check(model_version, name, 100)

        expected_dict = {"version": 100}
        model_version_as_dict = dict(model_version)
        self.assertEqual(model_version_as_dict["version"], 100)
        self.assertIsInstance(model_version_as_dict["registered_model"],
                              RegisteredModel)
        self.assertEqual(model_version_as_dict["registered_model"].name, name)
        model_version_as_dict.pop("registered_model")
        self.assertEqual(model_version_as_dict, expected_dict)

        proto = model_version.to_proto()
        self.assertEqual(proto.registered_model.name, name)
        self.assertEqual(proto.version, 100)
        model_version_2 = ModelVersion.from_proto(proto)
        self._check(model_version_2, name, 100)

        expected_dict.update({"registered_model": RegisteredModel(name)})
        model_version_3 = ModelVersion.from_dictionary(expected_dict)
        self._check(model_version_3, name, 100)
 def test_string_repr(self):
     model_version = ModelVersionDetailed(
         RegisteredModel(name="myname"),
         version=43,
         creation_timestamp=12,
         last_updated_timestamp=100,
         description="This is a test model.",
         user_id="user one",
         current_stage="Archived",
         source="path/to/a/notebook",
         run_id="some run",
         status="PENDING_REGISTRATION",
         status_message="Copying!")
     assert str(model_version) == "<ModelVersionDetailed: creation_timestamp=12, " \
                                  "current_stage='Archived', description='This is a test " \
                                  "model.', last_updated_timestamp=100, " \
                                  "registered_model=<RegisteredModel: name='myname'>, " \
                                  "run_id='some run', source='path/to/a/notebook', " \
                                  "status='PENDING_REGISTRATION', status_message='Copying!', " \
                                  "user_id='user one', version=43>"
Exemple #10
0
 def test_with_tags(self):
     name = random_str()
     tag1 = RegisteredModelTag("key", "value")
     tag2 = RegisteredModelTag("randomKey", "not a random value")
     tags = [tag1, tag2]
     as_dict = {
         "name": name,
         "creation_timestamp": 1,
         "last_updated_timestamp": 4000,
         "description": random_str(),
         "latest_versions": [],
         "tags": tags
     }
     rmd_1 = RegisteredModel.from_dictionary(as_dict)
     as_dict["tags"] = {tag.key: tag.value for tag in (tags or [])}
     self.assertEqual(dict(rmd_1), as_dict)
     proto = rmd_1.to_proto()
     self.assertEqual(proto.creation_timestamp, 1)
     self.assertEqual(proto.last_updated_timestamp, 4000)
     self.assertEqual(set([tag.key for tag in proto.tags]),
                      set(["key", "randomKey"]))
     self.assertEqual(set([tag.value for tag in proto.tags]),
                      set(["value", "not a random value"]))
Exemple #11
0
 def _properties(cls):
     # aggregate with base class properties since cls.__dict__ does not do it automatically
     return sorted(cls._get_properties_helper() +
                   RegisteredModel._properties())
 def test_string_repr(self):
     model_version = ModelVersion(RegisteredModel(name="myname"), version=4)
     assert str(model_version) == "<ModelVersion: registered_model=<RegisteredModel: " \
                                  "name='myname'>, version=4>"
Exemple #13
0
 def test_string_repr(self):
     registered_model = RegisteredModel(name="myname")
     assert str(registered_model) == "<RegisteredModel: name='myname'>"