From b5ea08a1dd85fb43bf89b06f59b1cb8166ab97e5 Mon Sep 17 00:00:00 2001 From: Aneesh Karve Date: Mon, 10 Jun 2024 18:51:20 -0700 Subject: [PATCH 1/4] measure and act on codecov --- .github/workflows/ci.yaml | 2 +- .gitignore | 1 + Makefile | 19 ++-- poetry.lock | 87 ++++++++++++++++++- pyproject.toml | 1 + pytest.ini | 3 + src/bipsea/bip85.py | 9 -- .../test-integration.sh | 0 tests/test_cli.py | 71 ++++++++++++++- tests/test_util.py | 12 +++ 10 files changed, 181 insertions(+), 24 deletions(-) rename scripts/test-readme.sh => tests/test-integration.sh (100%) mode change 100644 => 100755 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dad305b..508acc6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,4 +26,4 @@ jobs: - name: check run: make check - name: test - run: make test-ci + run: make test-all diff --git a/.gitignore b/.gitignore index a232439..2ce7afe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ *.egg-info build dist +.coverage diff --git a/Makefile b/Makefile index 20454a8..ad42e37 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,18 @@ all:: install build -test:: lint test-ci +test:: lint + poetry run pytest -n auto -test-fast:: lint - pytest -n auto +test-all:: + poetry run pytest -n auto -m "" -test-ci:: - poetry run pytest -sx -n auto +test-dist:: clean build install-dist test-integration -test-dist:: clean build install-dist test-readme +test-integration:: + pytest tests/test_cli.py::TestIntegration -m slow -n auto -REDIRECT_OUTPUT ?= > /dev/null -test-readme:: - bash scripts/test-readme.sh $(REDIRECT_OUTPUT) - -push:: test-fast git-off-main git-no-unsaved +push:: test-all git-off-main git-no-unsaved @branch=$$(git symbolic-ref --short HEAD); \ git push origin $$branch diff --git a/poetry.lock b/poetry.lock index b4f323e..cfb0761 100644 --- a/poetry.lock +++ b/poetry.lock @@ -320,6 +320,73 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "coverage" +version = "7.5.3" +description = "Code coverage measurement for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "coverage-7.5.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:a6519d917abb15e12380406d721e37613e2a67d166f9fb7e5a8ce0375744cd45"}, + {file = "coverage-7.5.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:aea7da970f1feccf48be7335f8b2ca64baf9b589d79e05b9397a06696ce1a1ec"}, + {file = "coverage-7.5.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:923b7b1c717bd0f0f92d862d1ff51d9b2b55dbbd133e05680204465f454bb286"}, + {file = "coverage-7.5.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:62bda40da1e68898186f274f832ef3e759ce929da9a9fd9fcf265956de269dbc"}, + {file = "coverage-7.5.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d8b7339180d00de83e930358223c617cc343dd08e1aa5ec7b06c3a121aec4e1d"}, + {file = "coverage-7.5.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:25a5caf742c6195e08002d3b6c2dd6947e50efc5fc2c2205f61ecb47592d2d83"}, + {file = "coverage-7.5.3-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:05ac5f60faa0c704c0f7e6a5cbfd6f02101ed05e0aee4d2822637a9e672c998d"}, + {file = "coverage-7.5.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:239a4e75e09c2b12ea478d28815acf83334d32e722e7433471fbf641c606344c"}, + {file = "coverage-7.5.3-cp310-cp310-win32.whl", hash = "sha256:a5812840d1d00eafae6585aba38021f90a705a25b8216ec7f66aebe5b619fb84"}, + {file = "coverage-7.5.3-cp310-cp310-win_amd64.whl", hash = "sha256:33ca90a0eb29225f195e30684ba4a6db05dbef03c2ccd50b9077714c48153cac"}, + {file = "coverage-7.5.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f81bc26d609bf0fbc622c7122ba6307993c83c795d2d6f6f6fd8c000a770d974"}, + {file = "coverage-7.5.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:7cec2af81f9e7569280822be68bd57e51b86d42e59ea30d10ebdbb22d2cb7232"}, + {file = "coverage-7.5.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:55f689f846661e3f26efa535071775d0483388a1ccfab899df72924805e9e7cd"}, + {file = "coverage-7.5.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:50084d3516aa263791198913a17354bd1dc627d3c1639209640b9cac3fef5807"}, + {file = "coverage-7.5.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:341dd8f61c26337c37988345ca5c8ccabeff33093a26953a1ac72e7d0103c4fb"}, + {file = "coverage-7.5.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:ab0b028165eea880af12f66086694768f2c3139b2c31ad5e032c8edbafca6ffc"}, + {file = "coverage-7.5.3-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:5bc5a8c87714b0c67cfeb4c7caa82b2d71e8864d1a46aa990b5588fa953673b8"}, + {file = "coverage-7.5.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:38a3b98dae8a7c9057bd91fbf3415c05e700a5114c5f1b5b0ea5f8f429ba6614"}, + {file = "coverage-7.5.3-cp311-cp311-win32.whl", hash = "sha256:fcf7d1d6f5da887ca04302db8e0e0cf56ce9a5e05f202720e49b3e8157ddb9a9"}, + {file = "coverage-7.5.3-cp311-cp311-win_amd64.whl", hash = "sha256:8c836309931839cca658a78a888dab9676b5c988d0dd34ca247f5f3e679f4e7a"}, + {file = "coverage-7.5.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:296a7d9bbc598e8744c00f7a6cecf1da9b30ae9ad51c566291ff1314e6cbbed8"}, + {file = "coverage-7.5.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:34d6d21d8795a97b14d503dcaf74226ae51eb1f2bd41015d3ef332a24d0a17b3"}, + {file = "coverage-7.5.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8e317953bb4c074c06c798a11dbdd2cf9979dbcaa8ccc0fa4701d80042d4ebf1"}, + {file = "coverage-7.5.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:705f3d7c2b098c40f5b81790a5fedb274113373d4d1a69e65f8b68b0cc26f6db"}, + {file = "coverage-7.5.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b1196e13c45e327d6cd0b6e471530a1882f1017eb83c6229fc613cd1a11b53cd"}, + {file = "coverage-7.5.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:015eddc5ccd5364dcb902eaecf9515636806fa1e0d5bef5769d06d0f31b54523"}, + {file = "coverage-7.5.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:fd27d8b49e574e50caa65196d908f80e4dff64d7e592d0c59788b45aad7e8b35"}, + {file = "coverage-7.5.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:33fc65740267222fc02975c061eb7167185fef4cc8f2770267ee8bf7d6a42f84"}, + {file = "coverage-7.5.3-cp312-cp312-win32.whl", hash = "sha256:7b2a19e13dfb5c8e145c7a6ea959485ee8e2204699903c88c7d25283584bfc08"}, + {file = "coverage-7.5.3-cp312-cp312-win_amd64.whl", hash = "sha256:0bbddc54bbacfc09b3edaec644d4ac90c08ee8ed4844b0f86227dcda2d428fcb"}, + {file = "coverage-7.5.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:f78300789a708ac1f17e134593f577407d52d0417305435b134805c4fb135adb"}, + {file = "coverage-7.5.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b368e1aee1b9b75757942d44d7598dcd22a9dbb126affcbba82d15917f0cc155"}, + {file = "coverage-7.5.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f836c174c3a7f639bded48ec913f348c4761cbf49de4a20a956d3431a7c9cb24"}, + {file = "coverage-7.5.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:244f509f126dc71369393ce5fea17c0592c40ee44e607b6d855e9c4ac57aac98"}, + {file = "coverage-7.5.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c4c2872b3c91f9baa836147ca33650dc5c172e9273c808c3c3199c75490e709d"}, + {file = "coverage-7.5.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:dd4b3355b01273a56b20c219e74e7549e14370b31a4ffe42706a8cda91f19f6d"}, + {file = "coverage-7.5.3-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:f542287b1489c7a860d43a7d8883e27ca62ab84ca53c965d11dac1d3a1fab7ce"}, + {file = "coverage-7.5.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:75e3f4e86804023e991096b29e147e635f5e2568f77883a1e6eed74512659ab0"}, + {file = "coverage-7.5.3-cp38-cp38-win32.whl", hash = "sha256:c59d2ad092dc0551d9f79d9d44d005c945ba95832a6798f98f9216ede3d5f485"}, + {file = "coverage-7.5.3-cp38-cp38-win_amd64.whl", hash = "sha256:fa21a04112c59ad54f69d80e376f7f9d0f5f9123ab87ecd18fbb9ec3a2beed56"}, + {file = "coverage-7.5.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:f5102a92855d518b0996eb197772f5ac2a527c0ec617124ad5242a3af5e25f85"}, + {file = "coverage-7.5.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:d1da0a2e3b37b745a2b2a678a4c796462cf753aebf94edcc87dcc6b8641eae31"}, + {file = "coverage-7.5.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8383a6c8cefba1b7cecc0149415046b6fc38836295bc4c84e820872eb5478b3d"}, + {file = "coverage-7.5.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9aad68c3f2566dfae84bf46295a79e79d904e1c21ccfc66de88cd446f8686341"}, + {file = "coverage-7.5.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2e079c9ec772fedbade9d7ebc36202a1d9ef7291bc9b3a024ca395c4d52853d7"}, + {file = "coverage-7.5.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:bde997cac85fcac227b27d4fb2c7608a2c5f6558469b0eb704c5726ae49e1c52"}, + {file = "coverage-7.5.3-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:990fb20b32990b2ce2c5f974c3e738c9358b2735bc05075d50a6f36721b8f303"}, + {file = "coverage-7.5.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:3d5a67f0da401e105753d474369ab034c7bae51a4c31c77d94030d59e41df5bd"}, + {file = "coverage-7.5.3-cp39-cp39-win32.whl", hash = "sha256:e08c470c2eb01977d221fd87495b44867a56d4d594f43739a8028f8646a51e0d"}, + {file = "coverage-7.5.3-cp39-cp39-win_amd64.whl", hash = "sha256:1d2a830ade66d3563bb61d1e3c77c8def97b30ed91e166c67d0632c018f380f0"}, + {file = "coverage-7.5.3-pp38.pp39.pp310-none-any.whl", hash = "sha256:3538d8fb1ee9bdd2e2692b3b18c22bb1c19ffbefd06880f5ac496e42d7bb3884"}, + {file = "coverage-7.5.3.tar.gz", hash = "sha256:04aefca5190d1dc7a53a4c1a5a7f8568811306d7a8ee231c42fb69215571944f"}, +] + +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + +[package.extras] +toml = ["tomli"] + [[package]] name = "crashtest" version = "0.4.1" @@ -1076,6 +1143,24 @@ tomli = {version = ">=1", markers = "python_version < \"3.11\""} [package.extras] dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "pytest-cov" +version = "5.0.0" +description = "Pytest plugin for measuring coverage." +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-cov-5.0.0.tar.gz", hash = "sha256:5837b58e9f6ebd335b0f8060eecce69b662415b16dc503883a02f45dfeb14857"}, + {file = "pytest_cov-5.0.0-py3-none-any.whl", hash = "sha256:4f0764a1219df53214206bf1feea4633c3b558a2925c8b59f144f682861ce652"}, +] + +[package.dependencies] +coverage = {version = ">=5.2.1", extras = ["toml"]} +pytest = ">=4.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] + [[package]] name = "pytest-xdist" version = "3.6.1" @@ -1467,4 +1552,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = ">=3.8.1, <4.0" -content-hash = "5d18380aa2462972e8c08f63f7a657750b13f2ee829fe65366d98b78fcd084b8" +content-hash = "0fe58380bcd0f7b0c225009db3b56babb48a18bc26981ee1ef2410cbb4cc2448" diff --git a/pyproject.toml b/pyproject.toml index 2bc23d4..03cc993 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ pycryptodome = "~3.20.0" pytest = "~8.2.1" pytest-xdist = "~3.6.1" toml = "^0.10.2" +pytest-cov = "^5.0.0" [tool.poetry.scripts] bipsea = "bipsea.bipsea:cli" diff --git a/pytest.ini b/pytest.ini index 1dc9ffa..eead285 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,3 +3,6 @@ log_cli = false log_cli_level = DEBUG testpaths = tests +addopts = --cov=bipsea --cov-report=term-missing -m "not slow" +markers = + slow: consumes wall time (deselect with '-m "not slow"') \ No newline at end of file diff --git a/src/bipsea/bip85.py b/src/bipsea/bip85.py index 21fc75d..f637fb6 100644 --- a/src/bipsea/bip85.py +++ b/src/bipsea/bip85.py @@ -6,7 +6,6 @@ from typing import Dict, Union import base58 -from ecdsa import SECP256k1 from .bip32 import VERSIONS, ExtendedKey from .bip32 import derive_key as derive_key_bip32 @@ -178,14 +177,6 @@ def split_and_validate(path: str): return segments -def validate_key(entropy: bytes): - """per BIP-85 we should hard fail under these conditions""" - assert len(entropy) == 32 - int_key = int.from_bytes(entropy, "big") - if not int_key or int_key > SECP256k1.order: - raise ValueError("Invalid derived key. Try again with next child index.") - - def do_rolls(entropy: bytes, sides: int, rolls: int, index: int) -> str: """sides > 1, 1 < rolls > 100""" max_width = len(str(sides - 1)) diff --git a/scripts/test-readme.sh b/tests/test-integration.sh old mode 100644 new mode 100755 similarity index 100% rename from scripts/test-readme.sh rename to tests/test-integration.sh diff --git a/tests/test_cli.py b/tests/test_cli.py index 704b63d..94a682a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,5 +1,10 @@ import logging import random +import subprocess +import sys +import tempfile +from io import StringIO +from pathlib import Path import pytest from click.testing import CliRunner @@ -16,7 +21,7 @@ from bipsea.bip32types import validate_prv from bipsea.bip39 import LANGUAGES, validate_mnemonic_words -from bipsea.bipsea import ISO_TO_LANGUAGE, N_WORDS_ALLOWED, cli +from bipsea.bipsea import ISO_TO_LANGUAGE, N_WORDS_ALLOWED, cli, try_for_pipe_input from bipsea.util import ASCII_INPUTS, LOGGER_NAME logger = logging.getLogger(LOGGER_NAME) @@ -269,7 +274,7 @@ def test_bad_xprv(self, runner): class TestIntegration: - def test_chain_all_commands(self, runner): + def test_chain_no_pipe(self, runner): """this also tests that the default options are compatible""" mnemonic_result = runner.invoke(cli, ["mnemonic"]) assert mnemonic_result.exit_code == 0 @@ -302,3 +307,65 @@ def test_too_short_inputs(self, runner, input): bad_x_result = runner.invoke(cli, ["derive", "-x", input, "-a", "base85"]) assert bad_x_result.exit_code != 0 assert "Error" in bad_x_result.output + + def test_try_for_pipe_input(self, monkeypatch): + test_input = "test input" + monkeypatch.setattr(sys, "stdin", StringIO(test_input)) + monkeypatch.setattr(sys.stdin, "isatty", lambda: False) + assert try_for_pipe_input() == test_input.strip() + + monkeypatch.setattr(sys.stdin, "isatty", lambda: True) + assert try_for_pipe_input() == "" + + @pytest.mark.parametrize( + "cmd, opt", [("validate", "-m"), ("derive", "-m"), ("xprv", "-x")] + ) + def test_no_m(self, runner, cmd, opt): + result = runner.invoke(cli, [cmd, opt]) + assert result.exit_code != 0 + assert "Error" in result.output + + commands = [ + "bipsea --version", + "bipsea --help", + "bipsea mnemonic --help", + "bipsea validate --help", + "bipsea xprv --help", + "bipsea derive --help", + "bipsea mnemonic | bipsea validate | bipsea xprv | bipsea derive -a mnemonic -n 12", + "bipsea mnemonic -t jpn -n 15", + "bipsea mnemonic -n 12 --pretty", + "bipsea mnemonic -t spa -n 12 | bipsea validate -f spa", + "bipsea mnemonic | bipsea validate", + "bipsea mnemonic | bipsea validate | bipsea xprv", + 'bipsea xprv -m "elder major green sting survey canoe inmate funny bright jewel anchor volcano" | bipsea derive -a mnemonic -n 12', + 'bipsea validate -f free -m "123456123456123456" | bipsea xprv', + 'bipsea validate -f free -m "$(cat input.txt)"', + 'bipsea validate -m "elder major green sting survey canoe inmate funny bright jewel anchor volcano" | bipsea xprv | bipsea derive -a base85', + 'bipsea validate -m "elder major green sting survey canoe inmate funny bright jewel anchor volcano" | bipsea xprv | bipsea derive -a mnemonic -t jpn -n 12', + 'bipsea validate -m "elder major green sting survey canoe inmate funny bright jewel anchor volcano" | bipsea xprv | bipsea derive -a drng -n 1000', + 'bipsea validate -m "elder major green sting survey canoe inmate funny bright jewel anchor volcano" | bipsea xprv | bipsea derive -a dice -n 100 -s 6', + ] + + @pytest.mark.slow + @pytest.mark.parametrize( + "command", + commands, + ids=lambda cmd: (cmd[:32] + "...") if len(cmd) > 32 else cmd, + ) + def test_commands(self, command): + with tempfile.NamedTemporaryFile("w", suffix=".sh", delete=True) as script: + script.write("#!/bin/sh\n") + script.write(command + "\n") + script.flush() + Path(script.name).chmod(0o755) + + result = subprocess.run( + ["poetry", "run", script.name], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + assert ( + result.returncode == 0 + ), f"Command failed: {command}\nOutput: {result.stdout}\nError: {result.stderr}" diff --git a/tests/test_util.py b/tests/test_util.py index 3320490..6905c5c 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -11,6 +11,7 @@ relative_entropy, shannon_entropy, shuffle, + to_hex_string, ) logger = logging.getLogger(LOGGER_NAME) @@ -39,3 +40,14 @@ def test_contains_only_ascii(): def test_shuffle(): shuffled = shuffle(deck_52()) assert shuffled != deck_52() + + +def test_bad_relatve_entropy(): + with pytest.warns(UserWarning, match="outside"): + relative_entropy("λ") + + +def test_to_hex_string(): + data = b"\x00\xff\x10\x20" + expected = "00ff1020" + assert to_hex_string(data) == expected From 9ad99b2a96186ea73e6446bc37aab07367074950 Mon Sep 17 00:00:00 2001 From: Aneesh Karve Date: Mon, 10 Jun 2024 18:53:07 -0700 Subject: [PATCH 2/4] whitespace --- pytest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index eead285..46b1bf7 100644 --- a/pytest.ini +++ b/pytest.ini @@ -5,4 +5,4 @@ testpaths = tests addopts = --cov=bipsea --cov-report=term-missing -m "not slow" markers = - slow: consumes wall time (deselect with '-m "not slow"') \ No newline at end of file + slow: consumes wall time (deselect with '-m "not slow"') From 2150481bfd41c4c73b04368ab5732be717478031 Mon Sep 17 00:00:00 2001 From: Aneesh Karve Date: Mon, 10 Jun 2024 18:56:26 -0700 Subject: [PATCH 3/4] poetry run pytest --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ad42e37..2593061 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ test-all:: test-dist:: clean build install-dist test-integration test-integration:: - pytest tests/test_cli.py::TestIntegration -m slow -n auto + poetry run pytest "tests/test_cli.py::TestIntegration" -m "" -n auto push:: test-all git-off-main git-no-unsaved @branch=$$(git symbolic-ref --short HEAD); \ From 53c9ad22b8573371b0b8ad02c8c77ea402305d52 Mon Sep 17 00:00:00 2001 From: Aneesh Karve Date: Mon, 10 Jun 2024 19:03:06 -0700 Subject: [PATCH 4/4] close file bfore execute --- tests/test_cli.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 94a682a..aea805e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -354,18 +354,24 @@ def test_no_m(self, runner, cmd, opt): ids=lambda cmd: (cmd[:32] + "...") if len(cmd) > 32 else cmd, ) def test_commands(self, command): - with tempfile.NamedTemporaryFile("w", suffix=".sh", delete=True) as script: + with tempfile.NamedTemporaryFile("w", suffix=".sh", delete=False) as script: script.write("#!/bin/sh\n") script.write(command + "\n") script.flush() - Path(script.name).chmod(0o755) + Path(script.name).chmod(0o755) + + try: result = subprocess.run( ["poetry", "run", script.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, ) - assert ( - result.returncode == 0 - ), f"Command failed: {command}\nOutput: {result.stdout}\nError: {result.stderr}" + assert result.returncode == 0, ( + f"Command failed: {command}\n" + f"Output: {result.stdout}\n" + f"Error: {result.stderr}" + ) + finally: + Path(script.name).unlink()