Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nxdtest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nxdtest
Commits
bca50060
Commit
bca50060
authored
Nov 17, 2020
by
Jérome Perrin
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support output from unittest module from python standard library
parent
53064e71
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
186 additions
and
1 deletion
+186
-1
__init__.py
nxdtest/__init__.py
+43
-1
nxdtest_unittest_test.py
nxdtest/nxdtest_unittest_test.py
+143
-0
No files found.
nxdtest/__init__.py
View file @
bca50060
...
...
@@ -66,7 +66,8 @@ from golang import b
def
loadNXDTestFile
(
path
):
# -> TestEnv
t
=
TestEnv
()
g
=
{
'TestCase'
:
t
.
TestCase
,
# TODO + all other public TestEnv methods
'PyTest'
:
PyTest
}
'PyTest'
:
PyTest
,
'UnitTest'
:
UnitTest
,}
with
open
(
path
,
"r"
)
as
f
:
src
=
f
.
read
()
six
.
exec_
(
src
,
g
)
...
...
@@ -391,5 +392,46 @@ class PyTest:
return
stat
class
UnitTest
:
@
staticmethod
def
summary
(
out
,
err
):
# -> status_dict
run_re
=
re
.
compile
(
br
'.*Ran (?P<all_tests>
\
d+) tests? in (?P<seconds>
\
d+
\
.
\
d+)s'
,
re
.
DOTALL
)
status_re
=
re
.
compile
(
br
"""
.*(OK|FAILED)
\
s+
\
(
(failures=(?P<failures>
\
d+),?
\
s*)?
(errors=(?P<errors>
\
d+),?
\
s*)?
(skipped=(?P<skips>
\
d+),?
\
s*)?
(expected
\
s+failures=(?P<expected_failures>
\
d+),?
\
s*)?
(unexpected
\
s+successes=(?P<unexpected_successes>
\
d+),?
\
s*)?
\
)
"""
,
re
.
DOTALL
|
re
.
VERBOSE
)
status_dict
=
{
}
run
=
run_re
.
search
(
err
)
if
run
:
groupdict
=
run
.
groupdict
()
status_dict
.
update
(
duration
=
float
(
groupdict
[
'seconds'
]),
test_count
=
int
(
groupdict
[
'all_tests'
]),
error_count
=
0
,
failure_count
=
0
,
skip_count
=
0
,
)
status
=
status_re
.
search
(
err
)
if
status
:
groupdict
=
status
.
groupdict
()
status_dict
.
update
(
error_count
=
int
(
groupdict
.
get
(
'errors'
)
or
0
),
failure_count
=
int
(
groupdict
.
get
(
'failures'
)
or
0
)
+
int
(
groupdict
.
get
(
'unexpected_successes'
)
or
0
),
skip_count
=
int
(
groupdict
.
get
(
'skips'
)
or
0
)
+
int
(
groupdict
.
get
(
'expected_failures'
)
or
0
))
return
status_dict
if
__name__
==
'__main__'
:
main
()
nxdtest/nxdtest_unittest_test.py
0 → 100644
View file @
bca50060
# -*- coding: utf-8 -*-
# Copyright (C) 2020 Nexedi SA and Contributors.
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
# verify unittest-related functionality
from
nxdtest
import
_test_result_summary
,
UnitTest
import
pytest
from
golang
import
b
# [] of (name, out, err, summaryok)
testv
=
[]
def
case1
(
name
,
out
,
err
,
summaryok
):
testv
.
append
((
name
,
out
,
err
,
summaryok
))
case1
(
'ok'
,
b
(
''
),
b
(
"""
\
test_1 (test.Test) ... ok
test_2 (test.Test) ... ok
test_3 (test.Test) ... ok
----------------------------------------------------------------------
Ran 3 tests in 1.761s
OK
"""
),
'ok
\t
testname
\t
1.761s
\t
# 3t 0e 0f 0s'
)
case1
(
'ok+xfail'
,
b
(
''
),
b
(
"""
\
test_1 (test.Test) ... ok
test_2 (test.Test) ... ok
test_3 (test.Test) ... expected failure
----------------------------------------------------------------------
Ran 3 tests in 1.098s
OK (expected failures=1)
"""
),
'ok
\t
testname
\t
1.098s
\t
# 3t 0e 0f 1s'
)
case1
(
'fail'
,
b
(
''
),
b
(
"""
\
test_1 (test.Test) ... ok
test_2 (test.Test) ... ok
test_3 (test.Test) ... FAIL
======================================================================
FAIL: test_3 (test.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/srv/slapgrid/slappart4/srv/project/nxdtest/tmp/test.py", line 14, in test_3
self.assertEqual(1, 2)
AssertionError: 1 != 2
----------------------------------------------------------------------
Ran 3 tests in 2.198s
FAILED (failures=1)
"""
),
'fail
\t
testname
\t
2.198s
\t
# 3t 0e 1f 0s'
)
case1
(
'error'
,
b
(
''
),
b
(
"""
\
test_1 (test.Test) ... ok
test_2 (test.Test) ... ok
test_3 (test.Test) ... ERROR
======================================================================
ERROR: test_3 (test.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/srv/slapgrid/slappart4/srv/project/nxdtest/tmp/test.py", line 14, in test_3
boom
NameError: name 'boom' is not defined
----------------------------------------------------------------------
Ran 3 tests in 1.684s
FAILED (errors=1)
"""
),
'error
\t
testname
\t
1.684s
\t
# 3t 1e 0f 0s'
)
case1
(
'error-no-test'
,
b
(
''
),
b
(
"""
\
usage: python -m unittest discover [-h] [-v] [-q] [--locals] [-f] [-c] [-b]
[-k TESTNAMEPATTERNS] [-s START]
[-p PATTERN] [-t TOP]
python -m unittest discover: error: unrecognized arguments: --argument-error
"""
),
'?
\t
testname
\t
1.000s
\t
# ?t ?e ?f ?s'
)
case1
(
'error-no-output'
,
b
(
''
),
b
(
''
),
'?
\t
testname
\t
1.000s
\t
# ?t ?e ?f ?s'
)
case1
(
'failed+unexpected_success'
,
b
(
''
),
b
(
"""
\
test_1 (test.Test) ... ok
test_2 (test.Test) ... ok
test_3 (test.Test) ... unexpected success
----------------------------------------------------------------------
Ran 3 tests in 1.039s
FAILED (unexpected successes=1)
"""
),
'fail
\t
testname
\t
1.039s
\t
# 3t 0e 1f 0s'
)
case1
(
'mixed-output'
,
b
(
''
),
b
(
"""
\
----------------------------------------------------------------------
Ran 1 tests in 1.111s
FAILED (failures=1)
----------------------------------------------------------------------
Ran 3 tests in 2.222s
FAILED (failures=3)
"""
),
'fail
\t
testname
\t
2.222s
\t
# 3t 0e 3f 0s'
)
@
pytest
.
mark
.
parametrize
(
"name,out,err,summaryok"
,
testv
)
def
test_unittest_summary
(
name
,
out
,
err
,
summaryok
):
kw
=
{
'duration'
:
1.0
}
kw
.
update
(
UnitTest
.
summary
(
out
,
err
))
summary
=
_test_result_summary
(
'testname'
,
kw
)
assert
summary
==
summaryok
Jérome Perrin
@jerome
mentioned in commit
slapos@cdffdcbb
·
Nov 25, 2020
mentioned in commit
slapos@cdffdcbb
mentioned in commit slapos@cdffdcbb4dc927045bf4c8c442db48e991106c1a
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment