<commit_before>"""
Tests the ability of the server to fetch remote data files
"""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import client as client
import server as server
import server_test as server_test


class RemoteServerTestReads(server_test.RemoteServerTest):
    """
    Configures a RemoteServerTest subclass with read data
    """
    def getRemoteDataDir(self):
        return "tests/data/dataset1/reads/wgBam/"

    def getServer(self):
        dataDir = "tests/end_to_end/remoteTestDataReads"
        return server.Ga4ghServerForTestingDataSource(dataDir)


class TestRemoteFetchReads(RemoteServerTestReads):
    """
    Tests fetching read data from files on a remote server
    """
    def testBamFetch(self):
        self.client = client.ClientForTesting(self.server.getUrl())
        self.readGroupIds = (
            'ZGF0YXNldDE6cmVtb3RlVGVzdDp3Z0VuY29kZVV3UmVwbGlTZXFCZzAy'
            'ZXNHMWJBbG5SZXAxX3NhbXBsZQ==')
        self.runClientCmd(
            self.client,
            "reads-search --readGroupIds '{}' "
            "--referenceId chr1 ".format(self.readGroupIds))
        self._assertLogsWritten()
        self.client.cleanup()

    def _assertLogsWritten(self):
        # client should have gotten some reads back
        self.assertEqual(len(self.client.getOutLines()), 10)


class RemoteServerTestVariants(server_test.RemoteServerTest):
    """
    Configures a RemoteServerTest subclass with variant data
    """
    def getRemoteDataDir(self):
        return "tests/data/dataset1/variants/1kgPhase1"

    def getServer(self):
        dataDir = "tests/end_to_end/remoteTestDataVariants"
        return server.Ga4ghServerForTestingDataSource(dataDir)


class TestRemoteFetchVariants(RemoteServerTestVariants):
    """
    Tests fetching variant data from files on a remote server
    """
    def testVcfFetch(self):
        self.client = client.ClientForTesting(self.server.getUrl())
        self.runClientCmd(
            self.client,
            "variants-search -V ZGF0YXNldDE6cmVtb3RlVGVzdA==")
        self._assertLogsWritten()
        self.client.cleanup()

    def _assertLogsWritten(self):
        # client should have gotten some variants back
        self.assertEqual(len(self.client.getOutLines()), 100)<commit_msg>Temporary fix to cleanup htslib-downloaded indexes<commit_after>"""
Tests the ability of the server to fetch remote data files
"""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import glob
import os

import client as client
import server as server
import server_test as server_test


class RemoteServerTestReads(server_test.RemoteServerTest):
    """
    Configures a RemoteServerTest subclass with read data
    """
    def getRemoteDataDir(self):
        return "tests/data/dataset1/reads/wgBam/"

    def getServer(self):
        dataDir = "tests/end_to_end/remoteTestDataReads"
        return server.Ga4ghServerForTestingDataSource(dataDir)


class TestRemoteFetchReads(RemoteServerTestReads):
    """
    Tests fetching read data from files on a remote server
    """
    def testBamFetch(self):
        self.client = client.ClientForTesting(self.server.getUrl())
        self.readGroupIds = (
            'ZGF0YXNldDE6cmVtb3RlVGVzdDp3Z0VuY29kZVV3UmVwbGlTZXFCZzAy'
            'ZXNHMWJBbG5SZXAxX3NhbXBsZQ==')
        self.runClientCmd(
            self.client,
            "reads-search --readGroupIds '{}' "
            "--referenceId chr1 ".format(self.readGroupIds))
        self._assertLogsWritten()
        self.client.cleanup()

    def _assertLogsWritten(self):
        # client should have gotten some reads back
        self.assertEqual(len(self.client.getOutLines()), 10)

    # TODO take out when #500 is fixed
    def tearDown(self):
        # clean up downloaded local index file
        print("Removing bai index files; see issue #500")
        for indexFile in glob.glob("*.bai"):
            os.remove(indexFile)


class RemoteServerTestVariants(server_test.RemoteServerTest):
    """
    Configures a RemoteServerTest subclass with variant data
    """
    def getRemoteDataDir(self):
        return "tests/data/dataset1/variants/1kgPhase1"

    def getServer(self):
        dataDir = "tests/end_to_end/remoteTestDataVariants"
        return server.Ga4ghServerForTestingDataSource(dataDir)


class TestRemoteFetchVariants(RemoteServerTestVariants):
    """
    Tests fetching variant data from files on a remote server
    """
    def testVcfFetch(self):
        self.client = client.ClientForTesting(self.server.getUrl())
        self.runClientCmd(
            self.client,
            "variants-search -V ZGF0YXNldDE6cmVtb3RlVGVzdA==")
        self._assertLogsWritten()
        self.client.cleanup()

    def _assertLogsWritten(self):
        # client should have gotten some variants back
        self.assertEqual(len(self.client.getOutLines()), 100)

    # TODO take out when #500 is fixed
    def tearDown(self):
        # clean up downloaded local index file
        print("Removing tbi index files; see issue #500")
        for indexFile in glob.glob("*.tbi"):
            os.remove(indexFile)
{'fraction_non_alphanumeric': 0.08448275862068966, 'fraction_numerical': 0.011877394636015325, 'mean_word_length': 3.156847133757962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380054', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1525, 'n_words': 356}