From 54254c25b546d6a947a0ef915c2b6b6d9478af26 Mon Sep 17 00:00:00 2001 From: MountainGod2 Date: Mon, 1 Apr 2024 19:23:29 -0600 Subject: [PATCH] test: update ci-cd.yml and test_main.py --- .github/workflows/ci-cd.yml | 41 ++++++++++++------------------------- tests/test_main.py | 23 --------------------- 2 files changed, 13 insertions(+), 51 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 4145ae9d..916b6ae4 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -6,35 +6,22 @@ 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 @@ -42,10 +29,8 @@ jobs: - 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 diff --git a/tests/test_main.py b/tests/test_main.py index 8dde483c..dc9b0143 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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