<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> import datetime <EOL> import json <EOL> import unittest <EOL> import ga4gh . client as client <EOL> import ga4gh . backend as backend <EOL> import ga4gh . cli as cli <EOL> import ga4gh . datarepo as datarepo <EOL> import tests . utils as utils <EOL> import tests . paths as paths <EOL> import freezegun <EOL> @ freezegun . freeze_time ( datetime . datetime . now ( ) ) <EOL> class TestClientOutput ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . _maxDiff = None <EOL> self . _dataDir = paths . testDataDir <EOL> self . _dataUrl = "<STR_LIT>" . format ( self . _dataDir ) <EOL> dataRepository = datarepo . FileSystemDataRepository ( self . _dataDir ) <EOL> self . _backend = backend . Backend ( dataRepository ) <EOL> self . _client = client . LocalClient ( self . _backend ) <EOL> def captureCliOutput ( self , command , arguments , outputFormat ) : <EOL> clientCommand = "<STR_LIT>" . format ( <EOL> command , self . _dataUrl , arguments , outputFormat ) <EOL> stdout , stderr = utils . captureOutput ( <EOL> cli . client_main , clientCommand . split ( ) ) <EOL> self . assertEqual ( len ( stderr ) , <NUM_LIT:0> ) <EOL> return stdout <EOL> class TestClientFasta ( TestClientOutput ) : <EOL> """<STR_LIT>""" <EOL> def captureFastaOutput ( self , command , arguments = "<STR_LIT>" ) : <EOL> stdout = self . captureCliOutput ( command , arguments , "<STR_LIT>" ) <EOL> lines = stdout . split ( ) <EOL> return lines <EOL> def testListReferenceBases ( self ) : <EOL> referenceSetIterator = self . _client . searchReferenceSets ( ) <EOL> referenceSet = next ( referenceSetIterator ) <EOL> referencesIterator = self . _client . searchReferences ( referenceSet . id ) <EOL> reference = next ( referencesIterator ) <EOL> start = <NUM_LIT:1> <EOL> end = <NUM_LIT:5> <EOL> lines = self . captureFastaOutput ( <EOL> "<STR_LIT>" . format ( start , end ) , <EOL> reference . id ) <EOL> self . assertEqual ( <EOL> lines [ <NUM_LIT:0> ] , "<STR_LIT>" . format ( reference . id , start , end ) ) <EOL> cliBases = '<STR_LIT>' . join ( lines [ <NUM_LIT:1> : ] ) <EOL> bases = self . _client . listReferenceBases ( reference . id , start , end ) <EOL> self . assertEqual ( cliBases , bases ) <EOL> class TestClientJson ( TestClientOutput ) : <EOL> """<STR_LIT>""" <EOL> def captureJsonOutput ( self , command , arguments = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> stdout = self . captureCliOutput ( command , arguments , "<STR_LIT>" ) <EOL> cliOutput = [ ] <EOL> for line in stdout . splitlines ( ) : <EOL> cliOutput . append ( json . loads ( line ) ) <EOL> return cliOutput <EOL> def verifyParsedOutputsEqual ( <EOL> self , clientIterator , cliCommand , cliArguments = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> cliOutput = self . captureJsonOutput ( cliCommand , cliArguments ) <EOL> clientOutput = [ gaObject . toJsonDict ( ) for gaObject in clientIterator ] <EOL> self . assertEqual ( clientOutput , cliOutput ) <EOL> return len ( clientOutput ) <EOL> def testGetCallSet ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for variantSet in self . _client . searchVariantSets ( dataset . id ) : <EOL> for callSet in self . _client . searchCallSets ( variantSet . id ) : <EOL> self . verifyParsedOutputsEqual ( <EOL> [ callSet ] , "<STR_LIT>" , callSet . id ) <EOL> def testGetDataset ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> self . verifyParsedOutputsEqual ( <EOL> [ dataset ] , "<STR_LIT>" , dataset . id ) <EOL> def testGetReadGroup ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for readGroupSet in self . _client . searchReadGroupSets ( dataset . id ) : <EOL> for readGroup in readGroupSet . readGroups : <EOL> self . verifyParsedOutputsEqual ( <EOL> [ readGroup ] , "<STR_LIT>" , readGroup . id ) <EOL> def testGetReadGroupSet ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for readGroupSet in self . _client . searchReadGroupSets ( dataset . id ) : <EOL> self . verifyParsedOutputsEqual ( <EOL> [ readGroupSet ] , "<STR_LIT>" , readGroupSet . id ) <EOL> def testGetReference ( self ) : <EOL> for referenceSet in self . _client . searchReferenceSets ( ) : <EOL> for reference in self . _client . searchReferences ( referenceSet . id ) : <EOL> self . verifyParsedOutputsEqual ( <EOL> [ reference ] , "<STR_LIT>" , reference . id ) <EOL> def testGetReferenceSet ( self ) : <EOL> for referenceSet in self . _client . searchReferenceSets ( ) : <EOL> self . verifyParsedOutputsEqual ( <EOL> [ referenceSet ] , "<STR_LIT>" , referenceSet . id ) <EOL> def testGetVariant ( self ) : <EOL> test_executed = <NUM_LIT:0> <EOL> start = <NUM_LIT:0> <EOL> end = <NUM_LIT:1000> <EOL> referenceName = "<STR_LIT:1>" <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for variantSet in self . _client . searchVariantSets ( dataset . id ) : <EOL> variants = self . _client . searchVariants ( <EOL> variantSet . id , start = start , end = end , <EOL> referenceName = referenceName ) <EOL> for variant in variants : <EOL> test_executed += self . verifyParsedOutputsEqual ( <EOL> [ variant ] , "<STR_LIT>" , variant . id ) <EOL> self . assertGreater ( test_executed , <NUM_LIT:0> ) <EOL> def testGetVariantAnnotationSet ( self ) : <EOL> test_executed = <NUM_LIT:0> <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for variantSet in self . _client . searchVariantSets ( dataset . id ) : <EOL> for annSet in self . _client . searchVariantAnnotationSets ( <EOL> variantSet . id ) : <EOL> test_executed += self . verifyParsedOutputsEqual ( <EOL> [ annSet ] , "<STR_LIT>" , annSet . id ) <EOL> self . assertGreater ( test_executed , <NUM_LIT:0> ) <EOL> def testGetVariantSet ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for variantSet in self . _client . searchVariantSets ( dataset . id ) : <EOL> self . verifyParsedOutputsEqual ( <EOL> [ variantSet ] , "<STR_LIT>" , variantSet . id ) <EOL> def testSearchCallSets ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for variantSet in self . _client . searchVariantSets ( dataset . id ) : <EOL> iterator = self . _client . searchCallSets ( variantSet . id ) <EOL> args = "<STR_LIT>" . format ( variantSet . id ) <EOL> self . verifyParsedOutputsEqual ( <EOL> iterator , "<STR_LIT>" , args ) <EOL> def testSearchDatasets ( self ) : <EOL> iterator = self . _client . searchDatasets ( ) <EOL> self . verifyParsedOutputsEqual ( iterator , "<STR_LIT>" ) <EOL> def testSearchReadGroupSets ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> iterator = self . _client . searchReadGroupSets ( dataset . id ) <EOL> self . verifyParsedOutputsEqual ( <EOL> iterator , "<STR_LIT>" , <EOL> "<STR_LIT>" . format ( dataset . id ) ) <EOL> def testSearchReads ( self ) : <EOL> test_executed = <NUM_LIT:0> <EOL> start = <NUM_LIT:0> <EOL> end = <NUM_LIT:1000> <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for readGroupSet in self . _client . searchReadGroupSets ( dataset . id ) : <EOL> for readGroup in readGroupSet . readGroups : <EOL> reference = self . _client . searchReferences ( <EOL> referenceSetId = readGroup . referenceSetId ) . next ( ) <EOL> referenceId = reference . id <EOL> iterator = self . _client . searchReads ( <EOL> [ readGroup . id ] , referenceId = referenceId , <EOL> start = start , end = end ) <EOL> args = "<STR_LIT>" . format ( <EOL> start , end , readGroup . id , referenceId ) <EOL> test_executed += self . verifyParsedOutputsEqual ( <EOL> iterator , "<STR_LIT>" , args ) <EOL> self . assertGreater ( test_executed , <NUM_LIT:0> ) <EOL> def testSearchReferenceSets ( self ) : <EOL> iterator = self . _client . searchReferenceSets ( ) <EOL> self . verifyParsedOutputsEqual ( iterator , "<STR_LIT>" ) <EOL> def testSearchReferences ( self ) : <EOL> for referenceSet in self . _client . searchReferenceSets ( ) : <EOL> iterator = self . _client . searchReferences ( <EOL> referenceSetId = referenceSet . id ) <EOL> args = "<STR_LIT>" . format ( referenceSet . id ) <EOL> self . verifyParsedOutputsEqual ( iterator , "<STR_LIT>" , args ) <EOL> def testSearchVariantSets ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> iterator = self . _client . searchVariantSets ( dataset . id ) <EOL> self . verifyParsedOutputsEqual ( iterator , "<STR_LIT>" ) <EOL> def testSearchVariants ( self ) : <EOL> test_executed = <NUM_LIT:0> <EOL> start = <NUM_LIT:0> <EOL> end = <NUM_LIT:1000> <EOL> referenceName = "<STR_LIT:1>" <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for variantSet in self . _client . searchVariantSets ( dataset . id ) : <EOL> iterator = self . _client . searchVariants ( <EOL> variantSet . id , start = start , end = end , <EOL> referenceName = referenceName , callSetIds = [ ] ) <EOL> args = "<STR_LIT>" . format ( <EOL> variantSet . id , start , end , referenceName ) <EOL> test_executed += self . verifyParsedOutputsEqual ( <EOL> iterator , "<STR_LIT>" , args ) <EOL> self . assertGreater ( test_executed , <NUM_LIT:0> ) <EOL> def testSearchVariantAnnotationSets ( self ) : <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for variantSet in self . _client . searchVariantSets ( dataset . id ) : <EOL> iterator = self . _client . searchVariantAnnotationSets ( <EOL> variantSet . id ) <EOL> args = "<STR_LIT:{}>" . format ( variantSet . id ) <EOL> self . verifyParsedOutputsEqual ( <EOL> iterator , "<STR_LIT>" , args ) <EOL> def testSearchVariantAnnotations ( self ) : <EOL> test_executed = <NUM_LIT:0> <EOL> start = <NUM_LIT:0> <EOL> end = <NUM_LIT> <EOL> referenceName = "<STR_LIT:1>" <EOL> for dataset in self . _client . searchDatasets ( ) : <EOL> for variantSet in self . _client . searchVariantSets ( dataset . id ) : <EOL> searchIterator = self . _client . searchVariantAnnotationSets ( <EOL> variantSet . id ) <EOL> for variantAnnotationSet in searchIterator : <EOL> iterator = self . _client . searchVariantAnnotations ( <EOL> variantAnnotationSet . id , <EOL> start = start , <EOL> end = end , <EOL> referenceName = referenceName ) <EOL> args = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> variantAnnotationSet . id , start , end , referenceName ) <EOL> test_executed += self . verifyParsedOutputsEqual ( <EOL> iterator , "<STR_LIT>" , args ) <EOL> self . assertGreater ( test_executed , <NUM_LIT:0> ) </s>
