def test_call_set_update_increments_call_count_and_duration(): callset = NPlusOneCallSet() callset.update(SQL, 3, 0.11) callset.update(SQL, 2, 0.07) item = callset.find_for(SQL) assert item.call_count == 5 assert item.call_duration == 0.18
def test_call_set_finds_or_creates(): sql = "SELECT * from test" callset = NPlusOneCallSet() assert (0 == len(callset.items)) item = callset.find_for(sql) assert (1 == len(callset.items)) assert (item.sql_string == sql)
def test_call_set_updates(): sql = "SELECT * from test" callset = NPlusOneCallSet() callset.update(sql, 3, 4) item = callset.find_for(sql) assert (3 == item.call_count) assert (4 == item.call_duration)
def test_call_set_update_no_longer_increments_call_count_and_duration_after_capture( ): callset = NPlusOneCallSet() callset.update(SQL, CALL_COUNT_THRESHOLD, DURATION_THRESHOLD) callset.should_capture_backtrace(SQL) callset.update(SQL, CALL_COUNT_THRESHOLD // 2, DURATION_THRESHOLD // 2) item = callset.find_for(SQL) assert item.call_count == CALL_COUNT_THRESHOLD assert item.call_duration == DURATION_THRESHOLD
def test_is_past_duration_threshold(): sql = "SELECT * from test" callset = NPlusOneCallSet() callset.update(sql, 0, NPlusOneCallSetItem.DURATION_THRESHOLD - 1) item = callset.find_for(sql) assert (item.is_past_duration_threshold() is False) callset.update(sql, 0, 1) assert (item.is_past_duration_threshold() is True) # Assert again to test the attribute check in the function assert (item.is_past_duration_threshold() is True)
def test_call_set_find_for_creates_new_item(): callset = NPlusOneCallSet() assert len(callset.items) == 0 item = callset.find_for(SQL) assert len(callset.items) == 1 assert item.sql_string == SQL
def test_call_set_find_for_returns_existing_item(): callset = NPlusOneCallSet() item1 = callset.find_for(SQL) item2 = callset.find_for(SQL) assert len(callset.items) == 1 assert item1 is item2