Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexander Emmerich
erp5
Commits
705b8506
Commit
705b8506
authored
Mar 22, 2021
by
Aurel
Committed by
Julien Muchembled
Apr 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for python3 coding style
parent
08be2f8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
13 deletions
+119
-13
product/ERP5Type/tests/Python3StyleTest.py
product/ERP5Type/tests/Python3StyleTest.py
+99
-0
tests/__init__.py
tests/__init__.py
+20
-13
No files found.
product/ERP5Type/tests/Python3StyleTest.py
0 → 100644
View file @
705b8506
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2021 Nexedi SARL and Contributors. All Rights Reserved.
# Aurélien Calonne <aurel@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##############################################################################
import
os
,
sys
import
unittest
from
subprocess
import
check_output
,
CalledProcessError
from
cStringIO
import
StringIO
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
lib2to3.main
import
main
class
Python3StyleTest
(
ERP5TypeTestCase
):
""" Check coding style against python3 in the dir
defined by the TESTED_PRODUCT environment variable
We run 2to3 for each fixer applied to check for diff which means
that regression has been introduced
"""
def
getBusinessTemplateList
(
self
):
"""
No need to install anything
"""
return
()
def
getTestedBusinessTemplateList
(
self
):
"""
Return the list of business templates to be
checked for consistency. By default, return
the last business template of the
list of installed business templates.
"""
return
self
.
getBusinessTemplateList
()[
-
1
:]
def
_testFixer
(
self
,
fixer_name
):
"""check fixer is applied on given path
"""
HERE
=
os
.
path
.
dirname
(
__file__
)
if
os
.
environ
[
'TESTED_PRODUCT'
]
==
"bt5"
:
path
=
HERE
+
'/../../../'
else
:
path
=
HERE
+
'/../../'
path
=
os
.
path
.
normpath
(
path
+
os
.
environ
[
'TESTED_PRODUCT'
])
orig_stdout
=
sys
.
stdout
try
:
# XXX: not thread-safe
sys
.
stdout
=
stdout
=
StringIO
()
returncode
=
main
(
"lib2to3.fixes"
,
[
"--fix"
,
fixer_name
,
path
])
finally
:
sys
.
stdout
=
orig_stdout
error
=
stdout
.
getvalue
()
if
error
:
self
.
fail
(
error
)
def
test_raiseFixApplied
(
self
):
self
.
_testFixer
(
'raise'
)
def
test_importFixApplied
(
self
):
self
.
_testFixer
(
'import'
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
tested_product
=
os
.
environ
[
'TESTED_PRODUCT'
]
testclass
=
type
(
'Python3StyleTest %s'
%
tested_product
,
(
Python3StyleTest
,),
{
'tested_product'
:
tested_product
,
},
)
suite
.
addTest
(
unittest
.
makeSuite
(
testclass
))
return
suite
tests/__init__.py
View file @
705b8506
...
...
@@ -3,6 +3,7 @@ import os, subprocess, re
# test_suite is provided by 'run_test_suite'
from
test_suite
import
ERP5TypeTestSuite
import
sys
from
itertools
import
chain
HERE
=
os
.
path
.
dirname
(
__file__
)
...
...
@@ -34,10 +35,10 @@ class _ERP5(ERP5TypeTestSuite):
path
=
"%s/../"
%
HERE
component_re
=
re
.
compile
(
".*/([^/]+)/TestTemplateItem/portal_components"
"/test
\
.[^.]+
\
.([^.]+).py$"
)
for
test_path
in
(
glob
(
'%s/product/*/tests/test*.py'
%
path
)
+
glob
(
'%s/bt5/*/TestTemplateItem/test*.py'
%
path
)
+
glob
(
'%s/bt5/*/TestTemplateItem/portal_components/test.*.test*.py'
%
path
)):
for
test_path
in
chain
(
glob
(
path
+
'/product/*/tests/test*.py'
),
glob
(
path
+
'/bt5/*/TestTemplateItem/test*.py'
),
glob
(
path
+
'/bt5/*/TestTemplateItem/portal_components/test.*.test*.py'
)):
component_re_match
=
component_re
.
match
(
test_path
)
if
component_re_match
is
not
None
:
test_case
=
"%s:%s"
%
(
component_re_match
.
group
(
1
),
...
...
@@ -215,25 +216,31 @@ class ERP5BusinessTemplateCodingStyleTestSuite(_ERP5):
"""Run coding style test on all business templates.
"""
def
getTestList
(
self
):
test_list
=
[]
for
business_template_path
in
(
glob
(
'%s/../bt5/*'
%
HERE
)
+
glob
(
'%s/../product/ERP5/bootstrap/*'
%
HERE
)):
test_list
=
[
os
.
path
.
basename
(
path
)
for
path
in
chain
(
glob
(
HERE
+
'/../bt5/*'
),
glob
(
HERE
+
'/../product/ERP5/bootstrap/*'
))
# we skip coding style check for business templates having this marker
# property. Since the property is not exported (on purpose), modified business templates
# will be candidate for coding style test again.
if
os
.
path
.
isdir
(
business_template_path
)
and
\
not
os
.
path
.
exists
(
os
.
path
.
join
(
business_template_path
,
'bt/skip_coding_style_test'
)):
test_list
.
append
(
os
.
path
.
basename
(
business_template_path
))
if
not
os
.
path
.
exists
(
path
+
'/bt/skip_coding_style_test'
)
and
os
.
path
.
isdir
(
path
)
]
for
path
in
chain
(
glob
(
HERE
+
'/../product/*'
),
glob
(
HERE
+
'/../bt5'
)):
if
not
os
.
path
.
exists
(
path
+
'/skip_coding_style_test'
)
and
os
.
path
.
isdir
(
path
):
test_list
.
append
(
"Python3Style."
+
os
.
path
.
basename
(
path
))
return
test_list
def
run
(
self
,
full_test
):
if
full_test
.
startswith
(
"Python3Style."
):
return
self
.
runUnitTest
(
'Python3StyleTest'
,
TESTED_PRODUCT
=
full_test
[
13
:])
return
self
.
runUnitTest
(
'CodingStyleTest'
,
TESTED_BUSINESS_TEMPLATE
=
full_test
)
def
getLogDirectoryPath
(
self
,
*
args
,
**
kw
):
log_directory
=
os
.
path
.
join
(
self
.
log_directory
,
'{}-{}'
.
format
(
args
[
-
1
]
,
kw
[
'TESTED_BUSINESS_TEMPLATE
'
]))
args
[
-
1
]
+
'-'
+
(
kw
.
get
(
'TESTED_BUSINESS_TEMPLATE'
)
or
kw
[
'TESTED_PRODUCT
'
]))
os
.
mkdir
(
log_directory
)
return
log_directory
...
...
@@ -246,4 +253,4 @@ class RJS_Only(_ERP5):
"erp5_travel_expense_ui_test"
,
"erp5_gadget_interface_validator_ui_test"
,
"erp5_hal_json_style"
]
return
[
test
for
test
in
self
.
_getAllTestList
()
if
any
(
test
.
find
(
bt
)
>-
1
for
bt
in
rjs_officejs_bt_list
)]
\ No newline at end of file
return
[
test
for
test
in
self
.
_getAllTestList
()
if
any
(
test
.
find
(
bt
)
>-
1
for
bt
in
rjs_officejs_bt_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