• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

scope3data / scope3ai-py / 12600822014

03 Jan 2025 04:35PM UTC coverage: 94.022% (+13.5%) from 80.557%
12600822014

Pull #47

github

0248fe
kevdevg
fix: text-to-image async implementation
Pull Request #47: Kevdevg/huggingface

45 of 49 new or added lines in 3 files covered. (91.84%)

20 existing lines in 3 files now uncovered.

1447 of 1539 relevant lines covered (94.02%)

3.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.62
/scope3ai/tracers/huggingface/utils.py
1
import contextlib
4✔
2
import contextvars
4✔
3

4
HFRS_BASEKEY = "scope3ai__huggingface__hf_raise_for_status"
4✔
5
HFRS_ENABLED = contextvars.ContextVar(f"{HFRS_BASEKEY}__enabled", default=None)
4✔
6
HFRS_VALUE = contextvars.ContextVar(f"{HFRS_BASEKEY}__value", default=None)
4✔
7

8

9
HFRS_ASYNC_BASEKEY = "scope3ai__huggingface__hf_async_raise_for_status"
4✔
10
HFRS_ASYNC_ENABLED = contextvars.ContextVar(
4✔
11
    f"{HFRS_ASYNC_BASEKEY}__enabled", default=None
12
)
13
HFRS_ASYNC_VALUE = contextvars.ContextVar(f"{HFRS_ASYNC_BASEKEY}__value", default=None)
4✔
14

15

16
def hf_raise_for_status_enabled():
4✔
17
    return HFRS_ENABLED.get() is True
4✔
18

19

20
def hf_async_raise_for_status_enabled():
4✔
NEW
21
    return HFRS_ASYNC_ENABLED.get() is True
×
22

23

24
def hf_raise_for_status_wrapper(wrapped, instance, args, kwargs):
4✔
25
    try:
4✔
26
        result = wrapped(*args, **kwargs)
4✔
27
        response = args[0]
4✔
28
        HFRS_VALUE.set(response)
4✔
29
        return result
4✔
30
    except Exception as e:
4✔
31
        raise e
4✔
32

33

34
@contextlib.contextmanager
4✔
35
def hf_raise_for_status_capture():
4✔
36
    try:
4✔
37
        HFRS_VALUE.set(None)
4✔
38
        HFRS_ENABLED.set(True)
4✔
39
        yield HFRS_VALUE
4✔
40
    finally:
41
        HFRS_ENABLED.set(False)
4✔
42

43

44
@contextlib.contextmanager
4✔
45
def hf_async_raise_for_status_capture():
4✔
46
    try:
4✔
47
        HFRS_ASYNC_VALUE.set(None)
4✔
48
        HFRS_ASYNC_ENABLED.set(True)
4✔
49
        yield HFRS_ASYNC_VALUE
4✔
50
    finally:
51
        HFRS_ASYNC_ENABLED.set(False)
4✔
52

53

54
def async_post_wrapper(session_post):
4✔
55
    async def wrapped_post(*args, **kwargs):
4✔
56
        result = await session_post(*args, **kwargs)
4✔
57
        HFRS_ASYNC_VALUE.set(result)
4✔
58
        return result
4✔
59

60
    return wrapped_post
4✔
61

62

63
def get_client_session_async_wrapper(wrapped, instance, args, kwargs):
4✔
64
    try:
4✔
65
        result = wrapped(*args, **kwargs)
4✔
66
        result.post = async_post_wrapper(result.post)
4✔
67
        return result
4✔
NEW
68
    except Exception as e:
×
NEW
69
        raise e
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc