Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
648f860c
Commit
648f860c
authored
Oct 06, 2013
by
Ethan Furman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #19156: add tests and fix for Enum helper edge cases. Patch from CliffM.
parent
ab5a58d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
Lib/enum.py
Lib/enum.py
+4
-2
Lib/test/test_enum.py
Lib/test/test_enum.py
+29
-0
No files found.
Lib/enum.py
View file @
648f860c
...
...
@@ -17,14 +17,16 @@ def _is_dunder(name):
"""Returns True if a __dunder__ name, False otherwise."""
return
(
name
[:
2
]
==
name
[
-
2
:]
==
'__'
and
name
[
2
:
3
]
!=
'_'
and
name
[
-
3
:
-
2
]
!=
'_'
)
name
[
-
3
:
-
2
]
!=
'_'
and
len
(
name
)
>
4
)
def
_is_sunder
(
name
):
"""Returns True if a _sunder_ name, False otherwise."""
return
(
name
[
0
]
==
name
[
-
1
]
==
'_'
and
name
[
1
:
2
]
!=
'_'
and
name
[
-
2
:
-
1
]
!=
'_'
)
name
[
-
2
:
-
1
]
!=
'_'
and
len
(
name
)
>
2
)
def
_make_class_unpicklable
(
cls
):
...
...
Lib/test/test_enum.py
View file @
648f860c
...
...
@@ -58,6 +58,35 @@ try:
except
Exception
:
pass
class
TestHelpers
(
unittest
.
TestCase
):
# _is_descriptor, _is_sunder, _is_dunder
def
test_is_descriptor
(
self
):
class
foo
:
pass
for
attr
in
(
'__get__'
,
'__set__'
,
'__delete__'
):
obj
=
foo
()
self
.
assertFalse
(
enum
.
_is_descriptor
(
obj
))
setattr
(
obj
,
attr
,
1
)
self
.
assertTrue
(
enum
.
_is_descriptor
(
obj
))
def
test_is_sunder
(
self
):
for
s
in
(
'_a_'
,
'_aa_'
):
self
.
assertTrue
(
enum
.
_is_sunder
(
s
))
for
s
in
(
'a'
,
'a_'
,
'_a'
,
'__a'
,
'a__'
,
'__a__'
,
'_a__'
,
'__a_'
,
'_'
,
'__'
,
'___'
,
'____'
,
'_____'
,):
self
.
assertFalse
(
enum
.
_is_sunder
(
s
))
def
test_is_dunder
(
self
):
for
s
in
(
'__a__'
,
'__aa__'
):
self
.
assertTrue
(
enum
.
_is_dunder
(
s
))
for
s
in
(
'a'
,
'a_'
,
'_a'
,
'__a'
,
'a__'
,
'_a_'
,
'_a__'
,
'__a_'
,
'_'
,
'__'
,
'___'
,
'____'
,
'_____'
,):
self
.
assertFalse
(
enum
.
_is_dunder
(
s
))
class
TestEnum
(
unittest
.
TestCase
):
def
setUp
(
self
):
class
Season
(
Enum
):
...
...
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