def save(self, save_path: Path): """ Copies all internal data to an MLSchema, which it then uses to validate, and saves to disk. Returns True on success, or False and an array of errors if it fails schema validation. """ errors = self.validate() file_write_success = False if len(errors) == 0: file_path = save_path / \ (self.get_schema_name() + "-" + datetime.datetime.now().isoformat() + ".yaml") IO.write_content_to_path(file_path, self.dict_without_internal_variables()) # Expecting the file system to throw an error if something went wrong above. # By this point, the file system has written and so recording the filename. self.__file_path = file_path file_write_success = True return (file_write_success, errors)
def test_load_file_from_disk(self): all_objects = [] MLSchema.populate_registry() all_objects.append( IO.get_content_from_path(Path('tests/data/0/0/1/datapath.yaml'))) self.assertTrue(len(all_objects) == 1)
def test_save_file(self, mock_write_text): mock_write_text.return_value = True self.assertTrue(IO.write_content_to_path("A_PATH", "A_STRING"))
def create_object_from_file(file_path: str): """ Creates an MLObject based on a file path. File must be valid yaml.""" ml_content_from_disk = IO.get_content_from_path(file_path) return MLObject.create_object_from_string(ml_content_from_disk)