def upload(module_cls: str, model: Optional[Models] = None) -> None: try: _, cls = import_cls(module_cls) except ImportClsException as e: raise UploadException(e) path = inspect.getfile(cls) with open(path, "r") as source_file: source = source_file.read() try: check_object_type(source, cls.__name__) except SourceException as e: print(e) raise UploadException( f"There is something wrong with source code of '{cls.__name__}'." ) assert issubclass(cls, Generic) obj_type = ObjectType(id=cls.__name__, source=source, desc=cls.description()) if model: obj_type.model = model.metamodel() storage.put_model(model) print(f"Storing '{obj_type.id}'...") storage.update_object_type(obj_type)
def upload(module_cls: str) -> None: try: _, cls = import_cls(module_cls) except ImportClsException as e: raise UploadException(e) if not issubclass(cls, Service): print("Not subclass of Service!") return upload_cls(cls)
def test_import_cls_valid(): mod, cls = hlp.import_cls("datetime/timedelta") assert mod == datetime assert cls == datetime.timedelta
def test_import_cls_invalid(): with pytest.raises(hlp.ImportClsException): mod, cls = hlp.import_cls("Generic")
def test_import_cls_non_existing(): with pytest.raises(hlp.ImportClsException): mod, cls = hlp.import_cls("nonsense/NonSense")