Skip to content

Commit e03e725

Browse files
committed
adding workflows/actions to test code and release
1 parent 56e2a42 commit e03e725

File tree

3 files changed

+155
-23
lines changed

3 files changed

+155
-23
lines changed

.github/workflows/pylint.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: PyUIKit testing + Release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
# 1️⃣ Test job
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: ["3.10", "3.11"]
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -e . # editable install
27+
pip install pytest
28+
29+
- name: Run tests
30+
run: pytest tests
31+
32+
# 2️⃣ Release job (runs only if test job passes)
33+
release:
34+
runs-on: ubuntu-latest
35+
needs: test # only run if tests passed
36+
steps:
37+
- name: Checkout repo
38+
uses: actions/checkout@v4
39+
40+
- name: Setup Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: "3.11"
44+
45+
- name: Install build tools
46+
run: |
47+
python -m pip install --upgrade pip
48+
pip install build twine
49+
50+
- name: Get current version from setup.py
51+
id: get_version
52+
run: |
53+
VERSION=$(python -c "import re; import setuptools; f=open('setup.py'); print(re.search(r'version\s*=\s*[\"\\'](.+?)[\"\\']', f.read()).group(1))")
54+
echo "Version=${VERSION}" >> $GITHUB_ENV
55+
56+
- name: Check if version changed
57+
id: version_check
58+
run: |
59+
LAST_TAG=$(git describe --tags --abbrev=0 || echo "0.0.0")
60+
echo "Last tag: $LAST_TAG"
61+
echo "Current version: $VERSION"
62+
if [ "$LAST_TAG" = "v$VERSION" ]; then
63+
echo "Version not changed, skipping release."
64+
exit 78 # neutral
65+
fi
66+
67+
- name: Build distribution
68+
run: python -m build
69+
70+
- name: Publish to PyPI
71+
uses: pypa/gh-action-pypi-publish@release/v1
72+
with:
73+
password: ${{ secrets.PYPI_API_TOKEN }}

tests/test_initial.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# --- 1️⃣ Test top-level import ---
2+
def test_top_level_import():
3+
import pyuikit
4+
5+
6+
# --- 2️⃣ Test components import ---
7+
def test_components_importable():
8+
from pyuikit import Body, Div
9+
from pyuikit.components import Text, Button, Input
10+
11+
# Simple assertions to make sure they exist
12+
assert Body is not None
13+
assert Div is not None
14+
assert Text is not None
15+
assert Button is not None
16+
assert Input is not None
17+
18+
19+
# --- 3️⃣ Test container creation ---
20+
def test_body_creation():
21+
from pyuikit import Body
22+
23+
app = Body(width=400, height=300, bg_color='white')
24+
assert app.width == 400
25+
assert app.height == 300
26+
assert app.bg_color == 'white'
27+
28+
29+
def test_div_creation():
30+
from pyuikit import Div
31+
from pyuikit.components import Text, Input, Button
32+
33+
btn = Button(text='Click me')
34+
div = Div(
35+
width=360,
36+
height=250,
37+
children=[
38+
Text(text='Enter your name:'),
39+
Input(placeholder='Name', id='name_input'),
40+
btn,
41+
]
42+
)
43+
44+
assert div.width == 360
45+
assert div.height == 250
46+
assert len(div.children) == 3
47+
assert div.children[2] is btn
48+
49+
50+
# --- 4️⃣ Test Input/Text/Button logic (simulate greet function) ---
51+
def test_greet_logic():
52+
from pyuikit.components import Text, Input, Button
53+
54+
# Mock the input
55+
Input._mock_inputs = {"name_input": "Alice"} # simulate user input
56+
greeting_text = Text(text='', id='greeting')
57+
58+
def greet():
59+
name = Input.get_input(id='name_input')
60+
Text.set_text(id='greeting', new_text=f'Hello, {name}!')
61+
62+
greet() # call the function
63+
64+
# Check if greeting text updated correctly
65+
assert Text.get_text(id='greeting') == "Hello, Alice!"
66+
67+
68+
# --- 5️⃣ Optional: Test button on_click triggers greet ---
69+
def test_button_on_click_triggers_greet():
70+
from pyuikit.components import Text, Input, Button
71+
72+
Input._mock_inputs = {"name_input": "Bob"}
73+
Text.set_text(id='greeting', new_text='')
74+
75+
def greet():
76+
name = Input.get_input(id='name_input')
77+
Text.set_text(id='greeting', new_text=f'Hello, {name}!')
78+
79+
btn = Button(text='Greet', on_click=greet)
80+
btn._trigger_click() # simulate click
81+
82+
assert Text.get_text(id='greeting') == "Hello, Bob!"

0 commit comments

Comments
 (0)