Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-KINADINOVA-Dariya
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dariya Kinadinova
AP-KINADINOVA-Dariya
Commits
7e2f61a9
Commit
7e2f61a9
authored
1 year ago
by
Dariya Kinadinova
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
b5d8fd0c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tp9/apl1test.py
+89
-0
89 additions, 0 deletions
tp9/apl1test.py
with
89 additions
and
0 deletions
tp9/apl1test.py
0 → 100644
+
89
−
0
View file @
7e2f61a9
import
thonnycontrib
from
thonnycontrib.backend.evaluator
import
Evaluator
import
thonnycontrib.backend.l1test_backend
from
thonny.plugins.cpython_backend.cp_back
import
MainCPythonBackend
import
thonnycontrib.backend.doctest_parser
from
thonnycontrib.backend.doctest_parser
import
ExampleWithExpected
,
ExampleWithoutExpected
import
thonnycontrib.backend.ast_parser
from
thonnycontrib.backend.ast_parser
import
L1DocTest
import
thonnycontrib.backend.verdicts
from
thonnycontrib.backend.verdicts.ExceptionVerdict
import
ExceptionVerdict
import
inspect
import
tempfile
import
os
import
sys
class
MockBackend
(
MainCPythonBackend
):
"""
Fake backend.
"""
def
__init__
(
self
):
...
def
send_message
(
self
,
msg
)
->
None
:
...
# register backend
thonnycontrib
.
backend
.
l1test_backend
.
BACKEND
=
MockBackend
()
def
l1test_to_org
(
filename
:
str
,
source
:
str
=
""
):
"""
Return an org abstract of the tests presents in `filename` file.
"""
abstract
=
{
'
total
'
:
0
,
'
success
'
:
0
,
'
failures
'
:
0
,
'
errors
'
:
0
,
'
empty
'
:
0
}
if
source
==
""
:
with
open
(
filename
,
'
rt
'
)
as
fin
:
source
=
fin
.
read
()
evaluator
=
Evaluator
(
filename
=
filename
,
source
=
source
)
tests
=
evaluator
.
evaluate
()
n
=
len
(
tests
)
abstract
[
'
total
'
]
=
n
res
=
""
for
test
in
tests
:
examples
=
test
.
get_examples
()
res_examples
=
""
nb_test
,
nb_test_ok
=
0
,
0
empty
=
True
for
example
in
examples
:
verdict
=
test
.
get_verdict_from_example
(
example
)
if
isinstance
(
example
,
ExampleWithExpected
):
nb_test
+=
1
if
verdict
.
isSuccess
():
nb_test_ok
+=
1
abstract
[
'
success
'
]
+=
1
else
:
abstract
[
'
failures
'
]
+=
1
empty
=
False
if
isinstance
(
verdict
,
ExceptionVerdict
):
abstract
[
'
errors
'
]
+=
1
empty
=
False
res_examples
+=
f
"
**
{
verdict
}
\n\n
"
if
not
verdict
.
isSuccess
():
res_examples
+=
f
"
{
verdict
.
get_details
()
}
\n\n
"
if
not
empty
:
res
+=
f
"
*
{
test
.
get_name
()
}
~
{
nb_test_ok
}
/
{
nb_test
}
réussis
\n\n
"
else
:
abstract
[
'
empty
'
]
+=
1
res
+=
f
"
*
{
test
.
get_name
()
}
\n\n
Aucun test trouvé !
\n\n
"
res
+=
res_examples
res
=
f
"
Tests exécutés :
{
abstract
[
'
total
'
]
}
\n
Succès:
{
abstract
[
'
success
'
]
}
,
\
Echecs:
{
abstract
[
'
failures
'
]
}
, Erreurs:
{
abstract
[
'
errors
'
]
}
,
\
Vide:
{
abstract
[
'
empty
'
]
}
\n\n
"
+
res
return
res
def
testmod
(
modulename
:
str
):
"""
mimic the doctest.testmod function
for `modulename` module
"""
print
(
l1test_to_org
(
modulename
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment