Skip to content

Commit

Permalink
Merge pull request #2 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.2
  • Loading branch information
pomponchik authored Jul 15, 2024
2 parents e8cc58a + 679748d commit 33d6f2c
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 10 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: New tests

on:
push
Expand All @@ -9,8 +9,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-13, ubuntu-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -43,3 +43,6 @@ jobs:
find . -iregex "codecov.*"
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
- name: Run tests and show the branch coverage on the command line
run: coverage run --source=suby --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
48 changes: 48 additions & 0 deletions .github/workflows/tests_and_coverage_old.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Old tests

on:
push

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-13, ubuntu-latest, windows-latest]
python-version: ['3.7']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install the library
shell: bash
run: pip install .

- name: Install dependencies
shell: bash
run: pip install -r requirements_dev.txt

- name: Print all libs
shell: bash
run: pip list

- name: Run tests and show coverage on the command line
run: coverage run --source=suby --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m

- name: Upload reports to codecov
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
if: runner.os == 'Linux'
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
find . -iregex "codecov.*"
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
- name: Run tests and show the branch coverage on the command line
run: coverage run --source=suby --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ print(result)
# > SubprocessResult(id='e9f2d29acb4011ee8957320319d7541c', stdout='hello, world!\n', stderr='', returncode=0, killed_by_token=False)
```

You can use strings or [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path) objects as positional arguments for `suby`.


## Output

Expand Down Expand Up @@ -202,7 +204,7 @@ print(suby('python', '-c', 'import time; time.sleep(10_000)', token=token, catch

## Timeouts

You can set a timeout for `suby`. It must be an integer greater than zero, which indicates the number of seconds that the sub process can continue to run. If the timeout expires before the subprocess completes, an exception will be raised:
You can set a timeout for `suby`. It must be an integer greater than zero, which indicates the number of seconds that the subprocess can continue to run. If the timeout expires before the subprocess completes, an exception will be raised:

```python
import suby
Expand Down
Binary file added docs/assets/logo_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/logo_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ build-backend = "setuptools.build_meta"

[project]
name = "suby"
version = "0.0.1"
version = "0.0.2"
authors = [
{ name="Evgeniy Blinov", email="[email protected]" },
]
description = 'Slightly simplified subprocesses'
readme = "README.md"
requires-python = ">=3.7"
dependencies = [
'emptylog>=0.0.3',
'emptylog>=0.0.7',
'cantok>=0.0.18',
]
classifiers = [
Expand Down
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ twine==4.0.2
mypy==1.4.1
ruff==0.0.290
mutmut==2.4.4
emptylog>=0.0.3
emptylog>=0.0.7
full_match==0.0.1
29 changes: 26 additions & 3 deletions tests/test_proxy_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from time import perf_counter
from io import StringIO
from contextlib import redirect_stdout, redirect_stderr
from pathlib import Path

import pytest
import full_match
from cantok import TimeoutCancellationError, ConditionCancellationError, ConditionToken, SimpleToken
from emptylog import MemoryLogger

Expand Down Expand Up @@ -68,7 +70,7 @@ def test_timeout_without_catching_exception():

start_time = perf_counter()
try:
result = suby(sys.executable, '-c', f'import time; time.sleep({sleep_time})', timeout=timeout)
suby(sys.executable, '-c', f'import time; time.sleep({sleep_time})', timeout=timeout)
except TimeoutCancellationError as e:
assert e.result.stdout == ''
assert e.result.stderr == ''
Expand Down Expand Up @@ -145,7 +147,7 @@ def test_logging_with_expired_timeout():
def test_logging_with_exception():
logger = MemoryLogger()

suby(sys.executable, '-c', f'1/0', logger=logger, catch_exceptions=True, catch_output=True)
suby(sys.executable, '-c', '1/0', logger=logger, catch_exceptions=True, catch_output=True)

assert len(logger.data.info) == 1
assert len(logger.data.error) == 1
Expand All @@ -171,7 +173,7 @@ def test_logging_with_exception_without_catching_exceptions():
logger = MemoryLogger()

with pytest.raises(RunningCommandError):
suby(sys.executable, '-c', f'1/0', logger=logger, catch_output=True)
suby(sys.executable, '-c', '1/0', logger=logger, catch_output=True)

assert len(logger.data.info) == 1
assert len(logger.data.error) == 1
Expand Down Expand Up @@ -308,3 +310,24 @@ def test_replace_stderr_callback():

assert stderr_buffer.getvalue() == ''
assert stdout_buffer.getvalue() == ''


@pytest.mark.parametrize(
['arguments', 'exception_message'],
(
([None], 'Only strings and pathlib.Path objects can be positional arguments when calling the suby function. You passed "None" (NoneType).'),
([1], 'Only strings and pathlib.Path objects can be positional arguments when calling the suby function. You passed "1" (int).'),
(['python', 1], 'Only strings and pathlib.Path objects can be positional arguments when calling the suby function. You passed "1" (int).'),
),
)
def test_pass_wrong_positional_argument(arguments, exception_message):
with pytest.raises(TypeError, match=full_match(exception_message)):
suby(*arguments)


def test_use_path_object_as_first_positional_argument():
result = suby(Path(sys.executable), '-c', 'print("kek")')

assert result.stdout == 'kek\n'
assert result.stderr == ''
assert result.returncode == 0

0 comments on commit 33d6f2c

Please sign in to comment.