Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_new_class(self):
class FooObject(RESTObject):
f = RESTProperty(float)
i = RESTProperty(int)
s = RESTProperty(str)
e = RESTProperty(enum("a", "b"))
f = FooObject(f="6.0", i="3", s="hello!")
self.assertEqual(f.f, 6.0)
self.assertEqual(f.i, 3)
self.assertEqual(f.s, "hello!")
with self.assertRaises(AttributeError):
f.e
self.assertEqual(f["f"], 6.0)
self.assertEqual(f["i"], 3)
self.assertEqual(f["s"], "hello!")
with self.assertRaises(KeyError):
def test_new_class(self):
class FooObject(RESTObject):
f = RESTProperty(float)
i = RESTProperty(int)
s = RESTProperty(str)
e = RESTProperty(enum("a", "b"))
f = FooObject(f="6.0", i="3", s="hello!")
self.assertEqual(f.f, 6.0)
self.assertEqual(f.i, 3)
self.assertEqual(f.s, "hello!")
with self.assertRaises(AttributeError):
f.e
self.assertEqual(f["f"], 6.0)
self.assertEqual(f["i"], 3)
self.assertEqual(f["s"], "hello!")
required_files : str
The local file path to the directory containing the
required files.
required_packages : str
The local file path to the directory containing the
required packages.
"""
src_path = RESTProperty(str)
required_files = RESTProperty(list)
required_packages = RESTProperty(list)
required_packages_dst_path = RESTProperty(str)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.type = "model"
def __eq__(self, other):
return (
super().__eq__(other)
and self.required_files == other.required_files
and self.required_packages == other.required_packages
)
class AliasEndpoint(Endpoint):
"""Represents an alias Endpoint.
required_files : str
The local file path to the directory containing the
required files.
required_packages : str
The local file path to the directory containing the
required packages.
"""
src_path = RESTProperty(str)
required_files = RESTProperty(list)
required_packages = RESTProperty(list)
required_packages_dst_path = RESTProperty(str)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.type = "model"
def __eq__(self, other):
return (
super().__eq__(other)
and self.required_files == other.required_files
and self.required_packages == other.required_packages
)
class AliasEndpoint(Endpoint):
"""Represents an alias Endpoint.
dependencies: list
A list of endpoints that this endpoint depends on.
methods : list
???
"""
name = RESTProperty(str)
type = RESTProperty(str)
version = RESTProperty(int)
description = RESTProperty(str)
dependencies = RESTProperty(list)
methods = RESTProperty(list)
creation_time = RESTProperty(datetime, from_epoch, to_epoch)
last_modified_time = RESTProperty(datetime, from_epoch, to_epoch)
evaluator = RESTProperty(str)
schema_version = RESTProperty(int)
schema = RESTProperty(str)
def __new__(cls, **kwargs):
"""Dispatch to the appropriate class."""
cls = {"alias": AliasEndpoint, "model": ModelEndpoint,}[kwargs["type"]]
"""return object.__new__(cls, **kwargs)"""
""" modified for Python 3"""
return object.__new__(cls)
def __eq__(self, other):
return (
self.name == other.name
and self.type == other.type
and self.version == other.version
and self.description == other.description
type : str
The type of endpoint. The types include "alias", "model".
version : int
The version of this endpoint. Initial versions have version on 1. New
versions increment this by 1.
description : str
A human-readable description of the endpoint.
dependencies: list
A list of endpoints that this endpoint depends on.
methods : list
???
"""
name = RESTProperty(str)
type = RESTProperty(str)
version = RESTProperty(int)
description = RESTProperty(str)
dependencies = RESTProperty(list)
methods = RESTProperty(list)
creation_time = RESTProperty(datetime, from_epoch, to_epoch)
last_modified_time = RESTProperty(datetime, from_epoch, to_epoch)
evaluator = RESTProperty(str)
schema_version = RESTProperty(int)
schema = RESTProperty(str)
def __new__(cls, **kwargs):
"""Dispatch to the appropriate class."""
cls = {"alias": AliasEndpoint, "model": ModelEndpoint,}[kwargs["type"]]
"""return object.__new__(cls, **kwargs)"""
""" modified for Python 3"""
return object.__new__(cls)
The local file path to the source of this object.
required_files : str
The local file path to the directory containing the
required files.
required_packages : str
The local file path to the directory containing the
required packages.
"""
src_path = RESTProperty(str)
required_files = RESTProperty(list)
required_packages = RESTProperty(list)
required_packages_dst_path = RESTProperty(str)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.type = "model"
def __eq__(self, other):
return (
super().__eq__(other)
and self.required_files == other.required_files
and self.required_packages == other.required_packages
)
The type of endpoint. The types include "alias", "model".
version : int
The version of this endpoint. Initial versions have version on 1. New
versions increment this by 1.
description : str
A human-readable description of the endpoint.
dependencies: list
A list of endpoints that this endpoint depends on.
methods : list
???
"""
name = RESTProperty(str)
type = RESTProperty(str)
version = RESTProperty(int)
description = RESTProperty(str)
dependencies = RESTProperty(list)
methods = RESTProperty(list)
creation_time = RESTProperty(datetime, from_epoch, to_epoch)
last_modified_time = RESTProperty(datetime, from_epoch, to_epoch)
evaluator = RESTProperty(str)
schema_version = RESTProperty(int)
schema = RESTProperty(str)
def __new__(cls, **kwargs):
"""Dispatch to the appropriate class."""
cls = {"alias": AliasEndpoint, "model": ModelEndpoint,}[kwargs["type"]]
"""return object.__new__(cls, **kwargs)"""
""" modified for Python 3"""
return object.__new__(cls)
version : int
The version of this endpoint. Initial versions have version on 1. New
versions increment this by 1.
description : str
A human-readable description of the endpoint.
dependencies: list
A list of endpoints that this endpoint depends on.
methods : list
???
"""
name = RESTProperty(str)
type = RESTProperty(str)
version = RESTProperty(int)
description = RESTProperty(str)
dependencies = RESTProperty(list)
methods = RESTProperty(list)
creation_time = RESTProperty(datetime, from_epoch, to_epoch)
last_modified_time = RESTProperty(datetime, from_epoch, to_epoch)
evaluator = RESTProperty(str)
schema_version = RESTProperty(int)
schema = RESTProperty(str)
def __new__(cls, **kwargs):
"""Dispatch to the appropriate class."""
cls = {"alias": AliasEndpoint, "model": ModelEndpoint,}[kwargs["type"]]
"""return object.__new__(cls, **kwargs)"""
""" modified for Python 3"""
return object.__new__(cls)
def __eq__(self, other):
A list of endpoints that this endpoint depends on.
methods : list
???
"""
name = RESTProperty(str)
type = RESTProperty(str)
version = RESTProperty(int)
description = RESTProperty(str)
dependencies = RESTProperty(list)
methods = RESTProperty(list)
creation_time = RESTProperty(datetime, from_epoch, to_epoch)
last_modified_time = RESTProperty(datetime, from_epoch, to_epoch)
evaluator = RESTProperty(str)
schema_version = RESTProperty(int)
schema = RESTProperty(str)
def __new__(cls, **kwargs):
"""Dispatch to the appropriate class."""
cls = {"alias": AliasEndpoint, "model": ModelEndpoint,}[kwargs["type"]]
"""return object.__new__(cls, **kwargs)"""
""" modified for Python 3"""
return object.__new__(cls)
def __eq__(self, other):
return (
self.name == other.name
and self.type == other.type
and self.version == other.version
and self.description == other.description
and self.dependencies == other.dependencies