Esempio n. 1
0
    def test_extract_index_meta(self):
        self.maxDiff = None
        dt = met.get_datetime_now()
        base_meta = {
            "created_at": dt,
            "model": "docfreq",
            "series": "pga-2018",
            "uuid": "12345678-9abc-def0-1234-56789abcdef0",
            "version": [1, 0, 2],
            "parent": "f64bacd4-67fb-4c64-8382-399a8e7db52a",
            "dependencies": ["1e3da42a-28b6-4b33-94a2-a5671f4102f4"],
            "description": "model_description",
            "license": "MIT",
        }
        extra_meta = {
            "code": "model_code %s",
            "datasets": [["any", "https://any"]],
            "description": "override",
            "references": [["any", "ref"]],
            "tags": ["one", "two"],
            "extra": {
                "feature": "value"
            },
        }

        def route(url):
            self.assertEqual("https://xxx", url)
            return b"content"

        met.requests = FakeRequests(route)
        model_meta = met.extract_model_meta(base_meta, extra_meta,
                                            "https://xxx")
        self.assertIsInstance(model_meta, dict)
        self.assertGreater(len(met.format_datetime(dt)), 0)
        self.assertDictEqual(
            model_meta, {
                "default": {
                    "default": "12345678-9abc-def0-1234-56789abcdef0",
                    "description": "model_description",
                    "code": "model_code %s"
                },
                "model": {
                    "created_at": met.format_datetime(dt),
                    "code": "model_code %s",
                    "description": "model_description",
                    "dependencies": ["1e3da42a-28b6-4b33-94a2-a5671f4102f4"],
                    "license": "MIT",
                    "parent": "f64bacd4-67fb-4c64-8382-399a8e7db52a",
                    "datasets": [["any", "https://any"]],
                    "references": [["any", "ref"]],
                    "size": "7 Bytes",
                    "series": "pga-2018",
                    "url": "https://xxx",
                    "tags": ["one", "two"],
                    "version": [1, 0, 2],
                    "extra": {
                        "feature": "value"
                    }
                }
            })
Esempio n. 2
0
 def __str__(self):
     """Format model description as a string."""
     try:
         dump = self.dump()
     except NotImplementedError:
         dump = ""
     except AttributeError:
         return repr(self)
     if dump:
         dump = "\n" + dump
     meta = deepcopy(self.meta)
     meta["created_at"] = format_datetime(meta["created_at"])
     meta["size"] = humanize.naturalsize(self.size)
     try:
         meta["environment"]["packages"] = \
             " ".join("%s==%s" % tuple(p) for p in self.environment["packages"])
     except KeyError:
         pass
     return "%s%s" % (pformat(meta, width=1024), dump)