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
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
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
Show 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
...
@@ -3,6 +3,7 @@ import os, subprocess, re
# test_suite is provided by 'run_test_suite'
# test_suite is provided by 'run_test_suite'
from
test_suite
import
ERP5TypeTestSuite
from
test_suite
import
ERP5TypeTestSuite
import
sys
import
sys
from
itertools
import
chain
HERE
=
os
.
path
.
dirname
(
__file__
)
HERE
=
os
.
path
.
dirname
(
__file__
)
...
@@ -34,10 +35,10 @@ class _ERP5(ERP5TypeTestSuite):
...
@@ -34,10 +35,10 @@ class _ERP5(ERP5TypeTestSuite):
path
=
"%s/../"
%
HERE
path
=
"%s/../"
%
HERE
component_re
=
re
.
compile
(
".*/([^/]+)/TestTemplateItem/portal_components"
component_re
=
re
.
compile
(
".*/([^/]+)/TestTemplateItem/portal_components"
"/test
\
.[^.]+
\
.([^.]+).py$"
)
"/test
\
.[^.]+
\
.([^.]+).py$"
)
for
test_path
in
(
for
test_path
in
chain
(
glob
(
'%s/product/*/tests/test*.py'
%
path
)
+
glob
(
path
+
'/product/*/tests/test*.py'
),
glob
(
'%s/bt5/*/TestTemplateItem/test*.py'
%
path
)
+
glob
(
path
+
'/bt5/*/TestTemplateItem/test*.py'
),
glob
(
'%s/bt5/*/TestTemplateItem/portal_components/test.*.test*.py'
%
path
)):
glob
(
path
+
'/bt5/*/TestTemplateItem/portal_components/test.*.test*.py'
)):
component_re_match
=
component_re
.
match
(
test_path
)
component_re_match
=
component_re
.
match
(
test_path
)
if
component_re_match
is
not
None
:
if
component_re_match
is
not
None
:
test_case
=
"%s:%s"
%
(
component_re_match
.
group
(
1
),
test_case
=
"%s:%s"
%
(
component_re_match
.
group
(
1
),
...
@@ -215,25 +216,31 @@ class ERP5BusinessTemplateCodingStyleTestSuite(_ERP5):
...
@@ -215,25 +216,31 @@ class ERP5BusinessTemplateCodingStyleTestSuite(_ERP5):
"""Run coding style test on all business templates.
"""Run coding style test on all business templates.
"""
"""
def
getTestList
(
self
):
def
getTestList
(
self
):
test_list
=
[]
test_list
=
[
for
business_template_path
in
(
os
.
path
.
basename
(
path
)
glob
(
'%s/../bt5/*'
%
HERE
)
for
path
in
chain
(
+
glob
(
'%s/../product/ERP5/bootstrap/*'
%
HERE
)):
glob
(
HERE
+
'/../bt5/*'
),
glob
(
HERE
+
'/../product/ERP5/bootstrap/*'
))
# we skip coding style check for business templates having this marker
# we skip coding style check for business templates having this marker
# property. Since the property is not exported (on purpose), modified business templates
# property. Since the property is not exported (on purpose), modified business templates
# will be candidate for coding style test again.
# will be candidate for coding style test again.
if
os
.
path
.
isdir
(
business_template_path
)
and
\
if
not
os
.
path
.
exists
(
path
+
'/bt/skip_coding_style_test'
)
and
os
.
path
.
isdir
(
path
)
not
os
.
path
.
exists
(
os
.
path
.
join
(
business_template_path
,
'bt/skip_coding_style_test'
)):
]
test_list
.
append
(
os
.
path
.
basename
(
business_template_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
return
test_list
def
run
(
self
,
full_test
):
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
)
return
self
.
runUnitTest
(
'CodingStyleTest'
,
TESTED_BUSINESS_TEMPLATE
=
full_test
)
def
getLogDirectoryPath
(
self
,
*
args
,
**
kw
):
def
getLogDirectoryPath
(
self
,
*
args
,
**
kw
):
log_directory
=
os
.
path
.
join
(
log_directory
=
os
.
path
.
join
(
self
.
log_directory
,
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
)
os
.
mkdir
(
log_directory
)
return
log_directory
return
log_directory
...
...
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