Skip to content

Commit

Permalink
test: update ci-cd.yml and test_main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MountainGod2 committed Apr 2, 2024
1 parent 77c3f93 commit 54254c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 51 deletions.
41 changes: 13 additions & 28 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,31 @@ jobs:
ci:
# Set up operating system
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Poetry
uses: snok/install-poetry@v1
# Define job steps
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
python-version: "3.10"

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Check-out repository
uses: actions/checkout@v3

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install poetry
uses: snok/install-poetry@v1

- name: Install project
run: poetry install --no-interaction
- name: Install package
run: poetry install

- name: Format with ruff
run: poetry run ruff format

- name: Lint with ruff
run: poetry run ruff check --fix

- name: Run tests
run: |
source .venv/bin/activate
pytest tests/ --cov=chaturbate_poller --cov-report=xml
- name: Test with pytest
run: poetry run pytest tests/ --cov=chaturbate_poller --cov-report=xml

- name: Use Codecov to track coverage
uses: codecov/codecov-action@v3
Expand Down
23 changes: 0 additions & 23 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,3 @@ async def test_keyboard_interrupt_handling(mocker: MockerFixture) -> None:
logger_mock.assert_called_once_with("Cancelled fetching Chaturbate events.")


def test_script_as_main() -> None:
"""Test running the script as the main module."""
process = subprocess.Popen(
["python", "-m", "chaturbate_poller"], # noqa: S603, S607
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)

# Increase sleep time to ensure the script has started
time.sleep(1)

# Send a KeyboardInterrupt signal to the process
process.send_signal(signal.SIGINT)

stdout, stderr = process.communicate()

# Additional debugging output

assert ( # noqa: S101
process.returncode == 0
), f"Script did not exit cleanly, return code: {process.returncode}"
assert "Stopping cb_poller module." in stderr, "KeyboardInterrupt not handled" # noqa: S101

0 comments on commit 54254c2

Please sign in to comment.