# -*- coding: utf8 -*-
from __future__ import unicode_literals

from future.standard_library import install_aliases
install_aliases()

import sys
import time
import threading
from urllib import parse as urlparse

import pytest

from bugbuzz import BugBuzz
from bugbuzz.packages import requests

# just a dummy unicode string, to see if we can handle unicode correctly
DUMMY_STR = u'除錯'


@pytest.fixture(scope='session')
def bugbuzz_dbg(
    base_url='https://bugbuzz-api.herokuapp.com',
    dashboard_url='http://dashboard.bugbuzz.io/',
):
    return BugBuzz(base_url, dashboard_url)


def test_set_trace(mocker, bugbuzz_dbg):
    mocker.patch('webbrowser.open_new_tab')

    # post continue command
    def post_continue():
        time.sleep(3)
        url = urlparse.urljoin(
            bugbuzz_dbg.base_url,
            '/sessions/{}/actions/continue'.format(
                bugbuzz_dbg.client.session_id
            ),
        )
        requests.post(url)

    thread = threading.Thread(target=post_continue)
    thread.daemon = True
    thread.start()

    # TODO: set a timeout here?
    bugbuzz_dbg.set_trace(sys._getframe())

    url = urlparse.urljoin(
        bugbuzz_dbg.base_url,
        '/sessions/{}'.format(bugbuzz_dbg.client.session_id),
    )
    resp = requests.get(url)
    session = resp.json()['session']
    assert len(session['files']) == 1
    assert len(session['breaks']) == 1

@@ -664,16 +664,59 @@
 ew_tab')
+%0A    base_url = bugbuzz_dbg.client.base_url
 %0A%0A    # 
@@ -824,36 +824,24 @@
             
-bugbuzz_dbg.
 base_url,%0A  
@@ -968,16 +968,23 @@
 %0A       
+ resp =
  request
@@ -994,16 +994,48 @@
 ost(url)
+%0A        resp.raise_for_status()
 %0A%0A    th
@@ -1201,16 +1201,56 @@
 ame())%0A%0A
+    sid = bugbuzz_dbg.client.session_id%0A
     url 
@@ -1272,29 +1272,8 @@
 oin(
-%0A        bugbuzz_dbg.
 base
@@ -1277,24 +1277,16 @@
 ase_url,
-%0A       
  '/sessi
@@ -1304,44 +1304,12 @@
 mat(
-bugbuzz_dbg.client.session_id),%0A    
+sid)
 )%0A  
@@ -1439,18 +1439,18 @@
 n%5B'breaks'%5D) == 
-1
+2
 %0A

Fix test itself