__license__ = "GPL"
__version__ = "1.6.0-dev"
__maintainer__ = "Justin Kuczynski"
__email__ = "*****@*****.**"
__status__ = "Development"

from qiime.principal_coordinates import pcoa
from cogent.util.unit_test import TestCase, main


class FunctionTests(TestCase):
    """Tests of top-level functions"""

    def setUp(self):
        self.distmtx_txt = """\tsam1\tsam2\tsam3
sam1\t0.00\t.18\t.44
sam2\t0.18\t0\t.66
sam3\t.44\t.66\t0""".split(
            "\n"
        )

    def test_pcoa(self):
        """ pcoa should throw no errors"""
        res = pcoa(self.distmtx_txt)
        assert res  # formatting tested elsewhere


# run tests if called from command line
if __name__ == "__main__":
    main()
Example #2
0
            test = doctest.DocFileSuite(module, optionflags=
                doctest.REPORT_ONLY_FIRST_FAILURE |
                doctest.ELLIPSIS)
        else:
            test = unittest.findTestCases(my_import(module))
        alltests.addTest(test)
    return alltests

class BoobyTrappedStream(object):
    def __init__(self, output):
        self.output = output

    def write(self, text):
        self.output.write(text)
        raise RuntimeError, "Output not allowed in tests"

if __name__ == '__main__':
    if '--debug' in sys.argv:
        s = suite()
        s.debug()
    else:
        orig = sys.stdout
        if '--output-ok' in sys.argv:
            sys.argv.remove('--output-ok')
        else:
            sys.stdout = BoobyTrappedStream(orig)
        try:
            unittest.main(defaultTest='suite', argv=sys.argv)
        finally:
            sys.stdout = orig
Example #3
0
class BoobyTrappedStream(object):
    def __init__(self, output):
        self.output = output

    def write(self, text):
        self.output.write(text)
        raise RuntimeError, "Output not allowed in tests"

    def flush(self):
        pass

    def isatty(self):
        return False


if __name__ == '__main__':
    if '--debug' in sys.argv:
        s = suite()
        s.debug()
    else:
        orig = sys.stdout
        if '--output-ok' in sys.argv:
            sys.argv.remove('--output-ok')
        else:
            sys.stdout = BoobyTrappedStream(orig)
        try:
            unittest.main(defaultTest='suite', argv=sys.argv)
        finally:
            sys.stdout = orig
        workers, client_sockets = self._setup_server_and_clients()

        self.assertTrue(check_workers(workers, client_sockets))

        #Now close and terminate a client, wait and check again
        client_sockets[0].close()
        self.server_socket.close()
        sleep(1)
        self.assertFalse(check_workers(workers, client_sockets))

    def test_setup_server(self):
        """setup_server opens a port and listens"""

        self.server_socket = setup_server()
        host, port = self.server_socket.getsockname()
        #Not much to test here, if we get something back it should work
        self.assertGreaterThan(port, 1023)
        #binding to a known port should fail
        self.assertRaises(error, setup_server, 80)

    def test_save_send(self):
        """save_send reliably send data to a socket"""
        #Don't really know how to test this effectively...
        #Would require to simulate a blocking socket on the recipient side...
        pass


if __name__ == "__main__":
    main()
Example #5
0
        self.output = output

    def write(self, text):
        self.output.write(text)
        raise RuntimeError("Output not allowed in tests")

    def flush(self):
        pass

    def isatty(self):
        return False


if __name__ == '__main__':
    if '--debug' in sys.argv:
        s = suite()
        s.debug()
    else:
        orig = sys.stdout
        if '--output-ok' in sys.argv:
            sys.argv.remove('--output-ok')
        else:
            sys.stdout = BoobyTrappedStream(orig)
        try:
            argv = {}
            if sys.argv is not None:
                argv = {'defaultTest': 'suite', 'argv': sys.argv}
            unittest.main(**argv)
        except:
            sys.stdout = orig