Skip to content

Commit 5d92247

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
more tests
1 parent 7a2da6b commit 5d92247

1 file changed

Lines changed: 67 additions & 1 deletion

File tree

tests/units/test_decorator.py

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
from transfunctions import async_context, sync_context, generator_context
1111

1212

13+
SOME_GLOBAL = 777
14+
1315
"""
1416
Что нужно проверить:
1517
1618
1 фаза:
1719
18-
9. Работает чтение глобальных переменных.
1920
10. Работает директива nonlocal.
2021
11. Работает директива global.
2122
12. Декоратор @transfunction можно использовать на методах (в т.ч. асинк и генераторных).
@@ -45,6 +46,7 @@
4546
17. Нельзя вызывать трансформер напрямую. При попытке это сделать вылетает информативное исключение, причем как при передаче аргументов, так и нет.
4647
7. Декоратор @transfunction нельзя использовать дважды на одной функции.
4748
8. Работает чтение из замыканий (в том числе для функций с аргументами).
49+
9. Работает чтение глобальных переменных.
4850
"""
4951

5052
@transfunction
@@ -396,3 +398,67 @@ def make(some_number):
396398

397399
assert list(function(1)) == [2]
398400
assert list(function(2)) == [3]
401+
402+
403+
def test_read_globals_with_usual_function():
404+
@transfunction
405+
def make():
406+
return SOME_GLOBAL
407+
408+
function = make.get_usual_function()
409+
410+
assert function() == SOME_GLOBAL
411+
412+
413+
def test_read_globals_with_usual_function_with_arguments():
414+
@transfunction
415+
def make(some_number):
416+
#nonlocal nonlocal_variable
417+
return SOME_GLOBAL + some_number
418+
419+
function = make.get_usual_function()
420+
421+
assert function(1) == SOME_GLOBAL + 1
422+
assert function(2) == SOME_GLOBAL + 2
423+
424+
425+
def test_read_globals_with_async_function():
426+
@transfunction
427+
def make():
428+
return SOME_GLOBAL
429+
430+
function = make.get_async_function()
431+
432+
assert run(function()) == SOME_GLOBAL
433+
434+
435+
def test_read_globals_with_async_function_with_arguments():
436+
@transfunction
437+
def make(some_number):
438+
return SOME_GLOBAL + some_number
439+
440+
function = make.get_async_function()
441+
442+
assert run(function(1)) == SOME_GLOBAL + 1
443+
assert run(function(2)) == SOME_GLOBAL + 2
444+
445+
446+
def test_read_globals_with_generator_function():
447+
@transfunction
448+
def make():
449+
yield SOME_GLOBAL
450+
451+
function = make.get_generator_function()
452+
453+
assert list(function()) == [SOME_GLOBAL]
454+
455+
456+
def test_read_globals_with_generator_function_with_arguments():
457+
@transfunction
458+
def make(some_number):
459+
yield SOME_GLOBAL + some_number
460+
461+
function = make.get_generator_function()
462+
463+
assert list(function(1)) == [SOME_GLOBAL + 1]
464+
assert list(function(2)) == [SOME_GLOBAL + 2]

0 commit comments

Comments
 (0)