class GafferPredicatesTest(unittest.TestCase): examples = [ [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.AgeOff", "ageOffTime" : 100000 } ''', g.AgeOff( age_off_time=100000 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.And", "predicates" : [ { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 3 }, { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 0 } ] } ''', g.And( predicates=[ g.IsLessThan( value=3, or_equal_to=False ), g.IsMoreThan( value=0, or_equal_to=False ) ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.And", "predicates" : [ { "class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 2 }, "selection" : [ 0 ] }, { "class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 5 }, "selection" : [ 1 ] } ] } ''', g.And( predicates=[ g.NestedPredicate( selection=[ 0 ], predicate=g.IsLessThan( value=2, or_equal_to=False ) ), g.NestedPredicate( selection=[ 1 ], predicate=g.IsMoreThan( value=5, or_equal_to=False ) ) ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.AreIn", "values" : [ 1, 2, 3 ] } ''', g.AreIn( values=[ 1, 2, 3 ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.CollectionContains", "value" : 1 } ''', g.CollectionContains( value=1 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Exists" } ''', g.Exists() ], [ ''' { "class" : "uk.gov.gchq.gaffer.sketches.clearspring.cardinality.predicate.HyperLogLogPlusIsLessThan", "orEqualTo" : false, "value" : 2 } ''', g.HyperLogLogPlusIsLessThan( value=2, or_equal_to=False ) ], [ ''' { "class" : "uk.gov.gchq.gaffer.sketches.datasketches.cardinality.predicate.HllSketchIsLessThan", "orEqualTo" : false, "value" : 2 } ''', g.HllSketchIsLessThan( value=2, or_equal_to=False ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsA", "type" : "java.lang.String" } ''', g.IsA( type="java.lang.String" ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsEqual", "value" : 5 } ''', g.IsEqual( value=5 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsFalse" } ''', g.IsFalse() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsIn", "values" : [ 5, { "java.lang.Long" : 5 }, "5", { "java.lang.Character" : "5" } ] } ''', g.IsIn( values=[ 5, {'java.lang.Long': 5}, "5", {'java.lang.Character': '5'} ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 5 } ''', g.IsLessThan( value=5, or_equal_to=False ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : true, "value" : 5 } ''', g.IsLessThan( value=5, or_equal_to=True ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 5 } ''', g.IsMoreThan( value=5, or_equal_to=False ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsShorterThan", "maxLength" : 4, "orEqualTo" : false } ''', g.IsShorterThan( or_equal_to=False, max_length=4 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsTrue" } ''', g.IsTrue() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsXLessThanY" } ''', g.IsXLessThanY() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsXMoreThanY" } ''', g.IsXMoreThanY() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.MapContains", "key" : "a" } ''', g.MapContains( key="a" ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.MapContainsPredicate", "keyPredicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.Regex", "value" : { "java.util.regex.Pattern" : "a.*" } } } ''', g.MapContainsPredicate( key_predicate=g.Regex( value={'java.util.regex.Pattern': 'a.*'} ) ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.MultiRegex", "value" : [ { "java.util.regex.Pattern" : "[a-d]" }, { "java.util.regex.Pattern" : "[0-4]" } ] } ''', g.MultiRegex( value=[ {'java.util.regex.Pattern': '[a-d]'}, {'java.util.regex.Pattern': '[0-4]'} ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Not", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.Exists" } } ''', g.Not( predicate=g.Exists() ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Or", "predicates" : [ { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 2 }, { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsEqual", "value" : 5 }, { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 10 } ] } ''', g.Or( predicates=[ g.IsLessThan( value=2, or_equal_to=False ), g.IsEqual( value=5 ), g.IsMoreThan( value=10, or_equal_to=False ) ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Or", "predicates" : [ { "class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 2 }, "selection" : [ 0 ] }, { "class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 10 }, "selection" : [ 1 ] } ] } ''', g.Or( predicates=[ g.NestedPredicate( selection=[ 0 ], predicate=g.IsLessThan( value=2, or_equal_to=False ) ), g.NestedPredicate( selection=[ 1 ], predicate=g.IsMoreThan( value=10, or_equal_to=False ) ) ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.predicate.PredicateMap", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : { "java.lang.Long" : 2 } }, "key" : "key1" } ''', g.PredicateMap( key="key1", predicate=g.IsMoreThan( or_equal_to=False, value={'java.lang.Long': 2} ) ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Regex", "value" : { "java.util.regex.Pattern" : "[a-d0-4]" } } ''', g.Regex( value={'java.util.regex.Pattern': '[a-d0-4]'} ) ], [ ''' { "class":"uk.gov.gchq.koryphe.impl.predicate.StringContains", "value":"someValue", "ignoreCase":false } ''', g.StringContains( value='someValue', ignore_case=False ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLongerThan", "minLength" : 10, "orEqualTo" : true } ''', g.IsLongerThan( min_length=10, or_equal_to=True ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.If", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.MapContains", "key" : "testKey" }, "then" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLongerThan", "minLength" : 20, "orEqualTo" : true }, "otherwise" : { "class" : "uk.gov.gchq.gaffer.sketches.clearspring.cardinality.predicate.HyperLogLogPlusIsLessThan", "value" : 10, "orEqualTo" : false } } ''', g.pred.If( predicate=g.MapContains( key='testKey' ), then=g.IsLongerThan( min_length=20, or_equal_to=True ), otherwise=g.HyperLogLogPlusIsLessThan( value=10, or_equal_to=False ) ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.If", "condition" : true, "then" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLongerThan", "minLength" : 20, "orEqualTo" : true } } ''', g.pred.If( condition=True, then=g.IsLongerThan( min_length=20, or_equal_to=True ) ) ], [ ''' {"class":"uk.gov.gchq.koryphe.impl.predicate.range.InTimeRangeDual","start":"2017/01/01","end":"2017/02/01","timeUnit":"MICROSECOND","startFullyContained":true,"endFullyContained":true,"timeZone":"Etc/GMT+0"} ''', g.InTimeRangeDual( start='2017/01/01', end='2017/02/01', time_unit='MICROSECOND', start_fully_contained=True, end_fully_contained=True, time_zone='Etc/GMT+0' ) ], [ ''' {"class":"uk.gov.gchq.koryphe.impl.predicate.range.InTimeRange","start":"2017/01/01","end":"2017/02/01","timeUnit":"MICROSECOND","timeZone":"Etc/GMT+0"} ''', g.InTimeRange( start='2017/01/01', end='2017/02/01', time_unit='MICROSECOND', time_zone='Etc/GMT+0' ) ], [ ''' { "class": "uk.gov.gchq.gaffer.data.element.comparison.ElementJoinComparator" } ''', g.ElementJoinComparator() ], [ ''' { "class": "uk.gov.gchq.gaffer.data.element.comparison.ElementJoinComparator", "groupByProperties": [ "test1", "test2" ] } ''', g.ElementJoinComparator(group_by_properties=["test1", "test2"]) ], [ ''' { "class": "uk.gov.gchq.gaffer.access.predicate.user.DefaultUserPredicate", "auths": [ "a", "test2" ], "creatingUserId": "user1" } ''', g.DefaultUserPredicate(auths=["a", "test2"], creating_user_id="user1") ], [ ''' { "class": "uk.gov.gchq.gaffer.access.predicate.user.UnrestrictedAccessUserPredicate" } ''', g.UnrestrictedAccessUserPredicate() ], [ ''' { "class": "uk.gov.gchq.gaffer.access.predicate.user.NoAccessUserPredicate" } ''', g.NoAccessUserPredicate() ], [ ''' { "class": "uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.user.NamedViewWriteUserPredicate", "auths": [ "a", "test2" ], "creatingUserId": "user1" } ''', g.NamedViewWriteUserPredicate(auths=["a", "test2"], creating_user_id="user1") ] ] def test_examples(self): for example in self.examples: self.assertEqual( g.json.loads(example[0]), example[1].to_json(), "json failed: \n" + example[0] ) g.JsonConverter.from_json(example[0], validate=True)
class GafferPredicatesTest(unittest.TestCase): examples = [ [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.AgeOff", "ageOffTime" : 100000 } ''', g.AgeOff( age_off_time=100000 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.And", "predicates" : [ { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 3 }, { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 0 } ] } ''', g.And( predicates=[ g.IsLessThan( value=3, or_equal_to=False ), g.IsMoreThan( value=0, or_equal_to=False ) ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.And", "predicates" : [ { "class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 2 }, "selection" : [ 0 ] }, { "class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 5 }, "selection" : [ 1 ] } ] } ''', g.And( predicates=[ g.NestedPredicate( selection=[ 0 ], predicate=g.IsLessThan( value=2, or_equal_to=False ) ), g.NestedPredicate( selection=[ 1 ], predicate=g.IsMoreThan( value=5, or_equal_to=False ) ) ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.AreIn", "values" : [ 1, 2, 3 ] } ''', g.AreIn( values=[ 1, 2, 3 ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.CollectionContains", "value" : 1 } ''', g.CollectionContains( value=1 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Exists" } ''', g.Exists() ], [ ''' { "class" : "uk.gov.gchq.gaffer.sketches.clearspring.cardinality.predicate.HyperLogLogPlusIsLessThan", "orEqualTo" : false, "value" : 2 } ''', g.HyperLogLogPlusIsLessThan( value=2, or_equal_to=False ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsA", "type" : "java.lang.String" } ''', g.IsA( type="java.lang.String" ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsEqual", "value" : 5 } ''', g.IsEqual( value=5 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsFalse" } ''', g.IsFalse() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsIn", "values" : [ 5, { "java.lang.Long" : 5 }, "5", { "java.lang.Character" : "5" } ] } ''', g.IsIn( values=[ 5, {'java.lang.Long': 5}, "5", {'java.lang.Character': '5'} ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 5 } ''', g.IsLessThan( value=5, or_equal_to=False ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : true, "value" : 5 } ''', g.IsLessThan( value=5, or_equal_to=True ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 5 } ''', g.IsMoreThan( value=5, or_equal_to=False ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsShorterThan", "maxLength" : 4, "orEqualTo" : false } ''', g.IsShorterThan( or_equal_to=False, max_length=4 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsTrue" } ''', g.IsTrue() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsXLessThanY" } ''', g.IsXLessThanY() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsXMoreThanY" } ''', g.IsXMoreThanY() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.MapContains", "key" : "a" } ''', g.MapContains( key="a" ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.MapContainsPredicate", "keyPredicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.Regex", "value" : { "java.util.regex.Pattern" : "a.*" } } } ''', g.MapContainsPredicate( key_predicate=g.Regex( value={'java.util.regex.Pattern': 'a.*'} ) ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.MultiRegex", "value" : [ { "java.util.regex.Pattern" : "[a-d]" }, { "java.util.regex.Pattern" : "[0-4]" } ] } ''', g.MultiRegex( value=[ {'java.util.regex.Pattern': '[a-d]'}, {'java.util.regex.Pattern': '[0-4]'} ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Not", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.Exists" } } ''', g.Not( predicate=g.Exists() ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Or", "predicates" : [ { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 2 }, { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsEqual", "value" : 5 }, { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 10 } ] } ''', g.Or( predicates=[ g.IsLessThan( value=2, or_equal_to=False ), g.IsEqual( value=5 ), g.IsMoreThan( value=10, or_equal_to=False ) ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Or", "predicates" : [ { "class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsLessThan", "orEqualTo" : false, "value" : 2 }, "selection" : [ 0 ] }, { "class" : "uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 10 }, "selection" : [ 1 ] } ] } ''', g.Or( predicates=[ g.NestedPredicate( selection=[ 0 ], predicate=g.IsLessThan( value=2, or_equal_to=False ) ), g.NestedPredicate( selection=[ 1 ], predicate=g.IsMoreThan( value=10, or_equal_to=False ) ) ] ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.predicate.PredicateMap", "predicate" : { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : { "java.lang.Long" : 2 } }, "key" : "key1" } ''', g.PredicateMap( key="key1", predicate=g.IsMoreThan( or_equal_to=False, value={'java.lang.Long': 2} ) ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.predicate.Regex", "value" : { "java.util.regex.Pattern" : "[a-d0-4]" } } ''', g.Regex( value={'java.util.regex.Pattern': '[a-d0-4]'} ) ], [ ''' { "class":"uk.gov.gchq.koryphe.impl.predicate.StringContains", "value":"someValue", "ignoreCase":false } ''', g.StringContains( value='someValue', ignore_case=False ) ] ] def test_examples(self): for example in self.examples: self.assertEqual( json.loads(example[0]), example[1].to_json(), "json failed: \n" + example[0] ) g.JsonConverter.from_json(example[0], validate=True)
class GafferFunctionsTest(unittest.TestCase): examples = [ [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Concat", "separator" : "\u0020" } ''', g.Concat( separator=" " ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Divide" } ''', g.Divide() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.DivideBy", "by" : 3 } ''', g.DivideBy( by=3 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ExtractKeys" } ''', g.ExtractKeys() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ExtractValue", "key" : "blueKey" } ''', g.ExtractValue( key="blueKey" ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ExtractValues" } ''', g.ExtractValues() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Identity" } ''', g.Identity() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.IsEmpty" } ''', g.IsEmpty() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.IterableConcat" } ''', g.IterableConcat() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Multiply" } ''', g.Multiply() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.MultiplyBy", "by" : 4 } ''', g.MultiplyBy( by=4 ) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Size" } ''', g.Size() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ToString" } ''', g.ToString() ], [ ''' { "class" : "uk.gov.gchq.gaffer.operation.function.ToEntityId" } ''', g.ToEntityId() ], [ ''' { "class" : "uk.gov.gchq.gaffer.operation.function.FromEntityId" } ''', g.FromEntityId() ], [ ''' { "class" : "uk.gov.gchq.gaffer.operation.function.ToElementId" } ''', g.ToElementId() ], [ ''' { "class" : "uk.gov.gchq.gaffer.operation.function.FromElementId" } ''', g.FromElementId() ], [ ''' { "class": "uk.gov.gchq.gaffer.types.function.ToTypeValue" } ''', g.ToTypeValue() ], [ ''' { "class": "uk.gov.gchq.gaffer.types.function.ToTypeSubTypeValue" } ''', g.ToTypeSubTypeValue() ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.generator.MapGenerator", "fields" : { "GROUP" : "Group Label", "VERTEX" : "Vertex Label", "SOURCE" : "Source Label", "count" : "Count Label" }, "constants" : { "A Constant" : "Some constant value" } } ''', g.MapGenerator( fields={ 'VERTEX': 'Vertex Label', 'count': 'Count Label', 'GROUP': 'Group Label', 'SOURCE': 'Source Label' }, constants={ 'A Constant': 'Some constant value' } ) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.generator.CsvGenerator", "fields" : { "GROUP" : "Group Label", "VERTEX" : "Vertex Label", "SOURCE" : "Source Label", "count" : "Count Label" }, "constants" : { "A Constant" : "Some constant value" }, "quoted" : true, "commaReplacement": "-" } ''', g.CsvGenerator( fields={ 'VERTEX': 'Vertex Label', 'count': 'Count Label', 'GROUP': 'Group Label', 'SOURCE': 'Source Label' }, constants={ 'A Constant': 'Some constant value' }, quoted=True, comma_replacement="-" ) ], [ ''' { "class": "uk.gov.gchq.gaffer.data.generator.JsonToElementGenerator" } ''', g.JsonToElementGenerator() ], [ ''' { "class" : "uk.gov.gchq.gaffer.types.function.FreqMapExtractor", "key" : "key1" } ''', g.FreqMapExtractor(key="key1") ], [ ''' { "class" : "uk.gov.gchq.koryphe.function.FunctionMap", "function" : { "class" : "uk.gov.gchq.koryphe.impl.function.MultiplyBy", "by" : 10 } } ''', g.FunctionMap( function=g.MultiplyBy(by=10) ) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdges" } ''', g.ExtractWalkEdges() ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop", "hop" : 2 } ''', g.ExtractWalkEdgesFromHop( hop=2 ) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities" } ''', g.ExtractWalkEntities() ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntitiesFromHop", "hop" : 1 } ''', g.ExtractWalkEntitiesFromHop( hop=1 ) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkVertex" } ''', g.ExtractWalkVertex() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Length", "maxLength" : 100000 } ''', g.Length( max_length=100000 ) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.element.function.ExtractId", "id" : "VERTEX" } ''', g.ExtractId( id='VERTEX' ) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.element.function.ExtractProperty", "name" : "countByVehicleType" } ''', g.ExtractProperty( name="countByVehicleType" ) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.element.function.ExtractGroup" } ''', g.ExtractGroup() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.CallMethod", "method": "someMethod" } ''', g.CallMethod(method="someMethod") ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.element.function.UnwrapEntityId" } ''', g.UnwrapEntityId() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.SetValue", "value": "value2" } ''', g.SetValue(value="value2") ], [ ''' { "class":"uk.gov.gchq.koryphe.impl.function.If", "predicate":{"class":"uk.gov.gchq.koryphe.impl.predicate.IsA","type":"java.lang.Integer"}, "then":{"class":"uk.gov.gchq.koryphe.impl.function.SetValue","value":"value2"}, "otherwise":{"class":"uk.gov.gchq.koryphe.impl.function.SetValue","value":"value3"} } ''', g.func.If( predicate=g.IsA(type="java.lang.Integer"), then=g.SetValue(value="value2"), otherwise=g.SetValue(value="value3") ) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToArray" } ''', g.func.ToArray() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToList" } ''', g.func.ToList() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToSet" } ''', g.func.ToSet() ], [ ''' { "class": "uk.gov.gchq.gaffer.types.function.ToFreqMap" } ''', g.func.ToFreqMap() ], [ ''' { "class": "uk.gov.gchq.gaffer.types.function.FreqMapPredicator", "predicate": { "class": "uk.gov.gchq.koryphe.impl.predicate.IsA", "type": "java.lang.String" } } ''', g.FreqMapPredicator( predicate=g.IsA( type="java.lang.String" ) ) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.IterableFilter", "predicate": { "class": "uk.gov.gchq.koryphe.impl.predicate.IsA", "type": "java.lang.String" } } ''', g.func.IterableFilter( predicate=g.IsA(type="java.lang.String") ) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapFilter" } ''', g.func.MapFilter() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapFilter", "keyPredicate": { "class":"uk.gov.gchq.koryphe.impl.predicate.StringContains", "value":"someValue", "ignoreCase":false } } ''', g.func.MapFilter( key_predicate=g.pred.StringContains( value="someValue", ignore_case=False ) ) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapFilter", "keyPredicate": { "class":"uk.gov.gchq.koryphe.impl.predicate.StringContains", "value":"someValue", "ignoreCase":false }, "valuePredicate": { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 0 } } ''', g.func.MapFilter( key_predicate=g.pred.StringContains( value="someValue", ignore_case=False ), value_predicate=g.pred.IsMoreThan( value=0, or_equal_to=False ) ) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapFilter", "keyValuePredicate": { "class": "uk.gov.gchq.koryphe.impl.predicate.AreEqual" } } ''', g.func.MapFilter( key_value_predicate=g.pred.AreEqual() ) ] ] def test_examples(self): for example in self.examples: self.assertEqual( json.loads(example[0]), example[1].to_json(), "json failed: \n" + example[0] + "\n" + g.JsonConverter.from_json(example[0]).to_code_string() ) g.JsonConverter.from_json(example[0], validate=True)
class GafferFunctionsTest(unittest.TestCase): examples = [ [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Concat", "separator" : "\u0020" } ''', g.Concat(separator=" ") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Divide" } ''', g.Divide() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.DivideBy", "by" : 3 } ''', g.DivideBy(by=3) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ExtractKeys" } ''', g.ExtractKeys() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.DictionaryLookup", "dictionary": { "One": 1, "Two": 2, "Three": 3 } } ''', g.DictionaryLookup(dictionary=dict(One=1, Two=2, Three=3)) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ExtractValue", "key" : "blueKey" } ''', g.ExtractValue(key="blueKey") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ExtractValues" } ''', g.ExtractValues() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Identity" } ''', g.Identity() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.IsEmpty" } ''', g.IsEmpty() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Longest" } ''', g.Longest() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.IterableLongest" } ''', g.IterableLongest() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.IterableFlatten", "operator": { "class": "uk.gov.gchq.koryphe.impl.binaryoperator.Max" } } ''', g.IterableFlatten(operator=g.bop.Max()) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.IterableConcat" } ''', g.IterableConcat() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Multiply" } ''', g.Multiply() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.MultiplyBy", "by" : 4 } ''', g.MultiplyBy(by=4) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.MultiplyLongBy", "by" : 4 } ''', g.MultiplyLongBy(by=4) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Size" } ''', g.Size() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ToString" } ''', g.ToString() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ToString", "charset": "UTF-16" } ''', g.ToString(charset="UTF-16") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringReplace", "searchString": "replaceme", "replacement": "withthis" } ''', g.StringReplace(search_string="replaceme", replacement="withthis") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringRegexReplace", "regex": "repl.*me", "replacement": "withthis" } ''', g.StringRegexReplace(regex="repl.*me", replacement="withthis") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringSplit", "delimiter": " " } ''', g.StringSplit(delimiter=" ") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringRegexSplit", "regex": "[ \\t]*" } ''', g.StringRegexSplit(regex="[ \t]*") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringJoin", "delimiter": " " } ''', g.StringJoin(delimiter=" ") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringTrim" } ''', g.StringTrim() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringAppend", "suffix": "test" } ''', g.StringAppend(suffix="test") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringPrepend", "prefix": "test" } ''', g.StringPrepend(prefix="test") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.StringTruncate", "length": 20, "ellipses": false } ''', g.StringTruncate(length=20, ellipses=False) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.ReverseString" } ''', g.ReverseString() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.DefaultIfNull", "defaultValue": "test" } ''', g.DefaultIfNull(default_value="test") ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.DefaultIfEmpty", "defaultValue": "test" } ''', g.DefaultIfEmpty(default_value="test") ], [ ''' { "class" : "uk.gov.gchq.gaffer.operation.function.ToEntityId" } ''', g.ToEntityId() ], [ ''' { "class" : "uk.gov.gchq.gaffer.operation.function.FromEntityId" } ''', g.FromEntityId() ], [ ''' { "class" : "uk.gov.gchq.gaffer.operation.function.ToElementId" } ''', g.ToElementId() ], [ ''' { "class" : "uk.gov.gchq.gaffer.operation.function.FromElementId" } ''', g.FromElementId() ], [ ''' { "class": "uk.gov.gchq.gaffer.types.function.ToTypeValue" } ''', g.ToTypeValue() ], [ ''' { "class": "uk.gov.gchq.gaffer.types.function.ToTypeSubTypeValue" } ''', g.ToTypeSubTypeValue() ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.generator.MapGenerator", "fields" : { "GROUP" : "Group Label", "VERTEX" : "Vertex Label", "SOURCE" : "Source Label", "count" : "Count Label" }, "constants" : { "A Constant" : "Some constant value" } } ''', g.MapGenerator(fields={ 'VERTEX': 'Vertex Label', 'count': 'Count Label', 'GROUP': 'Group Label', 'SOURCE': 'Source Label' }, constants={'A Constant': 'Some constant value'}) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.generator.CsvGenerator", "fields" : { "GROUP" : "Group Label", "VERTEX" : "Vertex Label", "SOURCE" : "Source Label", "count" : "Count Label" }, "constants" : { "A Constant" : "Some constant value" }, "quoted" : true, "commaReplacement": "-" } ''', g.CsvGenerator(fields={ 'VERTEX': 'Vertex Label', 'count': 'Count Label', 'GROUP': 'Group Label', 'SOURCE': 'Source Label' }, constants={'A Constant': 'Some constant value'}, quoted=True, comma_replacement="-") ], [ ''' { "class": "uk.gov.gchq.gaffer.data.generator.JsonToElementGenerator" } ''', g.JsonToElementGenerator() ], [ ''' { "class" : "uk.gov.gchq.gaffer.types.function.FreqMapExtractor", "key" : "key1" } ''', g.FreqMapExtractor(key="key1") ], [ ''' { "class" : "uk.gov.gchq.koryphe.function.FunctionMap", "function" : { "class" : "uk.gov.gchq.koryphe.impl.function.MultiplyBy", "by" : 10 } } ''', g.FunctionMap(function=g.MultiplyBy(by=10)) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdges" } ''', g.ExtractWalkEdges() ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop", "hop" : 2 } ''', g.ExtractWalkEdgesFromHop(hop=2) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities" } ''', g.ExtractWalkEntities() ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntitiesFromHop", "hop" : 1 } ''', g.ExtractWalkEntitiesFromHop(hop=1) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkVertex" } ''', g.ExtractWalkVertex() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.Length", "maxLength" : 100000 } ''', g.Length(max_length=100000) ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.element.function.ExtractId", "id" : "VERTEX" } ''', g.ExtractId(id='VERTEX') ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.element.function.ExtractProperty", "name" : "countByVehicleType" } ''', g.ExtractProperty(name="countByVehicleType") ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.element.function.ExtractGroup" } ''', g.ExtractGroup() ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.CallMethod", "method": "someMethod" } ''', g.CallMethod(method="someMethod") ], [ ''' { "class" : "uk.gov.gchq.gaffer.data.element.function.UnwrapEntityId" } ''', g.UnwrapEntityId() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.SetValue", "value": "value2" } ''', g.SetValue(value="value2") ], [ ''' { "class":"uk.gov.gchq.koryphe.impl.function.If", "predicate":{"class":"uk.gov.gchq.koryphe.impl.predicate.IsA","type":"java.lang.Integer"}, "then":{"class":"uk.gov.gchq.koryphe.impl.function.SetValue","value":"value2"}, "otherwise":{"class":"uk.gov.gchq.koryphe.impl.function.SetValue","value":"value3"} } ''', g.func.If(predicate=g.IsA(type="java.lang.Integer"), then=g.SetValue(value="value2"), otherwise=g.SetValue(value="value3")) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToArray" } ''', g.func.ToArray() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToList" } ''', g.func.ToList() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToSet" } ''', g.func.ToSet() ], [ ''' { "class": "uk.gov.gchq.gaffer.types.function.ToFreqMap" } ''', g.func.ToFreqMap() ], [ ''' { "class": "uk.gov.gchq.gaffer.types.function.FreqMapPredicator", "predicate": { "class": "uk.gov.gchq.koryphe.impl.predicate.IsA", "type": "java.lang.String" } } ''', g.FreqMapPredicator(predicate=g.IsA(type="java.lang.String")) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.IterableFilter", "predicate": { "class": "uk.gov.gchq.koryphe.impl.predicate.IsA", "type": "java.lang.String" } } ''', g.func.IterableFilter(predicate=g.IsA(type="java.lang.String")) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapFilter" } ''', g.func.MapFilter() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapFilter", "keyPredicate": { "class":"uk.gov.gchq.koryphe.impl.predicate.StringContains", "value":"someValue", "ignoreCase":false } } ''', g.func.MapFilter(key_predicate=g.pred.StringContains( value="someValue", ignore_case=False)) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.FirstValid", "predicate": { "class":"uk.gov.gchq.koryphe.impl.predicate.StringContains", "value":"someValue", "ignoreCase":false } } ''', g.func.FirstValid(predicate=g.pred.StringContains( value="someValue", ignore_case=False)) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.FirstValid", "predicate": { "class":"uk.gov.gchq.koryphe.impl.predicate.StringContains", "value":"someValue", "ignoreCase":false } } ''', g.func.FirstValid( predicate={ "class": "uk.gov.gchq.koryphe.impl.predicate.StringContains", "value": "someValue", "ignoreCase": False }) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapFilter", "keyPredicate": { "class":"uk.gov.gchq.koryphe.impl.predicate.StringContains", "value":"someValue", "ignoreCase":false }, "valuePredicate": { "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan", "orEqualTo" : false, "value" : 0 } } ''', g.func.MapFilter( key_predicate=g.pred.StringContains(value="someValue", ignore_case=False), value_predicate=g.pred.IsMoreThan(value=0, or_equal_to=False)) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapFilter", "keyValuePredicate": { "class": "uk.gov.gchq.koryphe.impl.predicate.AreEqual" } } ''', g.func.MapFilter(key_value_predicate=g.pred.AreEqual()) ], [ ''' { "class" : "uk.gov.gchq.koryphe.impl.function.CreateObject", "objectClass" : "java.lang.Long" } ''', g.func.CreateObject(object_class="java.lang.Long") ], [ ''' { "class": "uk.gov.gchq.gaffer.time.function.MaskTimestampSetByTimeRange", "startTime": { "java.lang.Long": 15300000000000 }, "endTime": { "java.lang.Long": 15400000000000 } } ''', g.func.MaskTimestampSetByTimeRange( start_time=g.long(15300000000000), end_time=g.long(15400000000000)) ], [ ''' { "class": "uk.gov.gchq.gaffer.time.function.MaskTimestampSetByTimeRange", "startTime": { "java.lang.Long": 15300000000000 }, "endTime": { "java.lang.Long": 15400000000000 }, "timeUnit": "SECOND" } ''', g.func.MaskTimestampSetByTimeRange( start_time=g.long(15300000000000), end_time=g.long(15400000000000), time_unit=g.TimeUnit.SECOND) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.Base64Decode" } ''', g.func.Base64Decode() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.CsvLinesToMaps", "delimiter": "|", "header": ["my", "csv", "file"], "firstRow": 1, "quoted": true, "quoteChar": "'" } ''', g.func.CsvLinesToMaps(delimiter='|', header=["my", "csv", "file"], first_row=1, quoted=True, quote_char='\'') ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.CsvToMaps", "delimiter": "|", "header": ["my", "csv", "file"], "firstRow": 1, "quoted": true, "quoteChar": "'" } ''', g.func.CsvToMaps(delimiter='|', header=["my", "csv", "file"], first_row=1, quoted=True, quote_char='\'') ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.CurrentDate" } ''', g.func.CurrentDate() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.CurrentTime" } ''', g.func.CurrentTime() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.DeserialiseJson", "outputClass": "uk.gov.gchq.gaffer.data.element.Edge" } ''', g.func.DeserialiseJson(output_class=g.Edge.CLASS) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.DeserialiseJson" } ''', g.func.DeserialiseJson() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.DeserialiseXml" } ''', g.func.DeserialiseXml() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.Gunzip" } ''', g.func.Gunzip() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.Increment", "increment": { "java.lang.Long": 1000000 } } ''', g.Increment(increment=g.long(1000000)) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.MapToTuple" } ''', g.func.MapToTuple() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ParseDate", "timeZone": "BST", "format": "DD-MM-YYYY" } ''', g.func.ParseDate(time_zone="BST", format="DD-MM-YYYY") ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ParseTime", "timeZone": "EST", "format": "MM-DD-YYYY HH:mm:ss.SSS", "timeUnit": "MICROSECOND" } ''', g.func.ParseTime(time_zone="EST", format="MM-DD-YYYY HH:mm:ss.SSS", time_unit=g.TimeUnit.MICROSECOND) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToDateString", "format": "YYYY-MMM-dd" } ''', g.func.ToDateString(format="YYYY-MMM-dd") ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToBytes", "charset": "UTF-8" } ''', g.func.ToBytes(charset="UTF-8") ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ApplyBiFunction", "function": { "class": "uk.gov.gchq.koryphe.impl.binaryoperator.Sum" } } ''', g.func.ApplyBiFunction(function=g.gaffer_binaryoperators.Sum()) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ApplyBiFunction", "function": { "class": "uk.gov.gchq.koryphe.impl.binaryoperator.Product" } } ''', g.func.ApplyBiFunction( function={ "class": "uk.gov.gchq.koryphe.impl.binaryoperator.Product" }) ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.ToTuple" } ''', g.func.ToTuple() ], [ ''' { "class": "uk.gov.gchq.gaffer.data.element.function.ToPropertiesTuple" } ''', g.func.ToPropertiesTuple() ], [ ''' { "class": "uk.gov.gchq.gaffer.data.element.function.ToElementTuple" } ''', g.func.ToElementTuple() ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.FunctionChain", "functions": [ { "class": "uk.gov.gchq.koryphe.impl.function.Base64Decode" }, { "class": "uk.gov.gchq.koryphe.impl.function.CsvLinesToMaps", "delimiter": "|", "quoted": true } ] } ''', g.FunctionChain(functions=[ g.Base64Decode(), g.CsvLinesToMaps(delimiter="|", quoted=True) ]) ], [ ''' { "class":"uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction", "selection":[0], "function": { "class": "uk.gov.gchq.gaffer.operation.function.ToEntityId" }, "projection": [1] } ''', g.TupleAdaptedFunction(selection=[0], function=g.ToEntityId(), projection=[1]) ], [ ''' { "class":"uk.gov.gchq.koryphe.impl.function.FunctionChain", "functions": [ { "class":"uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction", "selection":[0], "function": { "class": "uk.gov.gchq.koryphe.impl.function.ToUpperCase" }, "projection": [1] }, { "class":"uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction", "selection": [1], "function": { "class": "uk.gov.gchq.koryphe.impl.function.ToSet" }, "projection": [2] } ] } ''', g.FunctionChain(functions=[ g.TupleAdaptedFunction( selection=[0], function=g.ToUpperCase(), projection=[1]), g.TupleAdaptedFunction(selection=[1], function=g.gaffer_functions.ToSet(), projection=[2]) ]) ], [ ''' { "class": "uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunctionComposite", "functions": [ { "selection": [ "something" ], "function": { "class":"uk.gov.gchq.koryphe.impl.function.ToUpperCase" }, "projection": [1] } ] } ''', g.TupleAdaptedFunctionComposite(functions=[ g.FunctionContext(selection=["something"], function=g.ToUpperCase(), projection=[1]) ]), ], [ ''' { "class": "uk.gov.gchq.koryphe.impl.function.FunctionChain", "functions": [ { "class": "uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunctionComposite", "functions": [ { "selection": [0], "function": { "class":"uk.gov.gchq.koryphe.impl.function.ToUpperCase" }, "projection": [1] } ] }, { "class": "uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunctionComposite", "functions": [ { "selection": [1], "function": { "class":"uk.gov.gchq.koryphe.impl.function.ToSet" }, "projection": [2] } ] } ] } ''', g.FunctionChain(functions=[ g.TupleAdaptedFunctionComposite(functions=[ g.FunctionContext(selection=[0], function=g.ToUpperCase(), projection=[1]) ]), g.TupleAdaptedFunctionComposite(functions=[ g.FunctionContext(selection=[1], function=g.gaffer_functions.ToSet(), projection=[2]) ]) ]) ] ] def test_examples(self): for example in self.examples: self.assertEqual( json.loads(example[0]), example[1].to_json(), "json failed: \n" + example[0] + "\n" + g.JsonConverter.from_json(example[0]).to_code_string()) g.JsonConverter.from_json(example[0], validate=True)