Skip to content

Commit

Permalink
Adding Test Cases & Cache Updates (#18)
Browse files Browse the repository at this point in the history
* adding caching usage

* Addomg first test cases for Bullet class

* Adding documentation to tests

* Updating test script name to better match the class

* Adding check tests

* Adding documentation for check tests

* first revision of tests for client

* adding documentation to tests

* Adding cursor tests

* Adding keyhandler tests

* Adding utils tests and updated getchar with optimizations/corrections

* adding pytest to pre-commit and fixing the test file names

* Adding validation workflow

* adding pip install

* removing caching for tests

* Adding required packages

* version bump
  • Loading branch information
danner26 authored Jan 22, 2025
1 parent 8376fa1 commit 3ef4dbb
Show file tree
Hide file tree
Showing 22 changed files with 2,239 additions and 36 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
if: steps.cache-venv.outputs.cache-hit != 'true'
build-pytest-cache:
name: Build PyTest Cache
build-publish-cache:
name: Build Publish Cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -45,16 +45,16 @@ jobs:
python-version: '3.12'
- name: cache virtualenv
uses: actions/cache@v4
id: cache-venv-pytest
id: cache-venv-publish
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-pytest-${{ hashFiles('requirements.txt') }}
key: ${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-publish-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-pytest-
${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-publish-
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install pytest-github-actions-annotate-failures
if: steps.cache-venv-pytest.outputs.cache-hit != 'true'
if: steps.cache-venv-publish.outputs.cache-hit != 'true'
28 changes: 26 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,26 @@ jobs:
previous_tag: ${{ steps.check_pypi.outputs.previous_tag }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v5
id: setup_python
with:
python-version: "3.12"
- name: cache virtualenv
uses: actions/cache@v4
id: cache-venv-publish
with:
python-version: "3.x"
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-publish-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-publish-
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install setuptools wheel ultralytics-actions
if: steps.cache-venv-publish.outputs.cache-hit != 'true'
- id: check_pypi
shell: python3 -u {0}
run: |
Expand Down Expand Up @@ -67,14 +79,26 @@ jobs:
id-token: write # for PyPI trusted publishing
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v5
id: setup_python
with:
python-version: "3.12"
- name: cache virtualenv
uses: actions/cache@v4
id: cache-venv-publish
with:
python-version: "3.x"
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-publish-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-publish-
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install setuptools wheel
if: steps.cache-venv-publish.outputs.cache-hit != 'true'
- name: Build package
run: |
python3 setup.py sdist bdist_wheel
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: Validate definitions
on:
pull_request:
branches:
- master
jobs:
format-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Python
uses: actions/setup-python@v5
id: setup_python
with:
python-version: '3.12'
- name: cache virtualenv
uses: actions/cache@v4
id: cache-venv
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.pythonLocation }}-
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
if: steps.cache-venv.outputs.cache-hit != 'true'
- name: Run Ruff Formatting and Checks
uses: astral-sh/ruff-action@v3
with:
args: "format --check"
test:
runs-on: ubuntu-latest
needs: [format-checks]
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Python
uses: actions/setup-python@v5
id: setup_python
with:
python-version: '3.12'
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install pytest-github-actions-annotate-failures
python -m pip install .
- name: Run Test Cases
id: pytest
run: pytest --tb=short -v
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ __pycache__/
# C extensions
*.so
.DS_Store
# Tests
tests/
# Distribution / packaging
.Python
build/
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "tests"]
path = tests
url = https://github.com/danner26/BulletPrompt
branch = master/tests
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ repos:
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: local
hooks:
- id: pytest
name: Run PyTest Case Checks
entry: pytest
language: system
args: [--tb=short, -v]
pass_filenames: false
always_run: true
2 changes: 1 addition & 1 deletion bullet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.2.2"
__version__ = "2.2.3"

from .client import Bullet # noqa: F401
from .client import Check # noqa: F401
Expand Down
32 changes: 7 additions & 25 deletions bullet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,23 @@ def mygetc():
def getchar():
"""Character input parser."""
c = mygetc()
if (
ord(c) == LINE_BEGIN_KEY # noqa: F405
or ord(c) == LINE_END_KEY # noqa: F405
or ord(c) == TAB_KEY # noqa: F405
or ord(c) == INTERRUPT_KEY # noqa: F405
or ord(c) == NEWLINE_KEY # noqa: F405
):
if ord(c) in {LINE_BEGIN_KEY, LINE_END_KEY, TAB_KEY, INTERRUPT_KEY, NEWLINE_KEY, BACK_SPACE_KEY}: # noqa: F405
return c

elif ord(c) == BACK_SPACE_KEY: # noqa: F405
return c

elif ord(c) == ESC_KEY: # noqa: F405
if ord(c) == ESC_KEY: # noqa: F405
combo = mygetc()
if ord(combo) == MOD_KEY_INT: # noqa: F405
key = mygetc()
if ord(key) >= MOD_KEY_BEGIN - MOD_KEY_FLAG and ord(key) <= MOD_KEY_END - MOD_KEY_FLAG: # noqa: F405
if MOD_KEY_BEGIN - MOD_KEY_FLAG <= ord(key) <= MOD_KEY_END - MOD_KEY_FLAG: # noqa: F405
if ord(mygetc()) == MOD_KEY_DUMMY: # noqa: F405
return chr(ord(key) + MOD_KEY_FLAG) # noqa: F405
else:
return UNDEFINED_KEY # noqa: F405
elif ord(key) >= ARROW_KEY_BEGIN - ARROW_KEY_FLAG and ord(key) <= ARROW_KEY_END - ARROW_KEY_FLAG: # noqa: F405
return chr(ord(key) + ARROW_KEY_FLAG) # noqa: F405
else:
return UNDEFINED_KEY # noqa: F405
else:
return getchar()

else:
if is_printable(c):
return c
else:
if ARROW_KEY_BEGIN - ARROW_KEY_FLAG <= ord(key) <= ARROW_KEY_END - ARROW_KEY_FLAG: # noqa: F405
return chr(ord(key) + ARROW_KEY_FLAG) # noqa: F405
return UNDEFINED_KEY # noqa: F405
return getchar()

return UNDEFINED_KEY # noqa: F405
return c if is_printable(c) else UNDEFINED_KEY # noqa: F405


# Basic command line functions
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dev = [
"ruff",
"pytest",
"pre-commit",
"pytest-mock",
"uv",
]

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pre_commit==4.1.0
pytest==8.3.4
pytest-mock==3.14.0
ruff==0.9.2
uv==0.5.22
Loading

0 comments on commit 3ef4dbb

Please sign in to comment.