Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Clean up imports
Browse files Browse the repository at this point in the history
Add tests that show basic attributes examples
  • Loading branch information
david4096 committed Jan 10, 2017
1 parent c03e18e commit ef15ba1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/main/proto/ga4gh/genotype_phenotype_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ syntax = "proto3";
package ga4gh;

import "ga4gh/common.proto";
import "ga4gh/metadata.proto";
import "ga4gh/genotype_phenotype.proto";
import "google/api/annotations.proto";

Expand Down
1 change: 0 additions & 1 deletion src/main/proto/ga4gh/sequence_annotations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ syntax = "proto3";
package ga4gh;

import "ga4gh/common.proto";
import "ga4gh/metadata.proto";


// This protocol defines annotations on GA4GH genomic sequences It includes two
Expand Down
84 changes: 82 additions & 2 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@

# similar to dev_glue.py
import ga4gh

ga4gh.__path__.insert(0, 'python/ga4gh')

import ga4gh.schemas._protocol_version as version # NOQA
import ga4gh.schemas.google.api.http_pb2 as http_pb2 # NOQA
import ga4gh.schemas.ga4gh.common_pb2 as common_pb2 # NOQA
import ga4gh.schemas.ga4gh.metadata_pb2 as metadata # NOQA
import ga4gh.schemas.pb as pb # NOQA


class TestPb(unittest.TestCase):

def testString(self):
self.assertEqual(pb.DEFAULT_STRING, pb.string(None))
self.assertEqual('A', pb.string('A'))
Expand All @@ -29,13 +30,92 @@ def testInt(self):


class TestSchemas(unittest.TestCase):

def testVersion(self):
version.version.split('.')
self.assertIsNotNone(version.version)

def testGa4ghCommon(self):
self.assertIsNotNone(common_pb2.DESCRIPTOR)

def testDatasetAttributes(self):
"""
Demonstrates the usage of the Attribute's field on a dataset message.
This field is available on many other messages as well.
"""
key = "numbers_and_strings"
string_value = "hello"
int32_value = 5
double_value = 3.14159
attributes = {key: [string_value, int32_value, double_value]}
dataset = metadata.Dataset()
myattribute = dataset.attributes.attr[key].values

myattribute.add().string_value = string_value
myattribute.add().int32_value = int32_value
myattribute.add().double_value = double_value

self.assertEqual(
dataset.attributes.attr[key].values[0].string_value,
attributes[key][0])

self.assertEqual(
dataset.attributes.attr[key].values[1].int32_value,
attributes[key][1])

self.assertEqual(
dataset.attributes.attr[key].values[2].double_value,
attributes[key][2])

def testNestedAttributes(self):
"""
Demonstrates how nested attributes can be used to interchange
arbitrary unstructured, typed data.
"""
dataset = metadata.Dataset()
key1 = "key1"
key2 = "key2"
string_value = "hello"
int32_value = 32
attributes = {key1: [{key2: [string_value]}, int32_value]}
myAttribute = dataset.attributes.attr[key1].values
nestedAttribute = myAttribute.add().attributes.attr[key2].values
nestedAttribute.add().string_value = string_value
myAttribute.add().int32_value = int32_value

self.assertEqual(
dataset.attributes.attr[key1].values[0].
attributes.attr[key2].values[0].string_value,
attributes[key1][0][key2][0])

self.assertEqual(dataset.attributes.attr[key1].
values[1].int32_value, attributes[key1][1])

def testTypedAttributes(self):
"""
Demonstrates how to use other types defined in common to create an
attribute message.
"""
dataset = metadata.Dataset()
ontologyTerm = common_pb2.OntologyTerm()
ontologyTerm.id = "test"
ontologyKey = "my_ontology_term"

dataset.attributes.attr[ontologyKey] \
.values.add().ontology_term.MergeFrom(ontologyTerm)

self.assertEqual(
dataset.attributes.attr[ontologyKey].values[0].ontology_term.id,
ontologyTerm.id)

experiment = common_pb2.Experiment()
experiment.id = "test"
key = "my_experiment"

dataset.attributes.attr[key] \
.values.add().experiment.MergeFrom(experiment)
self.assertEqual(
dataset.attributes.attr[key].values[0].experiment.id, experiment.id)


def testGoogle(self):
self.assertIsNotNone(http_pb2.DESCRIPTOR)

0 comments on commit ef15ba1

Please sign in to comment.