def test_tojson_with_profiles_hooks_metadata( self, convert_yaml_schemas_to_json, load_schema ): t = Transformation("test", namespace="pegasus") t.add_sites( TransformationSite("local", "/pfn", True).add_env(JAVA_HOME="/java/home") ) t.add_requirement("required") t.add_env(JAVA_HOME="/java/home") t.add_shell_hook(EventType.START, "/bin/echo hi") t.add_metadata(key="value") result = json.loads(json.dumps(t, cls=_CustomEncoder)) expected = { "name": "test", "namespace": "pegasus", "requires": ["required"], "sites": [ { "name": "local", "pfn": "/pfn", "type": "stageable", "profiles": {"env": {"JAVA_HOME": "/java/home"}}, } ], "metadata": {"key": "value"}, "profiles": {Namespace.ENV.value: {"JAVA_HOME": "/java/home"}}, "hooks": {"shell": [{"_on": EventType.START.value, "cmd": "/bin/echo hi"}]}, } transformation_schema = load_schema("tc-5.0.json")["$defs"]["transformation"] validate(instance=result, schema=transformation_schema) assert result == expected
def test_add_invalid_requirement_as_str(self, namespace, name, version, bad_field): t = Transformation("test") with pytest.raises(ValueError) as e: t.add_requirement(name, namespace, version) assert "invalid {bad_field}".format(bad_field=bad_field) in str(e)
def test_tojson_without_profiles_hooks_metadata( self, convert_yaml_schemas_to_json, load_schema ): t = Transformation( "test", namespace="pegasus", site="local", pfn="/pfn", is_stageable=True, bypass_staging=True, checksum={"sha256": "abc123"}, ) t.add_requirement("required") result = json.loads(json.dumps(t, cls=_CustomEncoder)) expected = { "name": "test", "namespace": "pegasus", "checksum": {"sha256": "abc123"}, "requires": ["required"], "sites": [ {"name": "local", "pfn": "/pfn", "type": "stageable", "bypass": True} ], } transformation_schema = load_schema("tc-5.0.json")["$defs"]["transformation"] validate(instance=result, schema=transformation_schema) assert result == expected
def test_add_duplicate_requirement(self, transformation): t = Transformation("test") t.add_requirement(transformation) with pytest.raises(DuplicateError) as e: t.add_requirement(transformation) assert "transformation: required" in str(e)
def test_tojson_without_profiles_hooks_metadata( self, convert_yaml_schemas_to_json, load_schema): t = Transformation("test", namespace="pegasus") t.add_sites(TransformationSite("local", "/pfn", True)) t.add_requirement("required") result = json.loads(json.dumps(t, cls=_CustomEncoder)) expected = { "name": "test", "namespace": "pegasus", "requires": ["required"], "sites": [{ "name": "local", "pfn": "/pfn", "type": "stageable" }], } transformation_schema = load_schema( "tc-5.0.json")["$defs"]["transformation"] validate(instance=result, schema=transformation_schema) assert result == expected
def test_add_invalid_requirement(self): t = Transformation("test") with pytest.raises(TypeError) as e: t.add_requirement(1) assert "invalid required_transformation: {tr}".format(tr=1) in str(e)
def test_add_requirement_as_transformation_object(self, transformation, expected): t = Transformation("test") t.add_requirement(transformation) assert expected in t.requires
def test_add_requirement_as_str(self, namespace, name, version, expected): t = Transformation("test") t.add_requirement(name, namespace=namespace, version=version) assert expected in t.requires