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
143
Merge Requests
143
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
3298638e
Commit
3298638e
authored
Oct 25, 2022
by
Kazuhiko Shiozaki
Committed by
Arnaud Fontaine
Jul 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py2/py3: define ERP5Type.Utils.cmp.
parent
46545e9c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
product/ERP5Type/Utils.py
product/ERP5Type/Utils.py
+16
-1
product/ERP5Type/tests/testERP5Type.py
product/ERP5Type/tests/testERP5Type.py
+6
-0
No files found.
product/ERP5Type/Utils.py
View file @
3298638e
...
@@ -29,7 +29,6 @@
...
@@ -29,7 +29,6 @@
# Required modules - some modules are imported later to prevent circular deadlocks
# Required modules - some modules are imported later to prevent circular deadlocks
from
__future__
import
absolute_import
from
__future__
import
absolute_import
from
past.builtins
import
cmp
from
six
import
int2byte
as
chr
from
six
import
int2byte
as
chr
from
six
import
string_types
as
basestring
from
six
import
string_types
as
basestring
from
six.moves
import
xrange
from
six.moves
import
xrange
...
@@ -125,6 +124,22 @@ from Products.ERP5Type.Globals import get_request
...
@@ -125,6 +124,22 @@ from Products.ERP5Type.Globals import get_request
from
.Accessor.TypeDefinition
import
type_definition
from
.Accessor.TypeDefinition
import
type_definition
from
.Accessor.TypeDefinition
import
list_types
from
.Accessor.TypeDefinition
import
list_types
if
six
.
PY3
:
def
cmp
(
a
,
b
):
try
:
return
(
a
>
b
)
-
(
a
<
b
)
except
TypeError
:
if
a
is
None
:
return
-
1
elif
b
is
None
:
return
1
type_a
=
''
if
isinstance
(
a
,
(
int
,
float
))
else
type
(
a
).
__name__
type_b
=
''
if
isinstance
(
b
,
(
int
,
float
))
else
type
(
b
).
__name__
return
(
type_a
>
type_b
)
-
(
type_a
<
type_b
)
else
:
import
__builtin__
cmp
=
__builtin__
.
cmp
#####################################################
#####################################################
# Generic sort method
# Generic sort method
#####################################################
#####################################################
...
...
product/ERP5Type/tests/testERP5Type.py
View file @
3298638e
...
@@ -39,6 +39,7 @@ from Acquisition import aq_base
...
@@ -39,6 +39,7 @@ from Acquisition import aq_base
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
AccessControl.ZopeGuards
import
guarded_import
from
AccessControl.ZopeGuards
import
guarded_import
from
Products.ERP5Type.tests.utils
import
LogInterceptor
,
createZODBPythonScript
from
Products.ERP5Type.tests.utils
import
LogInterceptor
,
createZODBPythonScript
from
Products.ERP5Type.Utils
import
cmp
class
TestERP5Type
(
ERP5TypeTestCase
,
LogInterceptor
):
class
TestERP5Type
(
ERP5TypeTestCase
,
LogInterceptor
):
"""
"""
...
@@ -284,6 +285,11 @@ class TestERP5Type(ERP5TypeTestCase, LogInterceptor):
...
@@ -284,6 +285,11 @@ class TestERP5Type(ERP5TypeTestCase, LogInterceptor):
self
.
assertIn
(
script
,
person
.
objectValues
())
self
.
assertIn
(
script
,
person
.
objectValues
())
self
.
assertNotIn
(
script
,
person
.
objectValues
(
portal_type
=
'Person'
))
self
.
assertNotIn
(
script
,
person
.
objectValues
(
portal_type
=
'Person'
))
def
test_cmp
(
self
):
self
.
assertEqual
(
cmp
(
None
,
0
),
-
1
)
self
.
assertEqual
(
cmp
(
None
,
''
),
-
1
)
self
.
assertEqual
(
cmp
(
0
,
''
),
-
1
)
def
test_suite
():
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestERP5Type
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestERP5Type
))
...
...
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