From 3b6dfdab3eb58d35735d0149d480cc9488548ff6 Mon Sep 17 00:00:00 2001 From: Jacques Raphanel <147158906+TheCrab13@users.noreply.github.com> Date: Sun, 10 Mar 2024 18:59:14 +0100 Subject: [PATCH] test: add dedicated compression test when supported (#14) --- .github/workflows/test.yml | 25 ++++++------------------- tests/cli/test_add.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78615aa..03de0a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,38 +32,25 @@ jobs: - version: "3.10" toxenv: py310 - version: "3.11" - toxenv: py311 + toxenv: py311,cli include: - os: windows-latest python: version: "3.11" - toxenv: py311 + toxenv: py311,cli steps: - uses: actions/checkout@v4.1.0 - name: Set up Python ${{ matrix.python.version }} uses: actions/setup-python@v4.7.0 with: python-version: ${{ matrix.python.version }} + - name: Install gcab + if: ${{ matrix.os == 'ubuntu-latest' }} + run: sudo apt-get install -y gcab - name: Install dependencies run: pip install tox - name: Run tests - run: tox -e ${{ matrix.python.toxenv }} --skip-missing-interpreters false - - functional: - runs-on: ubuntu-22.04 - strategy: - matrix: - toxenv: [cli] - steps: - - uses: actions/checkout@v4.1.0 - - name: Set up Python - uses: actions/setup-python@v4.7.0 - with: - python-version: "3.11" - - name: Install dependencies - run: pip install tox - - name: Run tests - run: tox -e ${{ matrix.toxenv }} -- --override-ini='log_cli=True' + run: tox -e ${{ matrix.python.toxenv }} -- --override-ini='log_cli=True' coverage: runs-on: ubuntu-22.04 diff --git a/tests/cli/test_add.py b/tests/cli/test_add.py index ec26fa5..71d1141 100644 --- a/tests/cli/test_add.py +++ b/tests/cli/test_add.py @@ -1,3 +1,4 @@ +from pathlib import Path from unittest import mock import pytest @@ -11,6 +12,7 @@ ERROR_UNEXPECTED, SUCCESS, ) +from pdbstore.io import cab def test_incomplete_no_action(): @@ -155,3 +157,38 @@ def test_no_compression(tmp_store_dir, test_data_native_dir): # Test with direct call to main function assert cli.main(["add"] + argv) == ERROR_GENERAL + + +@pytest.mark.skipif(cab.compress is None, reason="compression not available") +def test_valid_compression(tmp_store_dir, test_data_native_dir): + """test add command when compression is supported""" + argv = [ + "--store-dir", + str(tmp_store_dir), + "--product-name", + "myproduct", + "--product-version", + "1.0.0", + "--compress", + str(test_data_native_dir / "dummyapp.pdb"), + ] + + # Test through direct command-line + with mock.patch( + "sys.argv", + ["pdbstore", "add"] + argv, + ): + assert cli.main() == SUCCESS + + stored_path: Path = ( + tmp_store_dir + / "dummyapp.pdb" + / "DBF7CE25C6DC4E0EA9AD889187E296A21" + / "dummyapp.pd_" + ) + assert stored_path.exists() is True + with stored_path.open("rb") as fpsp: + assert fpsp.read(4) == b"MSCF" + + # Test with direct call to main function + assert cli.main(["add"] + argv) == SUCCESS