Example #1
0
def open_problem(problem_id, block=Block.ONCE):
    """Open the problem inspector for the specified problem.

    Args:
        problem_id (str):
            Submitted problem identity, as returned by SAPI.

        block (:class:`Block`/str/bool, optional, default: :obj:`Block.ONCE`):
            Blocking behavior after opening up the web browser preview as set
            by :class:`Block` value.

    """
    # accept string name for `block`
    if isinstance(block, str):
        block = Block(block.lower())

    app_server.ensure_started()
    url = app_server.get_inspect_url(problem_id)

    # open url and block if requested
    view(url)

    if block is Block.ONCE:
        app_server.wait_problem_accessed(problem_id)
    elif block is Block.FOREVER or block is True:
        app_server.wait_shutdown()

    return url
Example #2
0
    def test_show_no_block(self):
        # exclude potential server start-up time from timing tests below
        app_server.ensure_started()

        # show shouldn't block regardless of problem inspector opening or not
        with self.assertMaxRuntime(2000):
            show(self.response, block=Block.NEVER)
Example #3
0
    def test_show_block_timeout(self):
        # exclude potential server start-up time from timing tests below
        app_server.ensure_started()

        # show blocks until timeout
        with self.assertMaxRuntime(2000):
            show(self.response, block=Block.ONCE, timeout=1)

        with self.assertMaxRuntime(2000):
            show(self.response, block=True, timeout=1)
Example #4
0
    def test_show_block_once(self):
        # exclude potential server start-up time from timing tests below
        app_server.ensure_started()

        # show should block until first access
        with ThreadPoolExecutor(max_workers=1) as executor:
            with self.assertMaxRuntime(2000):
                # notify the inspector server the `problem_id` has been "viewed" by
                # our mock browser/viewer (async)
                fut = executor.submit(self.notify_problem_loaded, problem_id=self.problem_id)
                show(self.response, block=Block.ONCE)
                fut.result()
 def test_smoke(self):
     self.assertTrue(app_server.ensure_started())
     app_server.stop()