Skip to content

Commit b136ee5

Browse files
committed
add tests and workflows
1 parent d804679 commit b136ee5

File tree

5 files changed

+111
-44
lines changed

5 files changed

+111
-44
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Upload Python Package
5+
6+
on:
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
deploy:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.x'
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install setuptools wheel twine
25+
- name: Build and publish
26+
env:
27+
TWINE_USERNAME: mvincig11
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
git fetch --all --tags
31+
python setup.py sdist bdist_wheel
32+
twine upload dist/*

.github/workflows/release.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- pre/*
7+
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Install git
14+
run: |
15+
sudo apt update
16+
sudo apt install -y git
17+
- name: Install the latest version of rye
18+
uses: eifinger/setup-rye@v3
19+
- name: Install Node Env
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
- name: Checkout
24+
uses: actions/[email protected]
25+
with:
26+
fetch-depth: 0
27+
persist-credentials: false
28+
- name: Build app
29+
run: |
30+
rye sync --no-lock
31+
rye build
32+
id: build_cache
33+
if: success()
34+
- name: Cache build
35+
uses: actions/cache@v2
36+
with:
37+
path: ./dist
38+
key: ${{ runner.os }}-build-${{ hashFiles('dist/**') }}
39+
if: steps.build_cache.outputs.id != ''
40+
41+
release:
42+
name: Release
43+
runs-on: ubuntu-latest
44+
needs: build
45+
environment: development
46+
if: |
47+
github.event_name == 'push' && github.ref == 'refs/heads/main' ||
48+
github.event_name == 'push' && github.ref == 'refs/heads/pre/beta' ||
49+
github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged && github.event.pull_request.base.ref == 'main' ||
50+
github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged && github.event.pull_request.base.ref == 'pre/beta'
51+
permissions:
52+
contents: write
53+
issues: write
54+
pull-requests: write
55+
id-token: write
56+
steps:
57+
- name: Checkout repo
58+
uses: actions/[email protected]
59+
with:
60+
fetch-depth: 0
61+
persist-credentials: false
62+
- name: Semantic Release
63+
uses: cycjimmy/[email protected]
64+
with:
65+
semantic_version: 23
66+
extra_plugins: |
67+
semantic-release-pypi@3
68+
@semantic-release/git
69+
@semantic-release/commit-analyzer@12
70+
@semantic-release/release-notes-generator@13
71+
@semantic-release/github@10
72+
@semantic-release/changelog@6
73+
conventional-changelog-conventionalcommits@7
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

tests/test_credits.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/test_feedback.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/test_scrape.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1 @@
1-
import pytest
2-
import os
3-
from dotenv import load_dotenv
4-
from pydantic import BaseModel
5-
from typing import List
6-
from scrapegraphaiapisdk.scrape import scrape
7-
8-
# Load environment variables from .env file
9-
load_dotenv()
10-
11-
class Product(BaseModel):
12-
name: str
13-
price: float
14-
description: str
15-
16-
class ProductList(BaseModel):
17-
products: List[Product]
18-
19-
def test_scrape_successful():
20-
api_key = os.getenv("SCRAPEGRAPH_API_KEY")
21-
url = "https://example.com/products"
22-
prompt = "Extract all products"
23-
schema = ProductList
24-
25-
# Mock the response
26-
with pytest.mock.patch('requests.post') as mock_post:
27-
mock_post.return_value.text = '{"products": [{"name": "Test Product", "price": 99.99, "description": "Test Description"}]}'
28-
mock_post.return_value.raise_for_status.return_value = None
29-
30-
result = scrape(api_key, url, prompt, schema)
31-
assert isinstance(result, str)
32-
assert "Test Product" in result
33-
34-
def test_scrape_invalid_api_key():
35-
api_key = "invalid_key"
36-
url = "https://example.com/products"
37-
prompt = "Extract all products"
38-
schema = ProductList
39-
40-
with pytest.mock.patch('requests.post') as mock_post:
41-
mock_post.side_effect = Exception("Invalid API key")
42-
43-
with pytest.raises(Exception):
44-
scrape(api_key, url, prompt, schema)
1+

0 commit comments

Comments
 (0)