Skip to content

Commit 5b617b2

Browse files
resolved todos
1 parent aa755ed commit 5b617b2

File tree

2 files changed

+11
-82
lines changed

2 files changed

+11
-82
lines changed

tests/regression/test_extract_aigrant_companies.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,9 @@ async def test_extract_aigrant_companies_local(self, local_stagehand):
101101
)
102102

103103
result = await stagehand.page.extract(extract_options)
104-
105-
# TODO - how to unify the extract result handling between LOCAL and BROWSERBASE?
106-
107-
# Handle result based on the mode (LOCAL returns data directly, BROWSERBASE returns ExtractResult)
108-
if hasattr(result, 'data') and result.data:
109-
# BROWSERBASE mode format
110-
companies_model = Companies.model_validate(result.data)
111-
companies = companies_model.companies
112-
else:
113-
# LOCAL mode format - result is the Pydantic model instance
114-
companies_model = Companies.model_validate(result.model_dump())
115-
companies = companies_model.companies
104+
105+
# Both LOCAL and BROWSERBASE modes return the Pydantic model instance directly
106+
companies = result.companies
116107

117108
# Verify total count
118109
expected_length = 91
@@ -179,18 +170,9 @@ async def test_extract_aigrant_companies_browserbase(self, browserbase_stagehand
179170
)
180171

181172
result = await stagehand.page.extract(extract_options)
182-
183-
# TODO - how to unify the extract result handling between LOCAL and BROWSERBASE?
184-
185-
# Handle result based on the mode (LOCAL returns data directly, BROWSERBASE returns ExtractResult)
186-
if hasattr(result, 'data') and result.data:
187-
# BROWSERBASE mode format
188-
companies_model = Companies.model_validate(result.data)
189-
companies = companies_model.companies
190-
else:
191-
# LOCAL mode format - result is the Pydantic model instance
192-
companies_model = Companies.model_validate(result.model_dump())
193-
companies = companies_model.companies
173+
174+
# Both LOCAL and BROWSERBASE modes return the Pydantic model instance directly
175+
companies = result.companies
194176

195177
# Verify total count
196178
expected_length = 91

tests/regression/test_wichita.py

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,9 @@ async def test_wichita_local(self, local_stagehand):
9595
)
9696

9797
result = await stagehand.page.extract(extract_options)
98-
#TODO - how to unify the extract result handling between LOCAL and BROWSERBASE?
99-
100-
# Handle result based on the mode with better error handling
101-
total_results = None
102-
103-
if hasattr(result, 'data') and result.data:
104-
# BROWSERBASE mode format
105-
try:
106-
bid_data = BidResults.model_validate(result.data)
107-
total_results = bid_data.total_results
108-
except Exception as e:
109-
# If validation fails, try to extract from raw data
110-
print(f"Schema validation failed: {e}")
111-
print(f"Raw result.data: {result.data}")
112-
if isinstance(result.data, dict):
113-
# Try different field names
114-
total_results = (
115-
result.data.get('total_results') or
116-
result.data.get('totalResults') or
117-
str(result.data)
118-
)
119-
else:
120-
total_results = str(result.data)
121-
elif hasattr(result, 'total_results'):
122-
# LOCAL mode format - result is the Pydantic model instance
123-
total_results = result.total_results
124-
else:
125-
# Fallback - try to get total_results from the result directly
126-
total_results = getattr(result, 'total_results', str(result))
98+
99+
# Both LOCAL and BROWSERBASE modes return the Pydantic model instance directly
100+
total_results = result.total_results
127101

128102
# Ensure we got some result
129103
assert total_results is not None, f"Failed to extract total_results from the page. Result: {result}"
@@ -177,35 +151,8 @@ async def test_wichita_browserbase(self, browserbase_stagehand):
177151

178152
result = await stagehand.page.extract(extract_options)
179153

180-
#TODO - how to unify the extract result handling between LOCAL and BROWSERBASE?
181-
182-
# Handle result based on the mode with better error handling
183-
total_results = None
184-
185-
if hasattr(result, 'data') and result.data:
186-
# BROWSERBASE mode format
187-
try:
188-
bid_data = BidResults.model_validate(result.data)
189-
total_results = bid_data.total_results
190-
except Exception as e:
191-
# If validation fails, try to extract from raw data
192-
print(f"Schema validation failed: {e}")
193-
print(f"Raw result.data: {result.data}")
194-
if isinstance(result.data, dict):
195-
# Try different field names
196-
total_results = (
197-
result.data.get('total_results') or
198-
result.data.get('totalResults') or
199-
str(result.data)
200-
)
201-
else:
202-
total_results = str(result.data)
203-
elif hasattr(result, 'total_results'):
204-
# LOCAL mode format - result is the Pydantic model instance
205-
total_results = result.total_results
206-
else:
207-
# Fallback - try to get total_results from the result directly
208-
total_results = getattr(result, 'total_results', str(result))
154+
# Both LOCAL and BROWSERBASE modes return the Pydantic model instance directly
155+
total_results = result.total_results
209156

210157
# Ensure we got some result
211158
assert total_results is not None, f"Failed to extract total_results from the page. Result: {result}"

0 commit comments

Comments
 (0)