From 77ef9491336f71f16a82f9528367b980ff143912 Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 29 Jun 2021 21:39:19 +0200 Subject: [PATCH 1/9] handling memory error * removed the use of `test.expect_no_error` inside the timeout utility: - done "manually", allowing to handle data passed to the thread - consequence: DOCS need an update because there isn't any extra assertion anymore, now. * tested on cw with 3.6, 3.8 wihtout imports, 3.8 with imports: work as expected. * removed a comment in the framework about the timeout (deprecated info) * added the default message for timeout ssertion (https://github.com/codewars/python-test-framework/issues/4) Still need to upddate the tests output (and maybe the tests files) --- codewars_test/test_framework.py | 51 +++++++++++---------- tests/fixtures/timeout_passing.expected.txt | 2 - 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/codewars_test/test_framework.py b/codewars_test/test_framework.py index cbe0993..b76af94 100644 --- a/codewars_test/test_framework.py +++ b/codewars_test/test_framework.py @@ -85,14 +85,7 @@ def assert_approx_equals( expect(abs((actual - expected) / div) < margin, message, allow_raise) -''' -Usage: -@describe('describe text') -def describe1(): - @it('it text') - def it1(): - # some test cases... -''' + def _timed_block_factory(opening_text): @@ -126,28 +119,38 @@ def wrapper(func): it = _timed_block_factory('IT') -''' -Timeout utility -Usage: -@timeout(sec) -def some_tests(): - any code block... -Note: Timeout value can be a float. -''' - -def timeout(sec): +def timeout(sec, user_msg=""): + def wrapper(func): - from multiprocessing import Process + from multiprocessing import Process, Value msg = 'Should not throw any exceptions inside timeout' - def wrapped(): - expect_no_error(msg, func) - process = Process(target=wrapped) + def wrapped(finished): + try: + func() + finished.value = 1.0 + except BaseException as e: + finished.value = 1.0 + fail("{}: {}".format(msg or "Unexpected exception", repr(e))) + + finished = Value('d',0.0) + # needed to know if the process crashed without any "feedback" and before any + # assertion has been done in the wrapped function or the wrapper (happens if + # the heap memory explodes) + + process = Process(target=wrapped, args=(finished,)) process.start() process.join(sec) + if process.is_alive(): - fail('Exceeded time limit of {:.3f} seconds'.format(sec)) + msg = 'Exceeded time limit of {:.3f} seconds'.format(sec) + if user_msg: + msg += ': ' + user_msg + fail(msg) process.terminate() process.join() - return wrapper + elif not finished.value: + fail('Something went wrong: the process running the function crashed without feedback (probably saturating the available memory)') + + return wrapper \ No newline at end of file diff --git a/tests/fixtures/timeout_passing.expected.txt b/tests/fixtures/timeout_passing.expected.txt index a0894ac..eed4f76 100644 --- a/tests/fixtures/timeout_passing.expected.txt +++ b/tests/fixtures/timeout_passing.expected.txt @@ -3,6 +3,4 @@ Test Passed -Test Passed - 17.19 From 5b536fa7acdbf1c5c588ae57356497fec4a495cd Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 29 Jun 2021 22:01:04 +0200 Subject: [PATCH 2/9] adding new tests procedures adding extra checks about the timeout utility: * failing inner assertion * user's assertion message * user's code raising an error --- .../timeout_failing_inner_test_assertion.expected.txt | 6 ++++++ tests/fixtures/timeout_failing_inner_test_assertion.py | 8 ++++++++ ....expected.txt => timeout_failing_time.expected.txt} | 0 .../{timeout_failing.py => timeout_failing_time.py} | 5 ++--- .../timeout_failing_user_raise_error.expected.txt | 6 ++++++ tests/fixtures/timeout_failing_user_raise_error.py | 9 +++++++++ .../timeout_failing_with_user_message.expected.txt | 6 ++++++ tests/fixtures/timeout_failing_with_user_message.py | 10 ++++++++++ 8 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/timeout_failing_inner_test_assertion.expected.txt create mode 100644 tests/fixtures/timeout_failing_inner_test_assertion.py rename tests/fixtures/{timeout_failing.expected.txt => timeout_failing_time.expected.txt} (100%) rename tests/fixtures/{timeout_failing.py => timeout_failing_time.py} (69%) create mode 100644 tests/fixtures/timeout_failing_user_raise_error.expected.txt create mode 100644 tests/fixtures/timeout_failing_user_raise_error.py create mode 100644 tests/fixtures/timeout_failing_with_user_message.expected.txt create mode 100644 tests/fixtures/timeout_failing_with_user_message.py diff --git a/tests/fixtures/timeout_failing_inner_test_assertion.expected.txt b/tests/fixtures/timeout_failing_inner_test_assertion.expected.txt new file mode 100644 index 0000000..2089e87 --- /dev/null +++ b/tests/fixtures/timeout_failing_inner_test_assertion.expected.txt @@ -0,0 +1,6 @@ + +group 1 + +Didn't pass + +30.41 diff --git a/tests/fixtures/timeout_failing_inner_test_assertion.py b/tests/fixtures/timeout_failing_inner_test_assertion.py new file mode 100644 index 0000000..a812e4a --- /dev/null +++ b/tests/fixtures/timeout_failing_inner_test_assertion.py @@ -0,0 +1,8 @@ +import codewars_test as test + + +@test.describe("group 1") +def group_1(): + @test.timeout(0.01) + def test_1(): + test.fail("Didn't pass") diff --git a/tests/fixtures/timeout_failing.expected.txt b/tests/fixtures/timeout_failing_time.expected.txt similarity index 100% rename from tests/fixtures/timeout_failing.expected.txt rename to tests/fixtures/timeout_failing_time.expected.txt diff --git a/tests/fixtures/timeout_failing.py b/tests/fixtures/timeout_failing_time.py similarity index 69% rename from tests/fixtures/timeout_failing.py rename to tests/fixtures/timeout_failing_time.py index 00c2d06..30f85b0 100644 --- a/tests/fixtures/timeout_failing.py +++ b/tests/fixtures/timeout_failing_time.py @@ -5,7 +5,6 @@ def group_1(): @test.timeout(0.01) def test_1(): - x = 0 - while x < 10 ** 9: - x += 1 + while True: + pass test.pass_() diff --git a/tests/fixtures/timeout_failing_user_raise_error.expected.txt b/tests/fixtures/timeout_failing_user_raise_error.expected.txt new file mode 100644 index 0000000..7df8eac --- /dev/null +++ b/tests/fixtures/timeout_failing_user_raise_error.expected.txt @@ -0,0 +1,6 @@ + +group 1 + +Should not throw any exceptions inside timeout: KeyError() + +30.41 diff --git a/tests/fixtures/timeout_failing_user_raise_error.py b/tests/fixtures/timeout_failing_user_raise_error.py new file mode 100644 index 0000000..f68fd49 --- /dev/null +++ b/tests/fixtures/timeout_failing_user_raise_error.py @@ -0,0 +1,9 @@ +import codewars_test as test + + +@test.describe("group 1") +def group_1(): + @test.timeout(0.01) + def test_1(): + raise KeyError() + test.pass_() diff --git a/tests/fixtures/timeout_failing_with_user_message.expected.txt b/tests/fixtures/timeout_failing_with_user_message.expected.txt new file mode 100644 index 0000000..9779d61 --- /dev/null +++ b/tests/fixtures/timeout_failing_with_user_message.expected.txt @@ -0,0 +1,6 @@ + +group 1 + +Exceeded time limit of 0.010 seconds: nope... + +30.41 diff --git a/tests/fixtures/timeout_failing_with_user_message.py b/tests/fixtures/timeout_failing_with_user_message.py new file mode 100644 index 0000000..243e28a --- /dev/null +++ b/tests/fixtures/timeout_failing_with_user_message.py @@ -0,0 +1,10 @@ +import codewars_test as test + + +@test.describe("group 1") +def group_1(): + @test.timeout(0.01, "nope...") + def test_1(): + while True: + pass + test.pass_() From 807553b0142394db57281376c64246780cbee823 Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 29 Jun 2021 22:03:36 +0200 Subject: [PATCH 3/9] Update test_framework.py --- codewars_test/test_framework.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/codewars_test/test_framework.py b/codewars_test/test_framework.py index b76af94..dc99e8f 100644 --- a/codewars_test/test_framework.py +++ b/codewars_test/test_framework.py @@ -124,7 +124,6 @@ def timeout(sec, user_msg=""): def wrapper(func): from multiprocessing import Process, Value - msg = 'Should not throw any exceptions inside timeout' def wrapped(finished): try: @@ -132,7 +131,7 @@ def wrapped(finished): finished.value = 1.0 except BaseException as e: finished.value = 1.0 - fail("{}: {}".format(msg or "Unexpected exception", repr(e))) + fail("Should not throw any exceptions inside timeout: {}".format(msg, repr(e))) finished = Value('d',0.0) # needed to know if the process crashed without any "feedback" and before any From 4a2d2cc19f0cc755bc2b522dc3f4f9c84235176d Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 29 Jun 2021 22:11:08 +0200 Subject: [PATCH 4/9] Update timeout_failing_with_user_message.py --- tests/fixtures/timeout_failing_with_user_message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/timeout_failing_with_user_message.py b/tests/fixtures/timeout_failing_with_user_message.py index 243e28a..38ed799 100644 --- a/tests/fixtures/timeout_failing_with_user_message.py +++ b/tests/fixtures/timeout_failing_with_user_message.py @@ -3,7 +3,7 @@ @test.describe("group 1") def group_1(): - @test.timeout(0.01, "nope...") + @test.timeout(0.2, "nope...") def test_1(): while True: pass From 659475f66afa0197def7d989e2d7e002d0675a60 Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 29 Jun 2021 22:12:43 +0200 Subject: [PATCH 5/9] corrections on outputs --- tests/fixtures/timeout_failing_user_raise_error.py | 2 +- tests/fixtures/timeout_failing_with_user_message.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/timeout_failing_user_raise_error.py b/tests/fixtures/timeout_failing_user_raise_error.py index f68fd49..d847e0c 100644 --- a/tests/fixtures/timeout_failing_user_raise_error.py +++ b/tests/fixtures/timeout_failing_user_raise_error.py @@ -3,7 +3,7 @@ @test.describe("group 1") def group_1(): - @test.timeout(0.01) + @test.timeout(0.2) def test_1(): raise KeyError() test.pass_() diff --git a/tests/fixtures/timeout_failing_with_user_message.py b/tests/fixtures/timeout_failing_with_user_message.py index 38ed799..243e28a 100644 --- a/tests/fixtures/timeout_failing_with_user_message.py +++ b/tests/fixtures/timeout_failing_with_user_message.py @@ -3,7 +3,7 @@ @test.describe("group 1") def group_1(): - @test.timeout(0.2, "nope...") + @test.timeout(0.01, "nope...") def test_1(): while True: pass From c227402268654889696d8f1eb94567c072548831 Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 29 Jun 2021 22:39:32 +0200 Subject: [PATCH 6/9] adding test against memory crash in sub process --- .../timeout_failing_memory_crash.expected.txt | 8 +++++ .../fixtures/timeout_failing_memory_crash.py | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/fixtures/timeout_failing_memory_crash.expected.txt create mode 100644 tests/fixtures/timeout_failing_memory_crash.py diff --git a/tests/fixtures/timeout_failing_memory_crash.expected.txt b/tests/fixtures/timeout_failing_memory_crash.expected.txt new file mode 100644 index 0000000..112db9b --- /dev/null +++ b/tests/fixtures/timeout_failing_memory_crash.expected.txt @@ -0,0 +1,8 @@ + +group 1 + +check memory crash + +Something went wrong: the process running the function crashed without feedback (probably saturating the available memory) + +30.41 diff --git a/tests/fixtures/timeout_failing_memory_crash.py b/tests/fixtures/timeout_failing_memory_crash.py new file mode 100644 index 0000000..c93f085 --- /dev/null +++ b/tests/fixtures/timeout_failing_memory_crash.py @@ -0,0 +1,31 @@ +import codewars_test as test + + +from functools import lru_cache +from sys import setrecursionlimit +setrecursionlimit(54000) + +Q = {*"nh|rh|ag|pa|b|h|pu|tb|ru|ts|cs|ir|no|cd|ne|og|np|hs|cu|pt|th|cr|ho|tm|lu|fl|ds|n|rn|k|sc|pm|ti|as|au|fe|pb|rg|s|u|ar|lv|at|hf|w|bh|in|na|tl|mt|v|xe|tc|cn|rb|sr|i|sm|br|ce|os|er|bi|eu|sb|sn|zr|sg|be|p|ni|ac|nb|rf|o|cl|cf|he|db|ra|ge|ga|nd|pr|mn|fr|f|pd|md|am|fm|ca|kr|lr|gd|mo|mc|mg|ta|se|y|bk|yb|si|es|re|co|po|li|te|c|hg|cm|al|zn|dy|la|ba".split('|')} +def XXX(s): + @lru_cache(maxsize=None) + def recurse(ind): + S = 0 + for i in range(2): + W = s[ind] if i == 0 else s[ind] + s[ind + 1] + if W in Q: + S += recurse(i + ind + 1) + return S + return recurse(0) + + + +DATA = "sbinbhscsinbhosmosbinosbinposbhosbinbhsbinhosnhosinbinacnosinosmoscosbinpbhsmcnosinhosnosinosininhsinpbinosinpbhosninhsnosbhsbhscscosinhoscsbinposnpbhsinbhosmnbhscscninbinbinpbinhosnpbinposcninposninhosnosmcsnhsbhscosbhosnposcsmcscninposinirnininbhsinhosbininpbhsbhscoscsbhosmnbhoscsmcscoscsnhsnbhsnosbhosinosmnbinposbininhosininosbinpbininosinirbhsbhosmnpbinhosnhscnhsbhscosmnosinhsinhosnhsbhsnpbinascsnpbhsnhsbirhosbhoscscnbhosnbinosnhosnposbhosinpbinosinoscsninosbhsbinposinhsbhoscscnbhscnposcsmnosmnposnosmcsinposnpbhosnposnbhsnbhsbhsnposcnpbinpbhosmosnoscnbhsnpbhosnasbhsnpbhscnpbinposcnhosinbinhosbhscosbhsbhsnbinosnbhosnosnhoscnacosnpbinosninposnininosmnirhsnpbhsninhscnosbhosbhoscnasinbinhscscnbinosbhsbinhsnhsmcnhsinacnposbhosnbhsnhoscnacsnbhsinpbinposbhsbinhsbhsbhsininpbhsnhosbinhsbinpbhoscscoscsinhsnosnasbhosnpbhosbinposmnhosinpbhscnhsninpbhscnosninbinosbhscnhosininbinpbhsbhsinpbhsirhscsnbininpbinhosnposbinbhoscosnpbhscsinhsinhsmcsnasinposcoscnosininhsnosbinhsnhosmcnirbhosmosbinposnposnbinoscsininposinbhsbhosinpbinbhsnpbhsbhscosnpbhosbhosbhoscsinhscscoscosbhsbhsinascnhosnosbinposbhsnosmninosnposmoscosbinbhscnbhosinhsbhoscnbinbinosbhsnosnposbhosnbininbhsbhsnbhscosbhosbirbhsbinosbhscninhsbhosnosinposnhsnacnasbinbinbinhosinhscsmnpbhsbinposnposninbinpbhsbhsnininoscosnpbinbhoscsbirnosbhosnosnininacsbhsirnposmcnhoscscnacosbhosbhscninpbhoscnosnosbhsbinbhosnpbininbhosinosinbinposinhscnbhsmosirnbinpbhsninposcsnbhscsbhosnposinpbhsinhsbhosbinosirnosnpbhoscsnbhsmcosnpbinpbhosnbhsnhosbhscosnpbhscosbhsbinhsinhsinbinbinirnbhsinirbhsinpbhsbinhscsnpbhosbinbhscsninposininbhoscsbinposinpbinosnpbhosinosinpbhsinoscnpbirbinposcscnpbhosnbinhsninasinposnacosbhosmninposinpbhoscsinacosininpbinoscoscsbhsbhsnasnbhsnpbhosinhscnbhosnhsbhsbhsbhscscnhsinbhsmosbhosininbhoscsirhscsbinposcnbinposcnpbhsbinposinascsnbhsnposbhosinpbininhoscosnpbhoscnhsnposininhosnacsninbinoscsbinhsinhosnbhosbinhscnosnoscoscnposbinosninbhsninbinpbhosinhsinosnosnbinbininposnbinhosbhosbhosininpbhoscosninirnhsinosnpbinosinpbhosbhosninhoscsninposcsinasinbhosnposinosnhoscnpbinininosnpbhsnbhsnosinoscsbinpbinposnpbinpbhosinbhscosnininposnininposcnasbinosninhsinhsbinhsnposcnposbinbhsinhoscosinbinposnposininasbhsnbhsbinbhosnposbinpbhscsnpbhsinbhosinosmnosbhosbhsnininosbinbhsnposbinposnhosinbinposirnbinasinbinposnbhsmcosininosnbhsbinposnbinpbinosmninbinposbhsnoscnacnpbhosnbininhsmninpbinosmoscosbhosbinbinoscsmninbinposcscnbhosbinhosbhosinbhsnbhsnbhosnhoscnasbhsnhsininpbhsninhoscnbhosmcscsninoscninbinoscosbhsnbhosnosbhsninpbinposnbhsinhosinhscoscsmninhsbhsnbhsnacnpbininbinosbininbhsmcsnosbhoscnhosnosinacnbhsnhosinbinhsnpbininhsbhosinosbhosbhosbhosnhoscnacosininbhsninbinhosnhosnposcsinacnposnbinhsbirnposninbinhsninpbinpbhsbhosnacsbhosinhsbinpbhoscsbinposnirnpbhsmnpbinbinhsnoscosnosirbirnbhosnosnbinposcosninbhosnbhscsbhosinbinosnbhscsnbinbinposcosinosnposinbhsbinhscosbinhsinhsnosbhsbinbinosnosninininposmcninpbinpbhsinposnposcnpbinpbhsnbininbhsbhscnposbhscosnpbinhsnacninposnirbininininposcosnpbhscnhsninbhscosnposbhosinpbinbinbinbininposinposbininirhsnpbhsnoscnacsnosinininosninposmcoscnhscnininosinpbhosnosmnosbhscsnhosnbhoscsbhsmcscsmnbinposbinpbinbinhoscosnhsnosinoscnpbinpbhsnposbinbhosnpbinpbhsinhscsbhosbhscosininpbhsnpbhscnosnpbininpbhsbhosininbhosbhosinbhsnbhosnhscsbininposnhscosnbinposnposcsnhsnosinposcnbinpbhscnbinposcnbhsmosinpbinbhsninpbhsnbirbhsnosnbhsininhosnosinbhsninoscnposcosmnirnhosinosinposnosininhscnosnbinhsinhscsnpbhoscnosbinbhsnposmnbhsmnpbhosnpbhsbinpbhsinbhosnbinhsinhsnposbinbhosinpbinirbinpbininposirbhsinosnosnosinpbinhsnbinoscnasbhosbhosinbhsnbhsbhsmnbhosnhscosnhosbhsnbhosnhsnhsinosinbhscnhsnhsmnhscnbinbininhscsmnbinbinirnposnhsbinhscnbinposnbhscsbhosnpbinbinhscnosbinhosnpbhosinpbhsinosbinosnposinpbinosnposnpbinhosnosbinbhscnininbhsnpbhsinbhoscsinhsinbinhsnbirnbhoscsmnhsbhscsbhsininosinininpbinhsmcscnhoscnbhosinpbininoscnbhsninhsbhscosinosnhsnoscscnpbhscsinosninpbinhscnbhsinbhsbhsbinbinhsininbinhscnosbhsmnosnposmcsbinposbinininbhsnhsbhosinirbhosbinposcnosinosbhoscninoscnasbhscoscnpbhosbinpbinininininposcninhsnpbinininhsnbinhsbhsbinosinposnhsinosbinposinpbinbinpbhsnhsbinpbhscnposbhosnhosbhosbinpbhosinpbinosininosinbhsnpbinhsinbhosbhsnhscosinhosbinpbinbinposnhosmosinhsbhsbininhosnasbhsnbhscoscnasnpbhoscsnposnbinosnhosbirbhsnhosinpbhscsbinposinhscnosnposbhsirnbinposninhscsnbirbhsbhoscnosbhsnosinpbinhsininbinhosninposnposnhsninpbinbinininosnbirnbinhosinhsbinoscsnhscscnasninpbhsbhsinpbininosbhsinposcnosinoscnosmcosnposcoscnpbhsnbinpbhsbinbinhosnpbhoscsbhsnhoscosnbinhsbhosbhosbhsinbinbinhosmninoscscscnposnpbhsnbinosnhosbininbininbhosbinhsnhsbinbhsnbhsbhosmcnosnhosbirhsinoscsnposcninhscnpbhsnosbhosnpbininhscscnpbhoscoscsnposininhsnosbhsnposbhscosbhosbhosnhsmcnhsbhscnbinoscnpbinosbhosininhscsninhsnosnhosnbhsbhsinpbhosmcnhosnpbinbhsbinhosinposnbinhsnposcoscnosnpbinpbhoscosbhsnpbhoscosnosirhsnposinbinposnpbinposmnpbhsbhosinbhscnhoscscnhsinpbinhscnosbhosnbhsbhsninbhoscnpbininhosbinosnbhscnposbinhsbhosbinpbhsnhsbinbhosnhosnbhosnposinbhoscsbhscsninposnhscnbirninoscnhsnhosbinbinbhsbhscsmnhsinhosnoscnhoscscscosmninacnpbinosbhscninhsbhoscsnhosnposnposnposnposbhosbhsnpbinosinpbinpbhsbinhoscninpbhosbinbirnirnposnposnposnposbinposinosbhsnbininposnposnposinacoscnoscosnposnbhsnpbhsinhscosinposinposcosininosnhsinhosinbinhosbhsnposnhosbhoscnposcscnpbinpbhosninposcosbhosinhsinhscnpbinininpbinhsbinpbhsininpbhsinposcnosbhosbhosinosinhsmninosnhosinoscsininposnosinosininoscnasnhosbhsnhosmnhscnoscnhosbhosinhsinhscsbinposnbhsnposinposcnhsnbhscsnposnpbhsbinhosbhsnhsbhsnpbinininhscoscsnosinosbhsnhoscosninininposcnosnposcsnbhsbhsbhsinposnosbhoscninosnhscnposcnoscnosmninhscscosnhsnposcnhsinpbhsbhosmosnosinoscninpbhsmcnbhscosbinosbhsnbinposnbhsmninbhosinbhosmoscnposbirbhsbininposnhoscnosbhsnhsinposinosnpbhosninhsinhsbinbhsbhosbinosnpbhsbhscosnbhscnasnposnhosinininbinposnpbhsnhsbhoscsinosinpbhsbirnhsbhosbhscsnosmcnhosnoscnosninposirbininpbirninbinhosnpbinoscnosnpbhsnpbhscsnbinpbinhscnhsnbhsbhsbinpbinhsnpbhoscsbhoscnosbhoscnbinpbhscosinbinhsinosnbinbhsbinbinasnbhosnhosnosbhscsnosinhsbhsnhsmnpbhsnposininpbinoscnosinhsmnhoscoscsinbinhsbinbhsnasbhosbhosirhsninposbhosmcnhscsbinosininposninbinpbhosbinpbinbhscnpbinosinhsmcninhosmnposnosmnhsbinposnoscosinosbhosbinhsninosnhsinhsnbinpbhsirnosininhsnposnbhosnbhscscnposbinpbhoscsinosnposmcscnhsnbhsninosinhsbhsnhsnhoscnhsbhsirnhsnpbininpbhosinpbhscnposcscosnbhscscnininpbhsnbinininpbhscosinpbhosininhscnhsnosinhsnpbinhsbinacsbinposbininpbhoscsinpbinirhscninbhsnhsbhosinpbhscsbhscscnposbhsnosmnosbhosnhsnhoscscosbinhscnposbhsinbhscnpbhscnosbhsbhsinbhscsnbhosnhosnposcnacnposninposinbinposnbhsnosirbinhscnbhosnhoscsbhsbirbinhosmcsnhsbinposcninhsnbinhscninhsnpbhosbhsnhscnascnbhsnpbhsbhosnhscosinhsnhsninposninosmnhsinoscscscnbinhscnposinbhosmosnhosninbhosinbinpbhsnbhosininpbinbinacsbhoscnasinhsbhoscsnposnbhscnpbinhsininpbinpbhscnbhosbhsnosbhosnposcnasinposbhsbhscscosmnbhoscoscosmnosinposinhscnposcnpbinpbhsbhsninpbhsnpbinpbhosinhscnasinininbinininposbhsinhscosnbininbhsnbinbhsinosnpbhsnhsbinposnoscsmnbinosnhscnpbhscoscoscnpbhsninbhsnoscnhscosbhsnposcsbinbirninpbhosininosbhsmosnhsnbinpbinpbinhsinposinhsbhsnpbhsmninosbinbinhoscsbinbhsbhsbinoscosnpbhosbinirnpbinpbinbinbinbhosnbininhsinosbhscnhsnposnhsbinposmosnosbhosnposininbhosinposnbinhscsbinoscnosnbininhsbinposcscsnacsbinhoscnhsnposirnpbinposinbhsbinpbinhsmninpbininposbininbhosinpbinpbhsnbhosbinininbinbinhosbinosninhosbinpbhsnininhosnosbhscnpbinhsnininpbinbirhosinpbhsnposnpbirninbhosbinosnosbinacsninpbhoscnposcosnpbinbhsmninosbhscoscsnposbhosmcnposinposinposnposnbhsinirbinposcsinirbinposinininosbinposmninpbhscnbhsnhsinhsnhscsnposcosinhsinbhosnpbinpbhosnposinoscnposcnosnininoscsbhsninosbhosininininbinhsbhsinbinposbinposbhoscsbinposmosnposnosnbinhsnhsninhsmnbhosmcsmcnbhosbinhsinbhoscsnoscninpbinposcnirnpbinpbinhsnoscnhosnposinbinposbhosnbhoscscsninosnposnbhsinpbinpbinhsnposmosinosbhscscnoscninhsbhosinposbinbhsnbhosmnpbhsinposcosnposnhsmcscninpbinacsnpbinbinbinhoscsbhsinposmcnosinbhosinhsinhscnbirnhsbirnhoscosinoscnbhosnosbhsnpbhscnposcnbhscosnposininosbirnosinpbinhsnbinbinposnposbirhosnposmnhsinbhoscscsnhosbhoscnhsinhsbinhosininpbinhosnbirninhsbhosinhsbhscnhsirnosbinbhsbinpbhsnosinbhosnposbhosbinhosnbinhsnposnbhosnhsirhsinposninbinposininoscoscosnpbirninoscnasinhsmcscosinosinasinbirninposmnpbhsbinbinbinosmcsninbinpbhosbhsnosinpbhosnbhsnposnbinposinbhsnosinbhsnoscnasbininposininosinosinbhosnpbhscsinhosbhsnpbinininosbhoscsbhscosbhsnhsbinposbhosninosnirnposnhscosbhosnhosnposbhosmnosnpbinposbhosinbinhsnhsbhsnosbhosinoscnirbinpbhsninbinhosbinbhscsinhsbhosnposbinposinhscsnhosnpbininbhsbinbhsmnbhoscsnosnhscnasnpbinpbhsbinoscninhsnpbhscninposinosnirnpbinhsnbinbhsninbinhosbinposmcsinhsninbinposnhscnposmcnbhsbhosnosnosbhosinbhoscnasnbinposninbhsbhsirhsinhosbhsnposbinhosbhsnpbhosmosnposinbhsninosininhoscnhoscnascnpbinpbinbhosbhosnpbinosnhsmosbhsbinbhosbinosnpbhsnhsbhosinhsnpbhsmcninbinpbhosnbinhsbhosirbhsbhsnpbhsninpbhsbhsinosnhosbhsnpbinhsnpbinosirbhosininoscnpbhscnosininpbirhosbinpbhscnininoscnbhsbhsnpbhosnhsinposinasbhosbinosnhsnposbhsmnbinhsnposnbinbinposbinposbhsbinposcosbhosmcnposcnhscnasbhosmnhosnosmcoscnpbhsbinpbinposbhsbininosnpbhscsbhsmnhsnhosbirbinosninposmcsnhsnbinhsbhosninpbhosinhsbinhosinosnposcnhsnposnbhscsbhosinposnbirnpbhosnhosnhsnbinbirhoscsnposnbhsinpbhsnpbinposininoscnpbhosninosnposbhosinhosbhsninposbinpbhosmninhscscninhsmninposcnposmnhsnhscscscnbhsinosnpbhosnhoscosbinhscscnhosnasinosinhscosbhscnbinhosbinhscosnbirhsbhosnposnbhsininhsbinpbhoscoscoscscsbinasnbhosinpbhsmcnosnhsmcnhosinosnpbinpbhosmcosmninosnbinosnbhosbhosnosinbhosbhsnininposnhoscnbinosnposnbinhsbhsninosinbininhscsmoscnhscninacosbhoscnpbinbhosbinpbinbinposinposnpbinposcsbhsbirbhosinosmninosmcscosinbhosnpbhsmcnpbinoscnoscnasbhosbhscscsinpbhosinbhosinosbhscosbinpbhosinpbhoscscnirhosmnbhosinposcninoscnhsbinpbhsnpbhosbhosnhsninbhosnhosnposbhsnhsmnosinbinosnposnbhscnbinoscscninposnosbhsbhscoscscsninbininposininosirbhosnoscoscnposmosbhsinhosinbhosinhsnposbinpbhsbhsmcosinposcosinoscsnhsbinbhscnosninbinposbinbinbirnhsbinposinhosinhsnoscscninpbinininosnhosinhsnposcsirhscnacosninposbhscosnpbhsnhsinposcosinosinirbirnbinposmnposnhscsirnbininosnposcnasinosnhosirnpbhscoscnbhoscsnpbinpbhosnosinposnhsnhsnposinbhosninhsnbhsnbhosbhosbhoscnosnbhscscsbhsbinposnbinpbhsbinbhoscsmnpbhscscnbirhosmnhsnposnbhsinpbinhscsbhsninpbhscnbhscsinirnpbinoscosnosbhscninposcnoscnpbhscnoscsnposcosbirhsinbhosninposnbirhsnbirbinbhosbinpbhsmcscosnhsirbinhsnhscosinbinbinbinposbirhsnhscscscnacsninoscsinhosnbhsbininbhsnosinbinposbinpbhsbininbhscosinininosininbhosbhsnpbinosinhosnpbhscnasnhsinininposcsinosbhsnbhscninposinosnhoscninposnacsbhscsinpbhscnpbinbhosmnhsinhscnasbhoscnhsbirbhoscosinbirhosnirhsbhsnposnposbinhsnhscnininbhosinbinpbhscosnbhosninposnirnhoscnhsnhosinhscnacsnascnhsmnosbinposinhsbinposinposnhoscosnbhsbhscosnpbhsnpbhsbhsnoscosninhosnbhosnhosinirbhosbhsbhsbininosnbhosbinirninbhsnposbhoscosbhosbinposinosbhsninhsnasnosmcnhosnposmnhsnposbininhoscsbhsnasbhscsnbinosmnhsninhosnpbhoscnpbhscsbhsbhscnposcsinbhsinpbinposinhsinhosninbinpbhsbinpbinosinosbinbinpbinbhosnposcnosnbinbhscnbinoscnbhoscsinbinininbhsinhosnhsnpbhscosininpbhscsbinoscnposbhscosnpbinbininosbhsnosnbinoscsinpbhsbinosnbhscosnpbhoscnpbinosinosinposninosnhosinbinosnbhscosbhsnpbhsbhsbhscnpbhsbinposcsmnosnpbinpbhosbhsnosnbhsininosininpbhoscsbhosnposninirnposbhosbinposbinposnbhsirhosbinoscsmosbhscninhosnhsmnbhosbhosinasnposnpbhscosnposcnbhoscsnposcnasbhsnpbinpbinbhosinpbinpbhsinhscnasinosnposcnacscsbininbhsnhsnhsnbhsinpbhsninbhsbhscsinbhscsinposinhsbinposmnbhsininposnhosmnosnhsbhosnbininpbinpbirnhscnoscnpbhsinhscnosnpbinhscosnbhscsbhosininhsinpbinbhscnbhoscsnosmosnbhsinbinosnposcsinbhosinbinposcsnhsninosbhsmnposnposnpbhsnhsininbhosinoscoscnposbinbhsnhosbhosnpbhosbhsmcosinposcnosinininosinoscsmcsnosinbinbininosbinhosnposcnposcsnpbhsinpbhsinosinpbinposnhsbinhsnpbinascsmoscnposinhsnposcnosnpbinbininbhosbhosinbinposbhsnacosinoscosbinosmcosinbhsnbhsnasinosbhosmcnhsbhsininpbinoscnhscnpbhscnacnposnposcnposnposnposnpbinbhsnasnposininbinpbhosbirbinosbhsbhsnbininbhsmnosnhsbinpbhsnhsnhsinpbhsinosbinbinposbhscsnascsinbinpbhsbinhsnbinosmnhscsinbhsnbhsnpbhosininbinosmnhsbhsnbhsinbinoscosnbinposcsnposnhsnpbinpbhscnbinhoscnposnascninhsinposnosinosnposcosnhoscoscnbhosbhosininpbhsnposbhsbinirhsinosinoscsmnhosinosinposcnosinhsbhosnposnosnbhosinpbininoscnpbinininbhoscnascnhsbinposninbhsnposbhosnpbhosnposininpbinhosninbhsbirhscnhscscnhosninosinosninposbhosmosninhsbhsnhsinpbhsnposbinacnasnposinhsbhosbhsninhsnpbhosnpbhosinosbhosnhscnhscsmnposmnpbhosbininhsininosbhoscnpbhosinhsbinhsnposbhosmosnhsbhosinhsnhscnposcninhosninbhosnhosmnpbinininhscnininbhosnosnacscsninhscnpbhscnposnpbirbhoscnacsbhsinpbhsninbinoscnbinbinposnbirninposnbinhsnbhscnhoscnhsinhsnposnbhsbhoscscsninirninposnpbhsbinposcnpbhscsinininbinhscsinpbhscosnbinhsbhosmnbirhosinhscscscscnbhsnosininbinosnosnpbhsnasnbinposnpbinosmcosnposininbinpbinposcnosbhscnbhsmnbhosinosnposbhsininhosnhscnpbinosbinposbhsmoscosbhosinoscnbhosnbinbhsbinpbhosbhosirnposninosnbhoscosinpbinbhosnposbhsnposcsmnbininininoscnpbinhscnacnbhsinhsnposnposnacsinbhscosnposbhosnosbhsbhsinoscnosninhsinoscsinhsnposcsbininhosnhscsmcnacosbinposcsbhosmnininhsbhsnposninpbhsnposininhsnoscscscsnhsbhsnosbhscnbhsinbinbhsnposnpbhosnbhscnhsnhosnhscosmnpbininosbhosbinposbhsinposbhosnbinbinbinpbinbhsnbhsinhosnhscnbhosnbhosbinhosbhscsnbhosinosbhosmcnosinpbinosbinhsnpbirninpbhsbhsninosnbinasinhsmnbinposnpbinosininpbinpbhosinhsnhosinoscninhscnposcoscscnbinpbhsnininpbhsmcsbinpbhsinacsinbininhsinposnbinhosinpbinhsnposnasbinhscnhosnoscsinbhsnhscnascnosnhscoscsbinbhscnbinbhsbinpbinhscsbhsbhsbinosnhosinpbinosinoscninbhosinbhsnbirbhsinbhosbhsinposnhscnposinhsbhsnpbhsnpbhsbinirnbinosininosinbhosbinpbinbhsinbinpbhosnposmcnpbhosininhsinhosnbhoscninpbinpbinhsnbhosninbinirhosnposnhsbhscnbininpbhosmnpbinhscsbhsnosinhsbininbinpbininpbinosinoscsbhscosnosnhoscosinbhsnininosninbhsbhoscsbhscscosnposinhsninposininhosnhosbinhsnoscosnininhosnposmcsbhsmnhsininbhsnhsnposbhosbinbhsbinhosininbhsbinininhoscscnposnbinpbhsnbhscsinhosnhscnpbhsbhoscnasbhsbinpbinbinbinhsnhsinposmcnposnininbhsnbininbinhosmcnpbhsnosnposinhsnosnosinhsbhosinposnhsininhsninosbhsinpbhsininpbhsinhsinhsnosirhoscsinasbirnhsnpbhsnpbinhsnbhsnhsbhscnosmninbinpbhsnhsnposbhosnpbhsbininininbinhscninosnpbinosnpbirhsnpbhsbhsinhsnhosnpbhsbhsinposnasinhosnpbhsnbhosnosnosinosbinbhsnposcninhsbhosbhosinposbinpbininininhsinposcosnposnpbhosnposcscsnposinposbhsbhosinpbhsinbhosinposnosnbininposcoscsnbhsnhosbhsbinbhosnpbinhsbhosbininoscnasinpbinirhsnpbinbinpbhsmcoscnininosnhscosnbhsnbinpbinhsinpbirbhsininpbhsbhosnpbinhsinbirbhosbinhoscosnposininbinposnposmnbhosnpbhsbhsnposcsinbinpbhosininpbhsnposbhsnposbhsninposninirnosinbirhsnbhsnosinpbhsinoscnhsinosnbhsininasbhsnbinposcsinosinosmnbinosinpbhosbininposnhosbhsbinpbhscsmnhsninbhsbinhsnosnpbhsinbinhsmcnpbirhosbinhosbhosinosinosnposbhscosbhosnposbhoscnhsbhosnhsbinpbinosbhsnposbhsinhsbinbhsmnoscsnhsbinposcsnpbinbhoscninosmcosnosnosinosnpbhsninhsnbinpbinhosnosninbinhscsbhosinosmcnpbhoscninpbinoscosnbinposinhsbhoscsnbinbhsbinhsmnpbhscsinpbininasinpbinasbhsbhsbinpbininposcnh" + +@test.describe('group 1') +def tests(): + @test.it("check memory crash") + def _(): + @test.timeout(8) + def _(): + test.pass_() + XXX(DATA) # this explodes the heap \ No newline at end of file From 471a212eec9e659b93317ba746cb5a32c2c02e18 Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 29 Jun 2021 22:41:00 +0200 Subject: [PATCH 7/9] Update test_framework.py --- codewars_test/test_framework.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/codewars_test/test_framework.py b/codewars_test/test_framework.py index dc99e8f..b4dd32e 100644 --- a/codewars_test/test_framework.py +++ b/codewars_test/test_framework.py @@ -86,7 +86,14 @@ def assert_approx_equals( - +''' +Usage: +@describe('describe text') +def describe1(): + @it('it text') + def it1(): + # some test cases... +''' def _timed_block_factory(opening_text): from timeit import default_timer as timer From fb1ae530fa5fb74a714cd1d5f0e297a9d93932e7 Mon Sep 17 00:00:00 2001 From: Blind4Basics <32236948+Blind4Basics@users.noreply.github.com> Date: Tue, 29 Jun 2021 23:20:15 +0200 Subject: [PATCH 8/9] update ouptus and tests --- .../fixtures/timeout_failing_memory_crash.expected.txt | 2 +- tests/fixtures/timeout_failing_memory_crash.py | 3 ++- .../timeout_failing_user_raise_error.expected.txt | 2 ++ tests/fixtures/timeout_failing_user_raise_error.py | 10 ++++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/fixtures/timeout_failing_memory_crash.expected.txt b/tests/fixtures/timeout_failing_memory_crash.expected.txt index 112db9b..81c199a 100644 --- a/tests/fixtures/timeout_failing_memory_crash.expected.txt +++ b/tests/fixtures/timeout_failing_memory_crash.expected.txt @@ -1,7 +1,7 @@ group 1 -check memory crash +check memory crash Something went wrong: the process running the function crashed without feedback (probably saturating the available memory) diff --git a/tests/fixtures/timeout_failing_memory_crash.py b/tests/fixtures/timeout_failing_memory_crash.py index c93f085..d667736 100644 --- a/tests/fixtures/timeout_failing_memory_crash.py +++ b/tests/fixtures/timeout_failing_memory_crash.py @@ -28,4 +28,5 @@ def _(): @test.timeout(8) def _(): test.pass_() - XXX(DATA) # this explodes the heap \ No newline at end of file + XXX(DATA) # this explodes the heap + test.fil("didn't fail...") \ No newline at end of file diff --git a/tests/fixtures/timeout_failing_user_raise_error.expected.txt b/tests/fixtures/timeout_failing_user_raise_error.expected.txt index 7df8eac..617f7bd 100644 --- a/tests/fixtures/timeout_failing_user_raise_error.expected.txt +++ b/tests/fixtures/timeout_failing_user_raise_error.expected.txt @@ -1,6 +1,8 @@ group 1 +it 1 + Should not throw any exceptions inside timeout: KeyError() 30.41 diff --git a/tests/fixtures/timeout_failing_user_raise_error.py b/tests/fixtures/timeout_failing_user_raise_error.py index d847e0c..a632f19 100644 --- a/tests/fixtures/timeout_failing_user_raise_error.py +++ b/tests/fixtures/timeout_failing_user_raise_error.py @@ -3,7 +3,9 @@ @test.describe("group 1") def group_1(): - @test.timeout(0.2) - def test_1(): - raise KeyError() - test.pass_() + @test.it("it 1") + def group_1(): + @test.timeout(0.2) + def test_1(): + raise KeyError() + test.pass_() From 1984fcf2db8518a46f8d0bf33e58cf8a692a8eca Mon Sep 17 00:00:00 2001 From: kazk Date: Tue, 29 Jun 2021 20:11:54 -0700 Subject: [PATCH 9/9] Fix NameError --- codewars_test/test_framework.py | 4 ++-- tests/fixtures/timeout_failing_memory_crash.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codewars_test/test_framework.py b/codewars_test/test_framework.py index b4dd32e..8a91d6b 100644 --- a/codewars_test/test_framework.py +++ b/codewars_test/test_framework.py @@ -138,7 +138,7 @@ def wrapped(finished): finished.value = 1.0 except BaseException as e: finished.value = 1.0 - fail("Should not throw any exceptions inside timeout: {}".format(msg, repr(e))) + fail("Should not throw any exceptions inside timeout: {}".format(repr(e))) finished = Value('d',0.0) # needed to know if the process crashed without any "feedback" and before any @@ -159,4 +159,4 @@ def wrapped(finished): elif not finished.value: fail('Something went wrong: the process running the function crashed without feedback (probably saturating the available memory)') - return wrapper \ No newline at end of file + return wrapper diff --git a/tests/fixtures/timeout_failing_memory_crash.py b/tests/fixtures/timeout_failing_memory_crash.py index d667736..020a519 100644 --- a/tests/fixtures/timeout_failing_memory_crash.py +++ b/tests/fixtures/timeout_failing_memory_crash.py @@ -29,4 +29,4 @@ def _(): def _(): test.pass_() XXX(DATA) # this explodes the heap - test.fil("didn't fail...") \ No newline at end of file + test.fail("didn't fail...")