Skip to content

Commit 4cf69a7

Browse files
authored
Merge pull request #4 from pomponchik/develop
0.0.4
2 parents 501bb60 + 443d8c1 commit 4cf69a7

5 files changed

Lines changed: 126 additions & 5 deletions

File tree

.github/workflows/tests_and_coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Run tests and show coverage on the command line
3535
run: |
36-
coverage run --source=transfunctions --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=80
36+
coverage run --source=transfunctions --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=90
3737
coverage xml
3838
3939
- name: Upload coverage to Coveralls
@@ -46,4 +46,4 @@ jobs:
4646
file: coverage.xml
4747

4848
- name: Run tests and show the branch coverage on the command line
49-
run: coverage run --branch --source=transfunctions --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=80
49+
run: coverage run --branch --source=transfunctions --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=90

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "transfunctions"
7-
version = "0.0.3"
7+
version = "0.0.4"
88
authors = [
99
{ name="Evgeniy Blinov", email="zheni-b@yandex.ru" },
1010
]

tests/units/decorators/test_superfunction.py

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from contextlib import redirect_stdout
44

55
import pytest
6+
import full_match
67

7-
from transfunctions import superfunction, sync_context, async_context, generator_context
8+
from transfunctions import superfunction, sync_context, async_context, generator_context, await_it, WrongDecoratorSyntaxError
89

910
"""
1011
Что нужно проверить:
@@ -153,3 +154,97 @@ def function(a, b, c=4, d=3):
153154

154155
with pytest.raises(ValueError):
155156
~function(2, 3, d=5)
157+
158+
159+
def test_return_value_from_async_simple_superfunction():
160+
@superfunction
161+
def function():
162+
return 1
163+
164+
assert run(function()) == 1
165+
166+
167+
def test_return_awaited_value_from_async_simple_superfunction():
168+
async def another_one():
169+
return 1
170+
171+
@superfunction
172+
def function():
173+
return await_it(another_one())
174+
175+
assert run(function()) == 1
176+
177+
178+
def test_return_value_from_async_superfunction_with_arguments():
179+
@superfunction
180+
def function(a, b=5, c=10):
181+
return a + b + c
182+
183+
assert run(function(2, b=3)) == 15
184+
185+
186+
def test_return_awaited_value_from_async_superfunction_with_arguments():
187+
async def another_one(a, b, c):
188+
return a + b + c
189+
190+
@superfunction
191+
def function(a, b=5, c=10):
192+
return await_it(another_one(a, b, c))
193+
194+
assert run(function(2, b=3)) == 15
195+
196+
197+
def test_call_superfunction_with_tilda_multiple_times():
198+
@superfunction
199+
def function():
200+
return 4
201+
202+
assert ~function() == 4
203+
assert ~function() == 4
204+
assert ~function() == 4
205+
206+
207+
def test_async_call_superfunction_multiple_times():
208+
@superfunction
209+
def function():
210+
return 4
211+
212+
assert run(function()) == 4
213+
assert run(function()) == 4
214+
assert run(function()) == 4
215+
216+
217+
def test_generator_call_superfunction_multiple_times():
218+
@superfunction
219+
def function():
220+
yield 4
221+
222+
assert list(function()) == [4]
223+
assert list(function()) == [4]
224+
assert list(function()) == [4]
225+
226+
227+
def test_combine_with_other_decorator_before():
228+
def other_decorator(function):
229+
return function
230+
231+
@superfunction
232+
@other_decorator
233+
def template():
234+
pass
235+
236+
with pytest.raises(WrongDecoratorSyntaxError, match=full_match('The @superfunction decorator cannot be used in conjunction with other decorators.')):
237+
~template()
238+
239+
240+
def test_combine_with_other_decorator_after():
241+
def other_decorator(function):
242+
return function
243+
244+
@other_decorator
245+
@superfunction
246+
def template():
247+
pass
248+
249+
with pytest.raises(WrongDecoratorSyntaxError, match=full_match('The @superfunction decorator cannot be used in conjunction with other decorators.')):
250+
~template()

tests/units/decorators/test_transfunction.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,29 @@ def template(self, a, b=5):
745745

746746
assert isinstance(some_class_instance.template, FunctionTransformer)
747747
assert list(some_class_instance.template.get_generator_function()(2)) == [9]
748+
749+
750+
def test_combine_with_other_decorator_before():
751+
def other_decorator(function):
752+
return function
753+
754+
@transfunction
755+
@other_decorator
756+
def template():
757+
pass
758+
759+
with pytest.raises(WrongDecoratorSyntaxError, match=full_match('The @transfunction decorator cannot be used in conjunction with other decorators.')):
760+
template.get_usual_function()
761+
762+
763+
def test_combine_with_other_decorator_after():
764+
def other_decorator(function):
765+
return function
766+
767+
@other_decorator
768+
@transfunction
769+
def template():
770+
pass
771+
772+
with pytest.raises(WrongDecoratorSyntaxError, match=full_match('The @transfunction decorator cannot be used in conjunction with other decorators.')):
773+
template.get_usual_function()

transfunctions/decorators/superfunction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def sync_sleep_option(flags: Dict[str, bool], args, kwargs, transformer, wrapped
6363
@staticmethod
6464
async def async_sleep_option(flags: Dict[str, bool], args, kwargs, transformer) -> None:
6565
flags['used'] = True
66-
await transformer.get_async_function()(*args, **kwargs)
66+
return await transformer.get_async_function()(*args, **kwargs)
6767

6868

6969
not_display(UsageTracer)

0 commit comments

Comments
 (0)