Пример #1
0
 def test_resolve_join_with_separator(self):
     template = parse_template({
         "{join}": ["foo", "{.foo}"],
         "{separator}": ", "
     })
     actual = resolve(template, data_0, data_index)
     expected = "foo, 1, 2, 3"
     self.assertEqual(actual, expected)
Пример #2
0
 def test_resolve_if2(self):
     template = parse_template({
         "{if}": "{.nonExistingField}",
         "{then}": "then"
     })
     actual = resolve(template, data_0, data_index)
     expected = None
     self.assertEqual(actual, expected)
Пример #3
0
 def test_resolve_capitalize2(self):
     input = parse_template({
         "{list}": ["foo", ["foo", "foo", "bar"], "bar"],
         "{transform}": ["capitalize"]
     })
     actual = resolve(input, data_0, data_index)
     expected = ["Foo", ["Foo", "Foo", "Bar"], "Bar"]
     self.assertEqual(actual, expected)
Пример #4
0
 def test_resolve_flatten2(self):
     template = parse_template({
         "{flatten_distinct}":
         ["foo", "bar", ["baz", ["fizz", "foo", "buzz"], "bar"]]
     })
     actual = resolve(template, data_0, data_index)
     expected = ["foo", "bar", "baz", "fizz", "buzz"]
     self.assertEqual(actual, expected)
Пример #5
0
 def test_resolve_flatten_capitalize(self):
     template = parse_template({
         "{list}": ["foo", ["foo", "foo", "bar"], "bar"],
         "{transform}": ["capitalize", "flatten"]
     })
     actual = resolve(template, data_0, data_index)
     expected = ["Foo", "Foo", "Foo", "Bar", "Bar"]
     self.assertEqual(actual, expected)
Пример #6
0
 def test_resolve_non_existing_field_in_join_without_none_template(self):
     template = parse_template({
         "{join}": ["The species is ", "{.nonExisitngField}"],
         "{accept_none}":
         False
     })
     actual = resolve(template, data_0, data_index)
     expected = None
     self.assertEqual(actual, expected)
Пример #7
0
 def test_resolve_if5(self):
     template = parse_template({
         "{if}": "{.falseField}",
         "{then}": "bar",
         "{else}": "else"
     })
     actual = resolve(template, data_0, data_index)
     expected = "else"
     self.assertEqual(actual, expected)
Пример #8
0
 def test_resolve_if4(self):
     input = parse_template({
         "{if}": "{.nonExistingField}",
         "{then}": "bar",
         "{else}": "else"
     })
     actual = resolve(input, data_0, data_index)
     expected = "else"
     self.assertEqual(actual, expected)
 def test_resolve_replace_with(self):
     template = parse_template({
         "{replace}": {
             "possible_terms":
             ["geno", "genotyping study", "Gnomic", "genotyping"]
         },
         "{with}": {
             "replaced_by": "Genotyping Study"
         }
     })
     actual = resolve(template, data_0, data_index)
     expected = "Genotyping Study"
     self.assertEqual(actual, expected)
Пример #10
0
 def test_resolve_merge_value(self):
     template = parse_template({
         "{merge}": {
             "foo": "bar",
             "baz": "fizz"
         },
         "{with}": {
             "foo": "fuzz"
         }
     })
     actual = resolve(template, None, None)
     expected = {"foo": "fuzz", "baz": "fizz"}
     self.assertEqual(actual, expected)
Пример #11
0
 def test_resolve_merge_resolved(self):
     template = parse_template({
         "{merge}": {
             "foo": "{.foo}",
             "baz": "{.species}"
         },
         "{with}": {
             "foo": "{.genus}"
         }
     })
     actual = resolve(template, data_0, data_index)
     expected = {"foo": "Zea", "baz": "mays"}
     self.assertEqual(actual, expected)
Пример #12
0
 def test_resolve_map_empty(self):
     template = parse_template({
         "studies": {
             "{map}": "{.nonExistingField}",
             "{to}": {
                 "id": "{.}"
             }
         },
         "foo": "bar"
     })
     actual = resolve(template, data_0, data_index)
     expected = {"foo": "bar"}
     self.assertEqual(actual, expected)
 def test_get_required_entities(self):
     input = parse_template([{
         "source-entity": "something",
         "document-transform": {
             "foo": "bar",
             "baz": {
                 "{join}": [
                     "{.entityDbIds => .objectDbId => .name}",
                     "{.dataDbIds => .desc}"
                 ]
             },
             "fizz": "{.buzz.entityDbIds => .objectDbId => .name}"
         }
     }, {
         "source-entity": "something_else",
         "document-transform": {
             "fizz": "{.buzz.entityDbIds => .objectDbId => .name}"
         }
     }])
     expected = {'entity', 'object', 'data', 'something_else', 'something'}
     actual = get_required_entities(input, None)
     self.assertEqual(expected, actual)
Пример #14
0
 def test_resolve_map(self):
     template = parse_template(
         {"studies": {
             "{map}": "{.refIds}",
             "{to}": {
                 "id": "{.}"
             }
         }})
     actual = resolve(template, data_0, data_index)
     expected = {
         'studies': [{
             'id': 1
         }, {
             'id': 2
         }, {
             'id': 3
         }, {
             'id': '4'
         }, {
             'id': 5
         }]
     }
     self.assertEqual(actual, expected)
Пример #15
0
 def test_resolve5(self):
     template = parse_template("{.genus + .species+.baz}")
     actual = resolve(template, data_1, data_index)
     expected = ["Zea mays"]
     self.assertEqual(actual, expected)
Пример #16
0
 def test_resolve_field(self):
     template = parse_template("{.foo}")
     actual = resolve(template, data_0, data_index)
     expected = [1, 2, 3]
     self.assertEqual(actual, expected)
Пример #17
0
 def test_resolve_self(self):
     template = parse_template("{.}")
     actual = resolve(template, data_0, data_index)
     expected = data_0
     self.assertEqual(actual, expected)
Пример #18
0
 def test_resolve_field_join(self):
     template = parse_template("{.refIds => .a}")
     actual = resolve(template, data_0, data_index)
     expected = ["a", "b", "b"]
     self.assertEqual(actual, expected)
Пример #19
0
 def test_resolve_double_object_path(self):
     template = parse_template("{.refIds => .links.objIds => .}")
     actual = resolve(template, data_0, data_index)
     expected = [data_1, data_2, data_3, data_4, data_6]
     self.assertEqual(actual, expected)
Пример #20
0
 def test_resolve(self):
     template = parse_template("{.refIds => .}")
     actual = resolve(template, data_0, data_index)
     expected = [data_1, data_2, data_3, data_4, data_5]
     self.assertEqual(actual, expected)
Пример #21
0
 def test_resolve_dict1(self):
     template = parse_template({"a": "a"})
     actual = resolve(template, data_0, data_index)
     expected = template
     self.assertEqual(actual, expected)
Пример #22
0
 def test_resolve8(self):
     template = parse_template("The species is {.genus + .species+.baz}")
     actual = resolve(template, data_0, data_index)
     expected = "The species is Zea mays"
     self.assertEqual(actual, expected)
Пример #23
0
 def test_resolve_if3(self):
     template = parse_template({"{if}": "{.foo}", "{then}": "bar"})
     actual = resolve(template, data_0, data_index)
     expected = "bar"
     self.assertEqual(actual, expected)
Пример #24
0
 def test_resolve_non_existing_field_in_string_template(self):
     template = parse_template("The species is {.nonExisitngField}")
     actual = resolve(template, data_0, data_index)
     expected = None
     self.assertEqual(actual, expected)
Пример #25
0
 def test_resolve6(self):
     template = parse_template("{.refIds => .g.genus + .g.species + .baz}")
     actual = resolve(template, data_0, data_index)
     expected = ['Populus', 'Triticum aestivum']
     self.assertEqual(actual, expected)
Пример #26
0
 def test_resolve_or1(self):
     template = parse_template({"{or}": ["foo", "bar", "baz"]})
     actual = resolve(template, data_0, data_index)
     expected = "foo"
     self.assertEqual(actual, expected)
Пример #27
0
 def test_resolve7(self):
     template = parse_template(
         "{.links.objIds => .g.genus + .g.species + .g.subtaxa}")
     actual = resolve(template, data_5, data_index)
     expected = ['Populus', 'Triticum aestivum', 'Zea mays subsp. mexicana']
     self.assertEqual(actual, expected)
Пример #28
0
 def test_resolve_or2(self):
     template = parse_template(
         {"{or}": ["{.falseField}", "{.nonExistingField}", "baz"]})
     actual = resolve(template, data_0, data_index)
     expected = "baz"
     self.assertEqual(actual, expected)
Пример #29
0
 def test_resolve9(self):
     template = parse_template("{.foo}{.genus + .species+.baz}")
     actual = resolve(template, data_0, data_index)
     expected = "123Zea mays"
     self.assertEqual(actual, expected)
Пример #30
0
 def test_resolve_dict2(self):
     template = parse_template({"a": "a", "b": "{.foo}"})
     actual = resolve(template, data_0, data_index)
     expected = {"a": "a", "b": [1, 2, 3]}
     self.assertEqual(actual, expected)