def test_dump_model(): '''Tests dump model utility, including generated artifacts''' def predict(x: int) -> int: return user_function(x) model = Model(predict=predict) model_name = 'my-model' reqs = Requirements(reqs=['wronglib'], req_map={'wronglib': 'scipy'}, packages=[_USER_PACKAGE_DIR]) with _dump_model(model, model_name, reqs) as dump_dir: assert set(listdir(dump_dir)) == set(_REQ_FILES) metadata = load_artifact(dump_dir, 'metadata.json', module=json, mode='r') schema = _load_schema(SCHEMA_VERSION) validate(metadata, schema) # test that a user-provided library was included and correctly mapped assert 'scipy' in { r['name'] for r in metadata['runtime']['dependencies']['pip']['requirements'] } # test that custom package was bundled _verify_files( dump_dir, ('scripts/user_provided/user_package/user_package_module.py', 'scripts/user_provided/user_package/__init__.py', 'scripts/user_provided/user_module.py'))
def test_license(): '''Tests that a user-provided license is correctly pushed''' with _patch_auth(): license_str = load_artifact(_FAKE_LICENSE, module=json, mode='r')['license'] extra_headers = {'X-Test-License': license_str} opts = Options(license=_FAKE_LICENSE) _push_dummy_model(extra_headers, options=opts) opts = Options(license=license_str) _push_dummy_model(extra_headers, options=opts)
def _configuration(**kwargs): '''Optionally updates and returns the config dict''' makedirs(_CONFIG_DIR, exist_ok=True) lock = FileLock(_LOCK_PATH) with lock: config = dict() if not isfile(_CONFIG_PATH) else load_artifact( _CONFIG_PATH, module=json, mode='r') config.update(kwargs) config['version'] = acumos.__version__ with lock: dump_artifact(_CONFIG_PATH, data=config, module=json, mode='w') return config