Beispiel #1
0
 def run_cmd(self, cmd):
     parser = cli.get_htsget_parser()
     args = parser.parse_args(cmd.split())
     with mock.patch("htsget.get") as mocked_get, \
             mock.patch("sys.exit") as mocked_exit:
         cli.run(args)
         self.assertEqual(mocked_get.call_count, 1)
         mocked_exit.assert_called_once_with(0)
         return mocked_get.call_args
Beispiel #2
0
 def run_cmd(self, cmd):
     parser = cli.get_htsget_parser()
     args = parser.parse_args(cmd.split())
     with mock.patch("htsget.get") as mocked_get, \
             mock.patch("sys.exit") as mocked_exit, \
             mock.patch("logging.basicConfig") as mocked_log_config:
         cli.run(args)
         self.assertEqual(mocked_get.call_count, 1)
         self.assertEqual(mocked_log_config.call_count, 1)
         mocked_exit.assert_called_once_with(0)
         return mocked_log_config.call_args[1]["level"]
Beispiel #3
0
 def assert_exception_writes_error_message(self, exception, message):
     parser = cli.get_htsget_parser()
     args = parser.parse_args(["https://some.url"])
     saved_stderr = sys.stderr
     try:
         with tempfile.TemporaryFile("w+") as tmp_stderr:
             sys.stderr = tmp_stderr
             with mock.patch("htsget.get") as mocked_get, \
                     mock.patch("sys.exit") as mocked_exit, \
                     mock.patch("logging.basicConfig"):
                 mocked_get.side_effect = exception
                 cli.run(args)
             tmp_stderr.seek(0)
             stderr = tmp_stderr.read().strip()
             mocked_exit.assert_called_once_with(1)
     finally:
         sys.stderr = saved_stderr
     self.assertTrue(stderr.endswith(message))
Beispiel #4
0
 def test_transfer_with_cli_stdout(self):
     test_instances = [
         TestUrlInstance(url="/data1", data=b"data1"),
         TestUrlInstance(url="/data2", data=b"data2")
     ]
     self.httpd.test_instances = test_instances
     saved = sys.stdout
     sys.stdout = self.output_file
     try:
         cmd = [TestRequestHandler.ticket_url]
         parser = cli.get_htsget_parser()
         args = parser.parse_args(cmd)
         with mock.patch("sys.exit") as mocked_exit:
             cli.run(args)
             mocked_exit.assert_called_once_with(0)
         all_data = b"".join(test_instance.data for test_instance in test_instances)
         self.output_file.seek(0)
         self.assertEqual(self.output_file.read(), all_data)
     finally:
         sys.stdout = saved
Beispiel #5
0
 def test_transfer_with_cli(self):
     test_instances = [
         TestUrlInstance(url="/data1", data=b"data1"),
         TestUrlInstance(url="/data2", data=b"data2")
     ]
     self.httpd.test_instances = test_instances
     try:
         fd, filename = tempfile.mkstemp()
         os.close(fd)
         cmd = [TestRequestHandler.ticket_url, "-O", filename]
         parser = cli.get_htsget_parser()
         args = parser.parse_args(cmd)
         with mock.patch("sys.exit") as mocked_exit:
             cli.run(args)
             mocked_exit.assert_called_once_with(0)
         all_data = b"".join(test_instance.data for test_instance in test_instances)
         with open(filename, "rb") as f:
             self.assertEqual(f.read(), all_data)
     finally:
         os.unlink(filename)