Skip to content

Commit 33d6f2c

Browse files
authored
Merge pull request #2 from pomponchik/develop
0.0.2
2 parents e8cc58a + 679748d commit 33d6f2c

File tree

8 files changed

+87
-10
lines changed

8 files changed

+87
-10
lines changed

.github/workflows/tests_and_coverage.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tests
1+
name: New tests
22

33
on:
44
push
@@ -9,8 +9,8 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010
strategy:
1111
matrix:
12-
os: [macos-13, ubuntu-latest, windows-latest]
13-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
12+
os: [macos-latest, ubuntu-latest, windows-latest]
13+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
1414

1515
steps:
1616
- uses: actions/checkout@v2
@@ -43,3 +43,6 @@ jobs:
4343
find . -iregex "codecov.*"
4444
chmod +x codecov
4545
./codecov -t ${CODECOV_TOKEN}
46+
47+
- name: Run tests and show the branch coverage on the command line
48+
run: coverage run --source=suby --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Old tests
2+
3+
on:
4+
push
5+
6+
jobs:
7+
build:
8+
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [macos-13, ubuntu-latest, windows-latest]
13+
python-version: ['3.7']
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
22+
- name: Install the library
23+
shell: bash
24+
run: pip install .
25+
26+
- name: Install dependencies
27+
shell: bash
28+
run: pip install -r requirements_dev.txt
29+
30+
- name: Print all libs
31+
shell: bash
32+
run: pip list
33+
34+
- name: Run tests and show coverage on the command line
35+
run: coverage run --source=suby --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m
36+
37+
- name: Upload reports to codecov
38+
env:
39+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
40+
if: runner.os == 'Linux'
41+
run: |
42+
curl -Os https://uploader.codecov.io/latest/linux/codecov
43+
find . -iregex "codecov.*"
44+
chmod +x codecov
45+
./codecov -t ${CODECOV_TOKEN}
46+
47+
- name: Run tests and show the branch coverage on the command line
48+
run: coverage run --source=suby --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ print(result)
7070
# > SubprocessResult(id='e9f2d29acb4011ee8957320319d7541c', stdout='hello, world!\n', stderr='', returncode=0, killed_by_token=False)
7171
```
7272

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

7476
## Output
7577

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

203205
## Timeouts
204206

205-
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:
207+
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:
206208

207209
```python
208210
import suby

docs/assets/logo_6.png

13.5 KB
Loading

docs/assets/logo_7.png

14.6 KB
Loading

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "suby"
7-
version = "0.0.1"
7+
version = "0.0.2"
88
authors = [
99
{ name="Evgeniy Blinov", email="zheni-b@yandex.ru" },
1010
]
1111
description = 'Slightly simplified subprocesses'
1212
readme = "README.md"
1313
requires-python = ">=3.7"
1414
dependencies = [
15-
'emptylog>=0.0.3',
15+
'emptylog>=0.0.7',
1616
'cantok>=0.0.18',
1717
]
1818
classifiers = [

requirements_dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ twine==4.0.2
55
mypy==1.4.1
66
ruff==0.0.290
77
mutmut==2.4.4
8-
emptylog>=0.0.3
8+
emptylog>=0.0.7
9+
full_match==0.0.1

tests/test_proxy_module.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from time import perf_counter
44
from io import StringIO
55
from contextlib import redirect_stdout, redirect_stderr
6+
from pathlib import Path
67

78
import pytest
9+
import full_match
810
from cantok import TimeoutCancellationError, ConditionCancellationError, ConditionToken, SimpleToken
911
from emptylog import MemoryLogger
1012

@@ -68,7 +70,7 @@ def test_timeout_without_catching_exception():
6870

6971
start_time = perf_counter()
7072
try:
71-
result = suby(sys.executable, '-c', f'import time; time.sleep({sleep_time})', timeout=timeout)
73+
suby(sys.executable, '-c', f'import time; time.sleep({sleep_time})', timeout=timeout)
7274
except TimeoutCancellationError as e:
7375
assert e.result.stdout == ''
7476
assert e.result.stderr == ''
@@ -145,7 +147,7 @@ def test_logging_with_expired_timeout():
145147
def test_logging_with_exception():
146148
logger = MemoryLogger()
147149

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

150152
assert len(logger.data.info) == 1
151153
assert len(logger.data.error) == 1
@@ -171,7 +173,7 @@ def test_logging_with_exception_without_catching_exceptions():
171173
logger = MemoryLogger()
172174

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

176178
assert len(logger.data.info) == 1
177179
assert len(logger.data.error) == 1
@@ -308,3 +310,24 @@ def test_replace_stderr_callback():
308310

309311
assert stderr_buffer.getvalue() == ''
310312
assert stdout_buffer.getvalue() == ''
313+
314+
315+
@pytest.mark.parametrize(
316+
['arguments', 'exception_message'],
317+
(
318+
([None], 'Only strings and pathlib.Path objects can be positional arguments when calling the suby function. You passed "None" (NoneType).'),
319+
([1], 'Only strings and pathlib.Path objects can be positional arguments when calling the suby function. You passed "1" (int).'),
320+
(['python', 1], 'Only strings and pathlib.Path objects can be positional arguments when calling the suby function. You passed "1" (int).'),
321+
),
322+
)
323+
def test_pass_wrong_positional_argument(arguments, exception_message):
324+
with pytest.raises(TypeError, match=full_match(exception_message)):
325+
suby(*arguments)
326+
327+
328+
def test_use_path_object_as_first_positional_argument():
329+
result = suby(Path(sys.executable), '-c', 'print("kek")')
330+
331+
assert result.stdout == 'kek\n'
332+
assert result.stderr == ''
333+
assert result.returncode == 0

0 commit comments

Comments
 (0)