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
Carlos Ramos Carreño
erp5
Commits
b0c0279b
Commit
b0c0279b
authored
Feb 16, 2021
by
Aurel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for python3 coding style
parent
0df4c670
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
1 deletion
+116
-1
product/ERP5Type/tests/Python3StyleTest.py
product/ERP5Type/tests/Python3StyleTest.py
+108
-0
tests/__init__.py
tests/__init__.py
+8
-1
No files found.
product/ERP5Type/tests/Python3StyleTest.py
0 → 100644
View file @
b0c0279b
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets <jp@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 adviced 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
os
import
unittest
from
glob
import
glob
from
subprocess
import
Popen
,
PIPE
from
Products.ERP5Type.tests.utils
import
addUserToDeveloperRole
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
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
=
os
.
path
.
normpath
(
glob
(
'%s/../../../%s'
%
(
HERE
,
os
.
environ
[
'TESTED_PRODUCT'
]))[
0
])
else
:
path
=
os
.
path
.
normpath
(
glob
(
'%s/../../%s'
%
(
HERE
,
os
.
environ
[
'TESTED_PRODUCT'
]))[
0
])
error_list
=
[]
try
:
stdout
=
Popen
([
"2to3"
,
"--fix"
,
fixer_name
,
str
(
path
)],
stdout
=
PIPE
).
communicate
()[
0
]
except
OSError
,
e
:
raise_
(
OSError
,
'%r
\
n
%r'
%
(
os
.
environ
,
e
))
if
stdout
:
error_list
.
append
((
path
,
stdout
))
if
error_list
:
message
=
'
\
n
'
.
join
([
"%s
\
n
%s
\
n
"
%
error
for
error
in
error_list
])
self
.
fail
(
message
)
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
,
# currently, jsl based test_javascript_lint report too many false positives.
'test_javascript_lint'
:
None
,
},
)
# required to create content in portal_components
addUserToDeveloperRole
(
'ERP5TypeTestCase'
)
suite
.
addTest
(
unittest
.
makeSuite
(
testclass
))
return
suite
tests/__init__.py
View file @
b0c0279b
...
...
@@ -214,9 +214,16 @@ class ERP5BusinessTemplateCodingStyleTestSuite(_ERP5):
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
))
for
product_path
in
(
glob
(
'%s/../product/*'
%
(
HERE
))
+
glob
(
'%s/../bt5'
%
HERE
)):
if
os
.
path
.
isdir
(
product_path
)
and
\
not
os
.
path
.
exists
(
os
.
path
.
join
(
product_path
,
'skip_coding_style_test'
)):
test_list
.
append
(
"Python3Style."
+
os
.
path
.
basename
(
product_path
))
return
test_list
def
run
(
self
,
full_test
):
if
full_test
.
split
(
'.'
)[
0
]
==
"Python3Style"
:
return
self
.
runUnitTest
(
'Python3StyleTest'
,
TESTED_PRODUCT
=
full_test
.
split
(
'.'
)[
1
])
return
self
.
runUnitTest
(
'CodingStyleTest'
,
TESTED_BUSINESS_TEMPLATE
=
full_test
)
def
getLogDirectoryPath
(
self
,
*
args
,
**
kw
):
...
...
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