当前位置: 首页>>代码示例>>Python>>正文


Python RunTracker.post_stats方法代码示例

本文整理汇总了Python中pants.goal.run_tracker.RunTracker.post_stats方法的典型用法代码示例。如果您正苦于以下问题:Python RunTracker.post_stats方法的具体用法?Python RunTracker.post_stats怎么用?Python RunTracker.post_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pants.goal.run_tracker.RunTracker的用法示例。


在下文中一共展示了RunTracker.post_stats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_upload_stats

# 需要导入模块: from pants.goal.run_tracker import RunTracker [as 别名]
# 或者: from pants.goal.run_tracker.RunTracker import post_stats [as 别名]
  def test_upload_stats(self):
    stats = {'stats': {'foo': 'bar', 'baz': 42}}

    class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
      def do_POST(handler):
        try:
          self.assertEquals('/upload', handler.path)
          self.assertEquals('application/x-www-form-urlencoded', handler.headers['Content-type'])
          length = int(handler.headers['Content-Length'])
          post_data = urlparse.parse_qs(handler.rfile.read(length).decode('utf-8'))
          decoded_post_data = {k: json.loads(v[0]) for k, v in post_data.items()}
          self.assertEquals(stats, decoded_post_data)
          handler.send_response(200)
        except Exception:
          handler.send_response(400)  # Ensure the main thread knows the test failed.
          raise


    server_address = ('', 0)
    server = BaseHTTPServer.HTTPServer(server_address, Handler)
    host, port = server.server_address

    server_thread = threading.Thread(target=server.serve_forever)
    server_thread.daemon = True
    server_thread.start()

    self.assertTrue(RunTracker.post_stats('http://{}:{}/upload'.format(host, port), stats))

    server.shutdown()
    server.server_close()
开发者ID:CaitieM20,项目名称:pants,代码行数:32,代码来源:test_run_tracker.py

示例2: test_upload_stats

# 需要导入模块: from pants.goal.run_tracker import RunTracker [as 别名]
# 或者: from pants.goal.run_tracker.RunTracker import post_stats [as 别名]
  def test_upload_stats(self):
    stats = {'stats': {'foo': 'bar', 'baz': 42}}

    class Handler(http.server.BaseHTTPRequestHandler):
      def do_POST(handler):
        try:
          if handler.path.startswith('/redirect'):
            code = int(handler.path[-3:])
            handler.send_response(code)
            handler.send_header('location', mk_url('/upload'))
            handler.end_headers()
          else:
            self.assertEqual('/upload', handler.path)
            self.assertEqual('application/x-www-form-urlencoded', handler.headers['Content-type'])
            length = int(handler.headers['Content-Length'])
            post_data = parse_qs(handler.rfile.read(length).decode('utf-8'))
            decoded_post_data = {k: json.loads(v[0]) for k, v in post_data.items()}
            self.assertEqual(stats, decoded_post_data)
            handler.send_response(200)
            handler.end_headers()
        except Exception:
          handler.send_response(400)  # Ensure the main thread knows the test failed.
          raise

    server_address = ('', 0)
    server = http.server.HTTPServer(server_address, Handler)
    host, port = server.server_address

    def mk_url(path):
      return 'http://{}:{}{}'.format(host, port, path)

    server_thread = threading.Thread(target=server.serve_forever)
    server_thread.daemon = True
    server_thread.start()

    self.context(for_subsystems=[Cookies])
    self.assertTrue(RunTracker.post_stats(mk_url('/upload'), stats))
    self.assertTrue(RunTracker.post_stats(mk_url('/redirect307'), stats))
    self.assertFalse(RunTracker.post_stats(mk_url('/redirect302'), stats))

    server.shutdown()
    server.server_close()
开发者ID:cosmicexplorer,项目名称:pants,代码行数:44,代码来源:test_run_tracker.py


注:本文中的pants.goal.run_tracker.RunTracker.post_stats方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。