Skip to content

Commit 51f6700

Browse files
shixishclaude
andcommitted
ci: run pyright in tests.yml; extend live suite over account, extract, crawl_download
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 85a9e5c commit 51f6700

2 files changed

Lines changed: 83 additions & 4 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ jobs:
2828
- name: Run tests
2929
run: uv run pytest
3030

31+
# Static typing gate: pyright (basic on src/, strict on types.py) plus the
32+
# assert_type checks in tests/typing. One Python version is enough.
33+
typecheck:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v5
40+
with:
41+
python-version: "3.12"
42+
43+
- name: Install dependencies (locked)
44+
run: uv sync --frozen --extra dev
45+
46+
- name: Run pyright
47+
run: uv run pyright
48+
3149
# Catch breakage against the lowest dependency versions our ranges allow,
3250
# which the pinned lockfile would otherwise hide.
3351
test-lowest:

‎tests/test_live.py‎

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Skipped by default. Assertions are on response *shape* only, never web content.
44
Never include token values in assertion messages.
55
"""
6+
import time
7+
import uuid
8+
69
import pytest
710

811
pytestmark = pytest.mark.live
@@ -20,13 +23,14 @@ def test_live_dql_post_single_read(db):
2023

2124

2225
def test_live_dql_post_csv(db):
23-
body = db.dql('type:Organization name:"Diffbot"', size=1, format="csv", raw=True)
24-
assert isinstance(body, bytes) and len(body) > 0
26+
text = db.dql('type:Organization name:"Diffbot"', size=1, format="csv")
27+
assert isinstance(text, str) and len(text.splitlines()) >= 2
28+
assert isinstance(db.dql('type:Organization name:"Diffbot"', size=1, format="csv", raw=True), bytes)
2529

2630

2731
def test_live_dql_post_jsonl(db):
28-
body = db.dql('type:Organization name:"Diffbot"', size=1, format="jsonl", raw=True)
29-
assert isinstance(body, bytes) and len(body) > 0
32+
entities = list(db.dql('type:Organization name:"Diffbot"', size=1, format="jsonl"))
33+
assert len(entities) >= 1
3034

3135

3236
def test_live_dql_long_query_beyond_url_limit(db):
@@ -39,3 +43,60 @@ def test_live_dql_long_query_beyond_url_limit(db):
3943
def test_live_entities(db):
4044
result = db.entities("Diffbot is a company based in Menlo Park.")
4145
assert "entities" in result
46+
47+
48+
def _redacted(account) -> str:
49+
"""Account bodies carry ``token``/``childTokens``: only ever show the other keys."""
50+
return f"keys={sorted(k for k in account if k not in ('token', 'childTokens'))}"
51+
52+
53+
def test_live_account_and_verify_token(db):
54+
account = db.account(days=1)
55+
assert isinstance(account, dict), _redacted({})
56+
assert "plan" in account or "name" in account or "usage" in account, _redacted(account)
57+
assert db.verify_token() is True
58+
59+
60+
def test_live_verify_token_rejects_a_bad_token():
61+
from diffbot import Diffbot
62+
63+
assert Diffbot(token="not-a-real-token").verify_token() is False
64+
65+
66+
def test_live_extract_with_fields_and_timeout(db):
67+
result = db.extract("https://example.com", "article", fmt="json", fields=["links"], timeout=45000)
68+
assert "objects" in result and len(result["objects"]) > 0
69+
70+
71+
CRAWL_PREFIX = "sdk-live-"
72+
73+
74+
def _purge_leaked_crawls(db) -> None:
75+
cutoff = time.time() - 3600
76+
for job in db.crawl_list_jobs():
77+
name = job.get("name", "")
78+
if name.startswith(CRAWL_PREFIX):
79+
try:
80+
created = int(name.rsplit("-", 1)[-1])
81+
except ValueError:
82+
continue
83+
if created < cutoff:
84+
db.crawl_delete_job(name)
85+
86+
87+
def test_live_crawl_start_poll_download(db):
88+
_purge_leaked_crawls(db)
89+
name = f"{CRAWL_PREFIX}py-{uuid.uuid4().hex[:8]}-{int(time.time())}"
90+
try:
91+
for _ in db.crawl("https://example.com", job_name=name, hops=0, max_to_crawl=5, max_to_process=5):
92+
pass
93+
deadline = time.time() + 180
94+
while time.time() < deadline:
95+
if db.crawl_get_job(name).get("jobStatus", {}).get("status", 0) not in (0, 7):
96+
break
97+
time.sleep(5)
98+
records = db.crawl_download(name)
99+
assert isinstance(records, list)
100+
assert isinstance(db.crawl_download(name, format="csv"), str)
101+
finally:
102+
db.crawl_delete_job(name)

0 commit comments

Comments
 (0)